Skip to content

Commit

Permalink
Refactor our cmake logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau committed Oct 16, 2024
1 parent 335884b commit f33b08b
Showing 1 changed file with 48 additions and 53 deletions.
101 changes: 48 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@ include(CMakePackageConfigHelpers)
include(CTest)


macro(ddc_configure_embedded_kokkos)
if("${Kokkos_ENABLE_CUDA}")
option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON)
option(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for CUDA" ON)
endif()
if("${Kokkos_ENABLE_HIP}")
option(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for HIP" ON)
endif()
add_subdirectory(vendor/kokkos)
endmacro()

macro(ddc_configure_embedded_kokkos_fft)
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable FFT on both host and device" ON)
add_subdirectory(vendor/kokkos-fft)
endmacro()

macro(ddc_configure_embedded_kokkos_kernels)
set(KokkosKernels_ENABLE_ALL_COMPONENTS OFF)
set(KokkosKernels_ENABLE_COMPONENT_BLAS ON)
set(KokkosKernels_ENABLE_COMPONENT_BATCHED ON)
set(KokkosKernels_ENABLE_COMPONENT_LAPACK OFF)
set(KokkosKernels_ENABLE_TPL_BLAS OFF)
set(KokkosKernels_ENABLE_TPL_LAPACK OFF)
add_subdirectory(vendor/kokkos-kernels)
endmacro()

macro(ddc_configure_embedded_googletest)
add_subdirectory(vendor/googletest)
endmacro()

macro(ddc_configure_embedded_benchmark)
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" OFF)
add_subdirectory(vendor/benchmark)
endmacro()

## kokkos

set(DDC_Kokkos_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `Kokkos` package. Options: ${DDC_DEPENDENCY_POLICIES}")
Expand All @@ -35,25 +71,11 @@ if("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos 4.4...4.5 CONFIG QUIET)
if(NOT Kokkos_FOUND)
if("${Kokkos_ENABLE_CUDA}")
option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON)
option(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for CUDA" ON)
endif()
if("${Kokkos_ENABLE_HIP}")
option(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for HIP" ON)
endif()
add_subdirectory(vendor/kokkos)
ddc_configure_embedded_kokkos()
endif()
endif()
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
if("${Kokkos_ENABLE_CUDA}")
option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON)
option(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for CUDA" ON)
endif()
if("${Kokkos_ENABLE_HIP}")
option(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for HIP" ON)
endif()
add_subdirectory(vendor/kokkos)
ddc_configure_embedded_kokkos()
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(Kokkos 4.4...4.5 CONFIG REQUIRED)
endif()
Expand All @@ -76,29 +98,18 @@ endif()
if("${BUILD_TESTING}" AND "${DDC_BUILD_TESTS}")
set(DDC_GTest_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `GTest` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_GTest_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES})
set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/vendor/googletest" CACHE PATH "Path to the googletest library source")

if("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest)
find_package(GTest)
find_package(GTest QUIET)
if(NOT GTest_FOUND)
add_subdirectory("${GOOGLETEST_PATH}")
ddc_configure_embedded_googletest()
endif()
endif()
if(NOT TARGET GTest::gtest_main)
if(TARGET GTest::GTest)
add_library(GTest::gtest_main ALIAS GTest::GTest)
else()
add_library(GTest::gtest_main ALIAS GTest::gtest)
endif()
endif()
elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory("${GOOGLETEST_PATH}")
ddc_configure_embedded_googletest()
elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(GTest REQUIRED)
if(NOT TARGET GTest::gtest_main)
add_library(GTest::gtest_main ALIAS GTest::GTest)
endif()
endif()

include(GoogleTest)
Expand All @@ -110,18 +121,16 @@ endif()
if("${DDC_BUILD_BENCHMARKS}")
set(DDC_benchmark_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `benchmark` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_benchmark_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES})
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" OFF)

if("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET benchmark::benchmark)
find_package(benchmark QUIET)
if(NOT benchmark_FOUND)
add_subdirectory(vendor/benchmark)
ddc_configure_embedded_benchmark()
endif()
endif()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory(vendor/benchmark)
ddc_configure_embedded_benchmark()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(benchmark REQUIRED)
endif()
Expand Down Expand Up @@ -175,13 +184,11 @@ if("${DDC_BUILD_KERNELS_FFT}")
if(NOT TARGET KokkosFFT::fft)
find_package(KokkosFFT 0.2.1...<1 CONFIG QUIET)
if(NOT KokkosFFT_FOUND)
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable FFT on both host and device" ON)
add_subdirectory(vendor/kokkos-fft)
ddc_configure_embedded_kokkos_fft()
endif()
endif()
elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable FFT on both host and device" ON)
add_subdirectory(vendor/kokkos-fft)
ddc_configure_embedded_kokkos_fft()
elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(KokkosFFT 0.2.1...<1 CONFIG REQUIRED)
endif()
Expand All @@ -205,25 +212,13 @@ if("${DDC_BUILD_KERNELS_SPLINES}")
set_property(CACHE DDC_KokkosKernels_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}")
if("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET Kokkos::kokkoskernels)
find_package(KokkosKernels)
find_package(KokkosKernels QUIET)
if(NOT KokkosKernels_FOUND)
set(KokkosKernels_ENABLE_ALL_COMPONENTS OFF)
set(KokkosKernels_ENABLE_COMPONENT_BLAS ON)
set(KokkosKernels_ENABLE_COMPONENT_BATCHED ON)
set(KokkosKernels_ENABLE_COMPONENT_LAPACK OFF)
set(KokkosKernels_ENABLE_TPL_BLAS OFF)
set(KokkosKernels_ENABLE_TPL_LAPACK OFF)
add_subdirectory(vendor/kokkos-kernels)
ddc_configure_embedded_kokkos_kernels()
endif()
endif()
elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
set(KokkosKernels_ENABLE_ALL_COMPONENTS OFF)
set(KokkosKernels_ENABLE_COMPONENT_BLAS ON)
set(KokkosKernels_ENABLE_COMPONENT_BATCHED ON)
set(KokkosKernels_ENABLE_COMPONENT_LAPACK OFF)
set(KokkosKernels_ENABLE_TPL_BLAS OFF)
set(KokkosKernels_ENABLE_TPL_LAPACK OFF)
add_subdirectory(vendor/kokkos-kernels)
ddc_configure_embedded_kokkos_kernels()
elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(KokkosKernels REQUIRED)
endif()
Expand Down

0 comments on commit f33b08b

Please sign in to comment.