diff --git a/CMakeLists.txt b/CMakeLists.txt index db62783cd..cffa0a609 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,42 +26,10 @@ set(DDC_DEPENDENCY_POLICIES "AUTO" "EMBEDDED" "INSTALLED" "SUBPROJECT") include(CMakePackageConfigHelpers) include(CTest) +## Custom cmake modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(DDCVendorConfiguration) -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 @@ -71,18 +39,15 @@ 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) - ddc_configure_embedded_kokkos() + ddc_configure_kokkos() endif() endif() elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_embedded_kokkos() + ddc_configure_kokkos() elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") find_package(Kokkos 4.4...4.5 CONFIG REQUIRED) endif() -# Custom cmake modules -list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ) - ## PDI @@ -103,11 +68,11 @@ if("${BUILD_TESTING}" AND "${DDC_BUILD_TESTS}") if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest) find_package(GTest QUIET) if(NOT GTest_FOUND) - ddc_configure_embedded_googletest() + ddc_configure_googletest() endif() endif() elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_embedded_googletest() + ddc_configure_googletest() elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") find_package(GTest REQUIRED) endif() @@ -126,11 +91,11 @@ if("${DDC_BUILD_BENCHMARKS}") if(NOT TARGET benchmark::benchmark) find_package(benchmark QUIET) if(NOT benchmark_FOUND) - ddc_configure_embedded_benchmark() + ddc_configure_benchmark() endif() endif() elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_embedded_benchmark() + ddc_configure_benchmark() elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") find_package(benchmark REQUIRED) endif() @@ -184,11 +149,11 @@ if("${DDC_BUILD_KERNELS_FFT}") if(NOT TARGET KokkosFFT::fft) find_package(KokkosFFT 0.2.1...<1 CONFIG QUIET) if(NOT KokkosFFT_FOUND) - ddc_configure_embedded_kokkos_fft() + ddc_configure_kokkos_fft() endif() endif() elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_embedded_kokkos_fft() + ddc_configure_kokkos_fft() elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") find_package(KokkosFFT 0.2.1...<1 CONFIG REQUIRED) endif() @@ -213,11 +178,11 @@ if("${DDC_BUILD_KERNELS_SPLINES}") if(NOT TARGET Kokkos::kokkoskernels) find_package(KokkosKernels QUIET) if(NOT KokkosKernels_FOUND) - ddc_configure_embedded_kokkos_kernels() + ddc_configure_kokkos_kernels() endif() endif() elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_embedded_kokkos_kernels() + ddc_configure_kokkos_kernels() elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") find_package(KokkosKernels REQUIRED) endif() diff --git a/cmake/DDCVendorConfiguration.cmake b/cmake/DDCVendorConfiguration.cmake new file mode 100644 index 000000000..d656e25cf --- /dev/null +++ b/cmake/DDCVendorConfiguration.cmake @@ -0,0 +1,42 @@ +# Copyright (C) The DDC development team, see COPYRIGHT.md file +# +# SPDX-License-Identifier: MIT + +# This file provides different macros that will configure the dependencies with required options. +# They should be used only if DDC is responsible of handling the vendor dependency. + +macro(ddc_configure_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() + +macro(ddc_configure_googletest) + add_subdirectory(vendor/googletest) +endmacro() + +macro(ddc_configure_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_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_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()