SET(PROVIDE_UNINSTALL_TARGET OFF)
# Force Ceres to build WITHOUT its own CUDA support: Jungfraujoch never uses Ceres' GPU solvers, so
# this just drops unused code and build time (Ceres would otherwise enable CUDA whenever a toolkit is
# found). See the Eigen note in the top-level CMakeLists for the related Windows/cmake history.
SET(USE_CUDA OFF CACHE BOOL "Force Ceres to build without CUDA (Jungfraujoch does not use Ceres' GPU solvers)" FORCE)

# Prevent MKL from being found (guarantees no MKL)
SET(CMAKE_DISABLE_FIND_PACKAGE_MKL TRUE)
SET(CERES_THREADING_MODEL "CXX_THREADS")

FetchContent_Declare(
        ceres
        GIT_REPOSITORY https://github.com/ceres-solver/ceres-solver
        GIT_TAG 0c70ed3
        EXCLUDE_FROM_ALL
)

FetchContent_MakeAvailable(ceres)

ADD_LIBRARY(JFJochImageAnalysis STATIC
        MXAnalysisWithoutFPGA.cpp
        MXAnalysisWithoutFPGA.h
        MXAnalysisAfterFPGA.h
        MXAnalysisAfterFPGA.cpp
        IndexAndRefine.cpp
        IndexAndRefine.h
        dark_mask_analysis/DarkMaskAnalysis.cpp
        dark_mask_analysis/DarkMaskAnalysis.h
        rotation_indexer/RotationIndexer.cpp
        rotation_indexer/RotationIndexer.h
        RotationParameters.cpp
        RotationParameters.h
        WriteReflections.cpp
        WriteReflections.h
        LoadFCalcFromMtz.cpp
        LoadFCalcFromMtz.h
        UpdateReflectionResolution.cpp
        UpdateReflectionResolution.h
        IntegrationOutcome.h
        rotation_indexer/RotationIndexerCounter.cpp
        rotation_indexer/RotationIndexerCounter.h)

FIND_PACKAGE(Eigen3 3.4 REQUIRED NO_MODULE)  # provides Eigen3::Eigen

ADD_SUBDIRECTORY(spot_finding)
ADD_SUBDIRECTORY(bragg_integration)
ADD_SUBDIRECTORY(bragg_prediction)
ADD_SUBDIRECTORY(indexing)
ADD_SUBDIRECTORY(geom_refinement)
ADD_SUBDIRECTORY(lattice_search)
ADD_SUBDIRECTORY(scale_merge)
ADD_SUBDIRECTORY(image_preprocessing)
ADD_SUBDIRECTORY(azint)
ADD_SUBDIRECTORY(roi)

TARGET_LINK_LIBRARIES(JFJochImageAnalysis JFJochAzIntEngine JFJochROIIntegration JFJochImagePreprocessing JFJochBraggPrediction JFJochBraggIntegration JFJochLatticeSearch JFJochIndexing JFJochSpotFinding JFJochCommon JFJochGeomRefinement JFJochScaleMerge gemmi)
