Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundant cmake logic #660

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 16 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +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)


## kokkos

Expand All @@ -35,32 +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)
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_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_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

Expand All @@ -76,29 +63,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_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_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 +86,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_benchmark()
endif()
endif()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory(vendor/benchmark)
ddc_configure_benchmark()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(benchmark REQUIRED)
endif()
Expand Down Expand Up @@ -175,13 +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)
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable FFT on both host and device" ON)
add_subdirectory(vendor/kokkos-fft)
ddc_configure_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_kokkos_fft()
elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(KokkosFFT 0.2.1...<1 CONFIG REQUIRED)
endif()
Expand All @@ -204,25 +176,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_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_kokkos_kernels()
elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(KokkosKernels REQUIRED)
endif()
Expand Down
42 changes: 42 additions & 0 deletions cmake/DDCVendorConfiguration.cmake
Original file line number Diff line number Diff line change
@@ -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()