Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leptonica: switch to CMake #194875

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions Formula/l/leptonica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
sha256 cellar: :any_skip_relocation, x86_64_linux: "9b2c01e724c093ba4b4bf19bdd65edcc3ff70dbc5071e5e801f07b9f24cc2d63"
end

depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "giflib"
depends_on "jpeg-turbo"
Expand All @@ -24,24 +25,60 @@

uses_from_macos "zlib"

patch :DATA

def install

Check failure on line 30 in Formula/l/leptonica.rb

View workflow job for this annotation

GitHub Actions / Linux

`brew install --verbose --formula --build-bottle leptonica` failed on Linux!

[ 28%] Linking C executable ../bin/blend5_reg cd /tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared/prog && /home/linuxbrew/.linuxbrew/Cellar/cmake/3.30.5/bin/cmake -E cmake_link_script CMakeFiles/blend5_reg.dir/link.txt --verbose=1 /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-11 -O3 -DNDEBUG CMakeFiles/blend5_reg.dir/blend5_reg.c.o -o ../bin/blend5_reg -Wl,-rpath,/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared/src ../src/libleptonica.so.6.0.0 /usr/bin/ld: CMakeFiles/blend4_reg.dir/blend4_reg.c.o: undefined reference to symbol 'sqrt@@GLIBC_2.2.5' /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status make[2]: *** [prog/CMakeFiles/blend4_reg.dir/build.make:101: bin/blend4_reg] Error 1 make[2]: Leaving directory '/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared' make[1]: *** [CMakeFiles/Makefile2:1294: prog/CMakeFiles/blend4_reg.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... make[2]: Leaving directory '/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared' make[2]: Leaving directory '/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared' [ 28%] Built target boxa1_reg [ 28%] Built target blend5_reg [ 28%] Linking C executable ../bin/boxa2_reg cd /tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared/prog && /home/linuxbrew/.linuxbrew/Cellar/cmake/3.30.5/bin/cmake -E cmake_link_script CMakeFiles/boxa2_reg.dir/link.txt --verbose=1 /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-11 -O3 -DNDEBUG CMakeFiles/boxa2_reg.dir/boxa2_reg.c.o -o ../bin/boxa2_reg -Wl,-rpath,/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared/src ../src/libleptonica.so.6.0.0 make[2]: Leaving directory '/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared' [ 28%] Built target boxa2_reg make[1]: Leaving directory '/tmp/leptonica-20241018-5515-votoxo/leptonica-1.85.0/build_shared' make: *** [Makefile:139: all] Error 2 ==> Formula Path: /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/l/leptonica.rb ==> Configuration HOMEBREW_VERSION: 4.4.1-57-gfdd2aa7 ORIGIN: https://github.com/Homebrew/brew HEAD: fdd2aa79023404fb98a16d14c19eee8ae834bb07 Last commit: 9 hours ago Core tap HEAD: 97a9dfc47a48457488d02678fe7694d85b012d7a Core tap last commit: 5 minutes ago Core tap JSON: 18 Oct 16:02 UTC HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew HOMEBREW_BOOTSNAP: set HOMEBREW_CASK_OPTS: [] HOMEBREW_COLOR: set HOMEBREW_CURL_PATH: /usr/bin/curl HOMEBREW_FAIL_LOG_LINES: 150 HOMEBREW_GITHUB_API_TOKEN: set HOMEBREW_GIT_EMAIL: [email protected] HOMEBREW_GIT_NAME: BrewTestBot HOMEBREW_GIT_PATH: /usr/bin/git HOMEBREW_LOGS: /github/home/bottles/logs HOMEBREW_MAKE_JOBS: 4 HOMEBREW_NO_AUTO_UPDATE: set HOMEBREW_NO_EMOJI: set HOMEBREW_NO_ENV_HINTS: set HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: set HOMEBREW_NO_INSTALL_FROM_API: set HOMEBREW_SORBET_RUNTIME: set HOMEBREW_VERIFY_ATTESTATIONS: set Homebrew Ruby: 3.3.5 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/3.3.5/bin/ruby CPU: quad-core 64-bit zen3 Clang: N/A Git: 2.47.0 => /usr/bin/git Curl: 7.81.0 => /usr/bin/curl Kernel: Linux 6.5.0-1025-azure x86_64 GNU/Linux OS: Ubuntu 22.04.5 LTS Host glibc: 2.35 /usr/bin/gcc: 11.4.0 /usr/bin/ruby: N/A glibc: N/A gcc@11: N/A gcc: N/A xorg: N/A ==> ENV HOMEBREW_CC: gcc-11 HOMEBREW_CXX: g++-11 MAKEFLAGS: -j4 CMAKE_PREFIX_PATH: /home/linuxbrew/.linuxbrew PKG_CONFIG_PATH: /home/linuxbrew/.linuxbrew/opt/jpeg-turbo/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/zlib/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/libpng/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/xz/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/lz4/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/zstd/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/libtiff/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/little-cms2/lib/pkgconfig:/home/linuxbrew/.linuxbrew/opt/openjpeg/lib/pkgconfig:/home/linuxbrew/
system "./configure", "--with-libwebp", "--with-libopenjpeg", *std_configure_args
system "make", "install"
args = ["-DSTRICT_CONF=ON"]
shared_args = ["-DBUILD_PROG=ON", "-DBUILD_SHARED_LIBS=ON", "-DCMAKE_INSTALL_RPATH=#{rpath}"]

system "cmake", "-S", ".", "-B", "build_shared", *args, *shared_args, *std_cmake_args
system "cmake", "--build", "build_shared"
system "cmake", "--install", "build_shared"

system "cmake", "-S", ".", "-B", "build_static", *args, *std_cmake_args
system "cmake", "--build", "build_static"
lib.install "build_static/src/libleptonica.a"

# Add lept.pc to align with autotools build
odie "lept.pc already exists!" if (lib/"pkgconfig/lept.pc").exist?
odie "lept_Release.pc does not exist!" unless (lib/"pkgconfig/lept_Release.pc").exist?
(lib/"pkgconfig").install_symlink "lept_Release.pc" => "lept.pc"
end

test do
(testpath/"test.cpp").write <<~EOS
#include <iostream>
(testpath/"test.c").write <<~C
#include <stdio.h>
#include <leptonica/allheaders.h>

int main(int argc, char **argv) {
fprintf(stdout, "%d.%d.%d", LIBLEPT_MAJOR_VERSION, LIBLEPT_MINOR_VERSION, LIBLEPT_PATCH_VERSION);
return 0;
int main() {
printf("%d.%d.%d", LIBLEPT_MAJOR_VERSION, LIBLEPT_MINOR_VERSION, LIBLEPT_PATCH_VERSION);
writeImageFileInfo("#{test_fixtures("test.png")}", stderr, 0);
return 0;
}
EOS
C

flags = ["-I#{include}/leptonica"] + ENV.cflags.to_s.split
system ENV.cxx, "test.cpp", *flags
assert_equal version.to_s, `./a.out`
system ENV.cc, "test.c", "-o", "test", "-L#{lib}", "-lleptonica"
assert_equal version.to_s, shell_output("./test 2>#{testpath}/stderr.log")
assert_match <<~TEXT, (testpath/"stderr.log").read
Reading the header:
input image format type: png
w = 8, h = 8, bps = 1, spp = 1, iscmap = 1
xres = 0, yres = 0
TEXT
end
end

__END__
diff --git a/prog/CMakeLists.txt b/prog/CMakeLists.txt
index 73fd28b5..6626ba25 100644
--- a/prog/CMakeLists.txt
+++ b/prog/CMakeLists.txt
@@ -15,7 +15,7 @@ function(add_prog_target target)
if (BUILD_SHARED_LIBS)
target_compile_definitions (${target} PRIVATE -DLIBLEPT_IMPORTS)
endif()
- if(FREEBSD AND HAVE_LIBM AND ${target} MATCHES ${math_progs})
+ if((FREEBSD OR CMAKE_SYSTEM_NAME STREQUAL "Linux") AND HAVE_LIBM AND ${target} MATCHES ${math_progs})
target_link_libraries (${target} leptonica m)
else()
target_link_libraries (${target} leptonica)
Loading