From 0220c6376dfe425f8e0cd6c606cf369e336b6544 Mon Sep 17 00:00:00 2001 From: leonarski_f Date: Fri, 19 Jun 2026 22:16:05 +0200 Subject: [PATCH] cmake: fetch libtiff and FFTW instead of relying on system libs Both are leaf deps (JFJochPreview / JFJochIndexing) that only our own code looks for, so building them ourselves removes the system-package lottery and gives a reproducible, statically-linked build on every platform. - libtiff: FetchContent, library only (jbig/zstd/lzma/jpeg/old-jpeg/tools/ tests off). The C++ binding (TIFF::CXX / libtiffxx) is packaged inconsistently across distros -- missing on Rocky 9 -- and absent on Windows, so find_package(TIFF COMPONENTS CXX) was unreliable; that call is removed and JFJochPreview links the tiff/tiffxx targets directly. GitHub mirror because upstream (gitlab) is unreachable from some restricted hosts. - FFTW: FetchContent single precision (ENABLE_FLOAT) from the release tarball -- the git repo ships no pre-generated codelets (needs OCaml genfft). It's now always available, so the CPU FFT indexer is always built and JFJOCH_USE_FFTW always defined; the "FFTW disabled" path is gone. Static (libfftw3f.a) via the global BUILD_SHARED_LIBS OFF. Verified on Linux: jfjoch_viewer builds and links libfftw3f.a + libtiff*.a, all static. Co-Authored-By: Claude Opus 4.8 --- CMakeLists.txt | 37 ++++++++++++++++++++------ image_analysis/indexing/CMakeLists.txt | 10 +++---- preview/CMakeLists.txt | 3 +-- viewer/CMakeLists.txt | 7 +---- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8828ad7..8a8fd1b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,14 +63,6 @@ IF (CMAKE_CUDA_COMPILER) ENDIF() ENDIF() -FIND_LIBRARY(FFTWF_LIBRARY NAMES libfftw3f.a libfftw3f.so fftw3f DOC "FFTW single-precision library" - PATHS /usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu/) -CHECK_INCLUDE_FILE(fftw3.h HAS_FFTW3_H) - -IF(HAS_FFTW3_H AND FFTWF_LIBRARY) - ADD_COMPILE_DEFINITIONS(JFJOCH_USE_FFTW) -ENDIF() - INCLUDE_DIRECTORIES(include) include(FetchContent) @@ -173,6 +165,35 @@ ELSE() FetchContent_MakeAvailable(zstd sls_detector_package catch2 hdf5 spdlog httplib) ENDIF() +# libtiff (used by JFJochPreview in every build mode): build it ourselves. Its C++ binding +# (tiffxx) is packaged inconsistently across distros (missing on Rocky 9) and absent on +# Windows. Library only; the SET()s below are libtiff's own codec/tool switches. The GitHub +# mirror is used because upstream (gitlab) is unreachable from some restricted build hosts. +SET(jbig OFF) +SET(zstd OFF) +SET(lzma OFF) +SET(jpeg OFF) +SET(old-jpeg OFF) +SET(tiff-tools OFF) +SET(tiff-tests OFF) +FetchContent_Declare(tiff + GIT_REPOSITORY https://github.com/fleon-psi/libtiff + GIT_TAG v4.6.0 + EXCLUDE_FROM_ALL) +FetchContent_MakeAvailable(tiff) + +# FFTW single precision (target fftw3f): the CPU fallback indexer, enables JFJOCH_USE_FFTW. +# Built from the release tarball -- the git repo ships no pre-generated codelets (needs the +# OCaml genfft). It's a fallback, so no aggressive SIMD tuning (plain scalar build is fine). +SET(ENABLE_FLOAT ON CACHE BOOL "" FORCE) +SET(BUILD_TESTS OFF CACHE BOOL "" FORCE) +FetchContent_Declare(fftw + URL https://www.fftw.org/fftw-3.3.10.tar.gz + URL_HASH SHA256=56c932549852cddcfafdab3820b0200c7742675be92179e59e6215b340e26467 + EXCLUDE_FROM_ALL) +FetchContent_MakeAvailable(fftw) +ADD_COMPILE_DEFINITIONS(JFJOCH_USE_FFTW) + IF (JFJOCH_VIEWER_ONLY) # Minimal subtree: jfjoch_viewer and only the libraries it transitively links. # (broker here provides JFJochAPI only; its service targets are gated out.) diff --git a/image_analysis/indexing/CMakeLists.txt b/image_analysis/indexing/CMakeLists.txt index f40c1492..159ac0b8 100644 --- a/image_analysis/indexing/CMakeLists.txt +++ b/image_analysis/indexing/CMakeLists.txt @@ -39,10 +39,6 @@ ELSE() TARGET_LINK_LIBRARIES(JFJochIndexing Eigen3::Eigen) ENDIF() -IF(HAS_FFTW3_H AND FFTWF_LIBRARY) - TARGET_SOURCES(JFJochIndexing PRIVATE FFTIndexerCPU.cpp FFTIndexerCPU.h) - TARGET_LINK_LIBRARIES(JFJochIndexing ${FFTWF_LIBRARY}) - MESSAGE(STATUS "FFT single-precision library found: ${FFTWF_LIBRARY}") -ELSE() - MESSAGE(WARNING "FFTW disabled") -ENDIF() +# FFTW (fftw3f) is always available via FetchContent -> the CPU FFT indexer is always built. +TARGET_SOURCES(JFJochIndexing PRIVATE FFTIndexerCPU.cpp FFTIndexerCPU.h) +TARGET_LINK_LIBRARIES(JFJochIndexing fftw3f) diff --git a/preview/CMakeLists.txt b/preview/CMakeLists.txt index d73e4379..08477371 100644 --- a/preview/CMakeLists.txt +++ b/preview/CMakeLists.txt @@ -2,7 +2,6 @@ include(ExternalProject) find_package(ZLIB REQUIRED) find_package(JPEG REQUIRED) -find_package(TIFF REQUIRED COMPONENTS CXX) ADD_LIBRARY(JFJochPreview STATIC JFJochTIFF.cpp JFJochTIFF.h @@ -16,5 +15,5 @@ ADD_LIBRARY(JFJochPreview STATIC ) TARGET_LINK_LIBRARIES(JFJochPreview PUBLIC JFJochZMQ JFJochCommon CBORStream2FrameSerialize) -TARGET_LINK_LIBRARIES(JFJochPreview PUBLIC JPEG::JPEG TIFF::TIFF TIFF::CXX ZLIB::ZLIB) +TARGET_LINK_LIBRARIES(JFJochPreview PUBLIC JPEG::JPEG tiff tiffxx ZLIB::ZLIB) diff --git a/viewer/CMakeLists.txt b/viewer/CMakeLists.txt index 58fc4a8a..b7f0a20e 100644 --- a/viewer/CMakeLists.txt +++ b/viewer/CMakeLists.txt @@ -133,9 +133,4 @@ ELSE() qt_import_plugins(jfjoch_viewer INCLUDE Qt::QXcbIntegrationPlugin) ENDIF() -IF(HAS_FFTW3_H AND FFTWF_LIBRARY) - TARGET_LINK_LIBRARIES(jfjoch_viewer ${FFTWF_LIBRARY}) - MESSAGE(STATUS "FFT single-precision library found: ${FFTWF_LIBRARY}") -ELSE() - MESSAGE(WARNING "FFTW disabled") -ENDIF() \ No newline at end of file +TARGET_LINK_LIBRARIES(jfjoch_viewer fftw3f) \ No newline at end of file