Skip to content

Commit

Permalink
leptonica: switch to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Oct 18, 2024
1 parent 42cce7e commit 4db3769
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions Formula/l/leptonica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Leptonica < Formula
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 @@ -25,23 +26,46 @@ class Leptonica < Formula
uses_from_macos "zlib"

def install

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

View workflow job for this annotation

GitHub Actions / Linux

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

/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-5414-hxkbdo/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[ 28%] Linking C executable ../bin/boxa1_reg : error adding symbols: DSO missing from command line cd /tmp/leptonica-20241018-5414-hxkbdo/leptonica-1.85.0/build_shared/prog && /home/linuxbrew/.linuxbrew/Cellar/cmake/3.30.5/bin/cmake -E cmake_link_script CMakeFiles/boxa1_reg.dir/link.txt --verbose=1 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-5414-hxkbdo/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.... /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-11 -O3 -DNDEBUG CMakeFiles/boxa1_reg.dir/boxa1_reg.c.o -o ../bin/boxa1_reg -Wl,-rpath,/tmp/leptonica-20241018-5414-hxkbdo/leptonica-1.85.0/build_shared/src ../src/libleptonica.so.6.0.0 make[2]: Leaving directory '/tmp/leptonica-20241018-5414-hxkbdo/leptonica-1.85.0/build_shared' [ 28%] Built target blend5_reg [ 28%] Linking C executable ../bin/boxa2_reg cd /tmp/leptonica-20241018-5414-hxkbdo/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-5414-hxkbdo/leptonica-1.85.0/build_shared/src ../src/libleptonica.so.6.0.0 make[2]: Leaving directory '/tmp/leptonica-20241018-5414-hxkbdo/leptonica-1.85.0/build_shared' [ 28%] Built target boxa1_reg make[2]: Leaving directory '/tmp/leptonica-20241018-5414-hxkbdo/leptonica-1.85.0/build_shared' [ 28%] Built target boxa2_reg make[1]: Leaving directory '/tmp/leptonica-20241018-5414-hxkbdo/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: 27d0594db5e6dafb0a8ff693167e587cce332118 Core tap last commit: 8 minutes ago Core tap JSON: 18 Oct 15:37 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/.lin
system "./configure", "--with-libwebp", "--with-libopenjpeg", *std_configure_args
system "make", "install"
system "cmake", "-S", ".", "-B", "build_shared",
"-DBUILD_PROG=ON",
"-DBUILD_SHARED_LIBS=ON",
"-DCMAKE_INSTALL_RPATH=#{rpath}",
*std_cmake_args
system "cmake", "--build", "build_shared"
system "cmake", "--install", "build_shared"

system "cmake", "-S", ".", "-B", "build_static",
"-DBUILD_PROG=OFF",
"-DBUILD_SHARED_LIBS=OFF",
*std_cmake_args
system "cmake", "--build", "build_static"
lib.install "build_static/src/libleptonica.a"

# Add pkg-config symlink to align with autotools
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

0 comments on commit 4db3769

Please sign in to comment.