# The fast-feedback indexer (TORO, the GPU known-cell indexer behind FFBIDX), vendored from
# https://github.com/paulscherrerinstitute/fast-feedback-indexer at commit a94fd4f5c55289e70860feea358182d2072e02b5,
# BSD-3-Clause (LICENSE.md). Only the static library the build links is kept, with the rules upstream's
# indexer/src/CMakeLists.txt gives it: its install, pkg-config, shared-library and C-API parts are left out,
# version.h is written once rather than generated, and data/ holds the library's test spot lists that
# FFBIDXIndexerCPU_MatchesGPU reads.

SET(THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE(Threads REQUIRED)
FIND_PACKAGE(CUDAToolkit REQUIRED)
IF (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
    SET(CMAKE_CUDA_ARCHITECTURES "75;80")
ENDIF()

ADD_LIBRARY(fast_indexer_static STATIC
        indexer_gpu.cu ffbidx/indexer_gpu.h
        indexer.cpp
        log.cpp
        ffbidx/indexer.h
        ffbidx/refine.h
        ffbidx/log.h
        ffbidx/exception.h
        ffbidx/envvar.h
        ffbidx/version.h)
SET_TARGET_PROPERTIES(fast_indexer_static PROPERTIES CUDA_RUNTIME_LIBRARY Static)
TARGET_COMPILE_FEATURES(fast_indexer_static PUBLIC cxx_std_17)
TARGET_INCLUDE_DIRECTORIES(fast_indexer_static PUBLIC .)
TARGET_LINK_LIBRARIES(fast_indexer_static
        PRIVATE CUDA::cudart_static
        PRIVATE Threads::Threads
        PUBLIC Eigen3::Eigen)

# indexer_gpu.cu includes CUB, which, like all of CCCL, stops with an #error under MSVC's traditional
# preprocessor: the host compiler gets the conforming one for the CUDA sources, as upstream does. The
# top-level CMakeLists.txt sets the same for every CUDA target; it is kept here so the library does not
# depend on that.
IF (MSVC)
    TARGET_COMPILE_OPTIONS(fast_indexer_static PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/Zc:preprocessor>)
ENDIF()
