diff --git a/CMakeLists.txt b/CMakeLists.txt index 4da0a03a..366e86f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,6 +213,21 @@ FetchContent_MakeAvailable(fftw) TARGET_INCLUDE_DIRECTORIES(fftw3f INTERFACE $) ADD_COMPILE_DEFINITIONS(JFJOCH_USE_FFTW) +# Eigen (header-only): consumed by Ceres and by the analysis libs directly, and by ffbidx under +# CUDA. Not auto-provided by FetchContent and absent on Windows, so vendor it here. OVERRIDE_FIND_PACKAGE +# routes every find_package(Eigen3) -- ours, Ceres', ffbidx' -- to this copy and bypasses the version +# request (they ask for 3.4; this is a newer major). ffbidx's own bundled eigen is disabled below +# (GIT_SUBMODULES "" on fast-indexer) so it does not create a duplicate Eigen3::Eigen target. +SET(EIGEN_BUILD_DOC OFF CACHE BOOL "" FORCE) +SET(EIGEN_BUILD_TESTING OFF CACHE BOOL "" FORCE) +SET(EIGEN_BUILD_PKGCONFIG OFF CACHE BOOL "" FORCE) +FetchContent_Declare(Eigen3 + GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git + GIT_TAG 5.0.1 + GIT_SHALLOW TRUE + EXCLUDE_FROM_ALL + OVERRIDE_FIND_PACKAGE) + 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 159ac0b8..6b8dc312 100644 --- a/image_analysis/indexing/CMakeLists.txt +++ b/image_analysis/indexing/CMakeLists.txt @@ -19,10 +19,14 @@ ADD_LIBRARY(JFJochIndexing STATIC TARGET_LINK_LIBRARIES(JFJochIndexing JFJochCommon JFJochLatticeSearch) IF (JFJOCH_CUDA_AVAILABLE) + # GIT_SUBMODULES "" -> do not fetch ffbidx's bundled eigen submodule; it would add_subdirectory + # a second Eigen3::Eigen target. ffbidx instead resolves Eigen via the project-level Eigen3 + # (OVERRIDE_FIND_PACKAGE in the top-level CMakeLists). FetchContent_Declare( fast-indexer GIT_REPOSITORY https://github.com/paulscherrerinstitute/fast-feedback-indexer/ GIT_TAG ca9e17486a1eb96319a738acef33cc24c9cd8845 + GIT_SUBMODULES "" ) FetchContent_MakeAvailable(fast-indexer) diff --git a/preview/CMakeLists.txt b/preview/CMakeLists.txt index 08477371..20d8f11c 100644 --- a/preview/CMakeLists.txt +++ b/preview/CMakeLists.txt @@ -1,7 +1,48 @@ include(ExternalProject) find_package(ZLIB REQUIRED) -find_package(JPEG REQUIRED) + +# libjpeg-turbo: upstream does NOT support add_subdirectory/FetchContent inclusion, so build and +# install it out-of-line and import the static lib. (Adapted from aseprite's FindJpegTurbo.cmake.) +# The static lib is `jpeg-static.lib` on MSVC and `libjpeg.a` elsewhere. +IF (MSVC) + SET(LIBJPEG_TURBO_STATIC_SUFFIX "-static") +ELSE() + SET(LIBJPEG_TURBO_STATIC_SUFFIX "") +ENDIF() +SET(LIBJPEG_TURBO_DIR "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo") +SET(LIBJPEG_TURBO_LIBRARY "${LIBJPEG_TURBO_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jpeg${LIBJPEG_TURBO_STATIC_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") +SET(LIBJPEG_TURBO_INCLUDE_DIRS "${LIBJPEG_TURBO_DIR}/include") + +ExternalProject_Add(libjpeg-turbo-project + GIT_REPOSITORY https://github.com/libjpeg-turbo/libjpeg-turbo + GIT_TAG 3.0.4 + PREFIX "${LIBJPEG_TURBO_DIR}" + INSTALL_DIR "${LIBJPEG_TURBO_DIR}" + BUILD_BYPRODUCTS "${LIBJPEG_TURBO_LIBRARY}" + CMAKE_CACHE_ARGS + -DENABLE_SHARED:BOOL=OFF + -DENABLE_STATIC:BOOL=ON + -DWITH_ARITH_DEC:BOOL=ON + -DWITH_ARITH_ENC:BOOL=ON + -DWITH_JPEG8:BOOL=OFF + -DWITH_JPEG7:BOOL=OFF + -DWITH_TURBOJPEG:BOOL=OFF + # Lazy SIMD: use NASM-accelerated SIMD when nasm is present, otherwise warn and build a + # scalar libjpeg (REQUIRE_SIMD=OFF is libjpeg-turbo's default; pinned here to be explicit). + -DWITH_SIMD:BOOL=ON + -DREQUIRE_SIMD:BOOL=OFF + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH= + -DCMAKE_INSTALL_LIBDIR:PATH=/lib) + +# Create the include dir up front so setting INTERFACE_INCLUDE_DIRECTORIES below does not fail. +FILE(MAKE_DIRECTORY ${LIBJPEG_TURBO_INCLUDE_DIRS}) + +ADD_LIBRARY(JPEG::JPEG STATIC IMPORTED GLOBAL) +SET_TARGET_PROPERTIES(JPEG::JPEG PROPERTIES + IMPORTED_LOCATION "${LIBJPEG_TURBO_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBJPEG_TURBO_INCLUDE_DIRS}") ADD_LIBRARY(JFJochPreview STATIC JFJochTIFF.cpp JFJochTIFF.h @@ -14,6 +55,10 @@ ADD_LIBRARY(JFJochPreview STATIC ZMQMetadataSocket.h ) +# JPEG::JPEG is an IMPORTED target, so the build-order dependency on the ExternalProject must be +# attached to the consuming target instead. +ADD_DEPENDENCIES(JFJochPreview libjpeg-turbo-project) + TARGET_LINK_LIBRARIES(JFJochPreview PUBLIC JFJochZMQ JFJochCommon CBORStream2FrameSerialize) TARGET_LINK_LIBRARIES(JFJochPreview PUBLIC JPEG::JPEG tiff tiffxx ZLIB::ZLIB)