Skip to content

Cleaner ddc installation #762

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

Merged
merged 5 commits into from
Jan 27, 2025
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
37 changes: 12 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
ddc_check_required_kokkos_options()
endif()

## PDI

if("${DDC_BUILD_PDI_WRAPPER}")
if(NOT TARGET PDI::PDI_C)
find_package(PDI 1.6...<2 REQUIRED COMPONENTS C)
endif()
endif()

## GoogleTest

if("${BUILD_TESTING}" AND "${DDC_BUILD_TESTS}")
Expand Down Expand Up @@ -131,11 +123,6 @@ endif()

## The library itself

### DDC legacy target
add_library(DDC INTERFACE)
add_library(DDC::DDC ALIAS DDC)
install(TARGETS DDC EXPORT DDCTargets)

add_library(ddc_core INTERFACE)
add_library(DDC::core ALIAS ddc_core)
configure_file(cmake/config.hpp.in generated/ddc/config.hpp NO_SOURCE_PERMISSIONS @ONLY)
Expand All @@ -151,9 +138,6 @@ target_include_directories(
)
target_link_libraries(ddc_core INTERFACE Kokkos::kokkos)

### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::core)

# Link library to DDC

if("${DDC_BUILD_KERNELS_FFT}")
Expand Down Expand Up @@ -183,11 +167,10 @@ if("${DDC_BUILD_KERNELS_FFT}")

add_library(ddc_fft INTERFACE)
add_library(DDC::fft ALIAS ddc_fft)
install(TARGETS ddc_fft EXPORT DDCTargets)
install(TARGETS ddc_fft EXPORT DDCFftTargets)
target_link_libraries(ddc_fft INTERFACE DDC::core Kokkos::kokkos KokkosFFT::fft)

### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::fft)
install(EXPORT DDCFftTargets NAMESPACE DDC::impl:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
endif()

if("${DDC_BUILD_KERNELS_SPLINES}")
Expand Down Expand Up @@ -223,23 +206,26 @@ if("${DDC_BUILD_KERNELS_SPLINES}")
add_library(ddc_splines INTERFACE)
add_library(DDC::splines ALIAS ddc_splines)
install(FILES cmake/FindLAPACKE.cmake DESTINATION ${DDC_INSTALL_CMAKEDIR})
install(TARGETS ddc_splines EXPORT DDCTargets)
install(TARGETS ddc_splines EXPORT DDCSplinesTargets)
target_include_directories(ddc_splines SYSTEM INTERFACE ${LAPACKE_INCLUDE_DIRS})
target_link_libraries(
ddc_splines
INTERFACE DDC::core Ginkgo::ginkgo Kokkos::kokkos Kokkos::kokkoskernels ${LAPACKE_LIBRARIES}
)

### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::splines)
install(EXPORT DDCSplinesTargets NAMESPACE DDC::impl:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
endif()

## The PDI wrapper

if("${DDC_BUILD_PDI_WRAPPER}")
if(NOT TARGET PDI::PDI_C)
find_package(PDI 1.6...<2 REQUIRED COMPONENTS C)
endif()

add_library(ddc_pdi INTERFACE)
add_library(DDC::pdi ALIAS ddc_pdi)
install(TARGETS ddc_pdi EXPORT DDCTargets)
install(TARGETS ddc_pdi EXPORT DDCPdiTargets)
target_compile_features(ddc_pdi INTERFACE cxx_std_17)
target_include_directories(
ddc_pdi
Expand All @@ -249,8 +235,7 @@ if("${DDC_BUILD_PDI_WRAPPER}")
)
target_link_libraries(ddc_pdi INTERFACE DDC::core PDI::PDI_C)

### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::pdi)
install(EXPORT DDCPdiTargets NAMESPACE DDC::impl:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
endif()

## if examples are enabled, build them
Expand Down Expand Up @@ -287,6 +272,8 @@ configure_package_config_file(
cmake/DDCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake
INSTALL_DESTINATION ${DDC_INSTALL_CMAKEDIR}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

# We use SameMinorVersion until major version 1
Expand Down
65 changes: 46 additions & 19 deletions cmake/DDCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

@PACKAGE_INIT@

# This macro extends the cmake macro `check_required_components`.
# It checks if all required components for a package are found and
# sets a custom NOT_FOUND_MESSAGE listing missing required components.
macro(ddc_check_required_components _NAME)
set(REQUIRED_COMPONENTS_NOT_FOUND "")
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
list(APPEND REQUIRED_COMPONENTS_NOT_FOUND "${comp}")
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()

if(REQUIRED_COMPONENTS_NOT_FOUND)
set(${_NAME}_NOT_FOUND_MESSAGE "Component(s) not found: ${REQUIRED_COMPONENTS_NOT_FOUND}")
endif()
unset(REQUIRED_COMPONENTS_NOT_FOUND)
endmacro()

# Workaround for rocm <6 setting a cmake_minimum_required <3.12.
# When redefining `find_dependency` we get a better chance
# to use the NEW policy for CMP0074.
Expand All @@ -16,11 +36,22 @@ set(DDC_BUILD_DOUBLE_PRECISION @DDC_BUILD_DOUBLE_PRECISION@)

ddc_find_dependency(Kokkos 4.4...<5)

if(@DDC_BUILD_KERNELS_FFT@)
include(${CMAKE_CURRENT_LIST_DIR}/DDCTargets.cmake)
if(NOT TARGET DDC::core)
add_library(DDC::core ALIAS DDC::impl::ddc_core)
endif()

if(@DDC_BUILD_KERNELS_FFT@ AND ("fft" IN_LIST DDC_FIND_COMPONENTS))
ddc_find_dependency(KokkosFFT 0.2.1...<1)

include(${CMAKE_CURRENT_LIST_DIR}/DDCFftTargets.cmake)
if(NOT TARGET DDC::fft)
add_library(DDC::fft ALIAS DDC::impl::ddc_fft)
endif()
set(DDC_fft_FOUND TRUE)
endif()

if(@DDC_BUILD_KERNELS_SPLINES@)
if(@DDC_BUILD_KERNELS_SPLINES@ AND ("splines" IN_LIST DDC_FIND_COMPONENTS))
ddc_find_dependency(Ginkgo 1.8...<2)
# DDC installs a FindLAPACKE.cmake file.
# We choose to rely on it by prepending to CMAKE_MODULE_PATH
Expand All @@ -29,26 +60,22 @@ if(@DDC_BUILD_KERNELS_SPLINES@)
ddc_find_dependency(LAPACKE)
list(POP_FRONT CMAKE_MODULE_PATH)
ddc_find_dependency(KokkosKernels 4.5.1...<5)
endif()

if(@DDC_BUILD_PDI_WRAPPER@)
ddc_find_dependency(PDI 1.6...<2 COMPONENTS C)
include(${CMAKE_CURRENT_LIST_DIR}/DDCSplinesTargets.cmake)
if(NOT TARGET DDC::splines)
add_library(DDC::splines ALIAS DDC::impl::ddc_splines)
endif()
set(DDC_splines_FOUND TRUE)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/DDCTargets.cmake)

# We always define public alias targets when impl targets are available.
foreach(target core fft pdi splines)
if((NOT TARGET DDC::${target}) AND (TARGET DDC::impl::ddc_${target}))
add_library(DDC::${target} ALIAS DDC::impl::ddc_${target})
endif()
endforeach()
if(@DDC_BUILD_PDI_WRAPPER@ AND ("pdi" IN_LIST DDC_FIND_COMPONENTS))
ddc_find_dependency(PDI 1.6...<2 COMPONENTS C)

# Components are found if the public targets exist
foreach(component ${DDC_FIND_COMPONENTS})
if(TARGET DDC::${component})
set(DDC_${component}_FOUND TRUE)
include(${CMAKE_CURRENT_LIST_DIR}/DDCPdiTargets.cmake)
if(NOT TARGET DDC::pdi)
add_library(DDC::pdi ALIAS DDC::impl::ddc_pdi)
endif()
endforeach()
set(DDC_pdi_FOUND TRUE)
endif()

check_required_components(DDC)
ddc_check_required_components(DDC)
10 changes: 5 additions & 5 deletions install_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ find_package(DDC 0.4 REQUIRED)
find_package(DDC 0.4 REQUIRED COMPONENTS fft)
find_package(DDC 0.4 REQUIRED COMPONENTS pdi splines)

message("DDC options:")
message("DDC_BUILD_DOUBLE_PRECISION=${DDC_BUILD_DOUBLE_PRECISION}")
message("DDC_fft_FOUND=${DDC_fft_FOUND}")
message("DDC_pdi_FOUND=${DDC_pdi_FOUND}")
message("DDC_splines_FOUND=${DDC_splines_FOUND}")
message(STATUS "DDC options:")
message(STATUS "* DDC_BUILD_DOUBLE_PRECISION=${DDC_BUILD_DOUBLE_PRECISION}")
message(STATUS "* DDC_fft_FOUND=${DDC_fft_FOUND}")
message(STATUS "* DDC_pdi_FOUND=${DDC_pdi_FOUND}")
message(STATUS "* DDC_splines_FOUND=${DDC_splines_FOUND}")

add_executable(main main.cpp)
target_link_libraries(main PRIVATE DDC::core DDC::fft DDC::pdi DDC::splines)
Loading