From 6bb67b4f4501a0a64e9f095da860c62f1a050099 Mon Sep 17 00:00:00 2001 From: Allison Piper Date: Wed, 4 Sep 2024 22:13:44 +0000 Subject: [PATCH] Migrate CMake packages to central location. --- CMakeLists.txt | 1 + cmake/CCCLAddSubdir.cmake | 9 ++-- cmake/CCCLAddSubdirHelper.cmake | 43 +++++++++++++++++++ cmake/CCCLInstallRules.cmake | 1 + cub/cmake/CubAddSubdir.cmake | 5 +-- cub/cmake/CubBuildTargetList.cmake | 2 +- cub/cmake/CubInstallRules.cmake | 6 +-- cudax/cmake/cudaxAddSubdir.cmake | 9 +--- cudax/cmake/cudaxBuildTargetList.cmake | 2 +- cudax/cmake/cudaxInstallRules.cmake | 4 +- lib/cmake/cccl/cccl-config.cmake | 19 +++----- .../cmake/cub}/cub-config-version.cmake | 0 .../cmake => lib/cmake/cub}/cub-config.cmake | 4 +- .../cmake/cub}/cub-header-search.cmake | 2 +- .../cmake/cub}/cub-header-search.cmake.in | 0 .../cmake/cudax/cudax-config-version.cmake | 0 .../cmake/cudax/cudax-config.cmake | 11 +++-- .../libcudacxx-config-version.cmake | 0 .../cmake/libcudacxx/libcudacxx-config.cmake | 0 .../libcudacxx/libcudacxx-header-search.cmake | 2 +- .../libcudacxx-header-search.cmake.in | 0 .../cmake => lib/cmake/thrust}/FindTBB.cmake | 0 .../cmake => lib/cmake/thrust}/README.md | 0 .../cmake/thrust}/thrust-config-version.cmake | 0 .../cmake/thrust}/thrust-config.cmake | 9 +--- .../cmake/thrust}/thrust-header-search.cmake | 2 +- .../thrust}/thrust-header-search.cmake.in | 0 libcudacxx/cmake/libcudacxxAddSubdir.cmake | 9 +--- libcudacxx/cmake/libcudacxxInstallRules.cmake | 4 +- test/cmake/CMakeLists.txt | 1 - test/cmake/test_export/CMakeLists.txt | 30 +------------ thrust/cmake/ThrustAddSubdir.cmake | 7 ++- thrust/cmake/ThrustInstallRules.cmake | 6 +-- 33 files changed, 88 insertions(+), 100 deletions(-) create mode 100644 cmake/CCCLAddSubdirHelper.cmake rename {cub/cub/cmake => lib/cmake/cub}/cub-config-version.cmake (100%) rename {cub/cub/cmake => lib/cmake/cub}/cub-config.cmake (96%) rename {cub/cub/cmake => lib/cmake/cub}/cub-header-search.cmake (80%) rename {cub/cub/cmake => lib/cmake/cub}/cub-header-search.cmake.in (100%) rename {cudax/lib => lib}/cmake/cudax/cudax-config-version.cmake (100%) rename {cudax/lib => lib}/cmake/cudax/cudax-config.cmake (92%) rename {libcudacxx/lib => lib}/cmake/libcudacxx/libcudacxx-config-version.cmake (100%) rename {libcudacxx/lib => lib}/cmake/libcudacxx/libcudacxx-config.cmake (100%) rename {libcudacxx/lib => lib}/cmake/libcudacxx/libcudacxx-header-search.cmake (93%) rename {libcudacxx/lib => lib}/cmake/libcudacxx/libcudacxx-header-search.cmake.in (100%) rename {thrust/thrust/cmake => lib/cmake/thrust}/FindTBB.cmake (100%) rename {thrust/thrust/cmake => lib/cmake/thrust}/README.md (100%) rename {thrust/thrust/cmake => lib/cmake/thrust}/thrust-config-version.cmake (100%) rename {thrust/thrust/cmake => lib/cmake/thrust}/thrust-config.cmake (98%) rename {thrust/thrust/cmake => lib/cmake/thrust}/thrust-header-search.cmake (96%) rename {thrust/thrust/cmake => lib/cmake/thrust}/thrust-header-search.cmake.in (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4aca13563c..a76eea6b8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ if (CCCL_ENABLE_INSTALL_RULES) endif() # Support adding CCCL to a parent project via add_subdirectory. +include(cmake/CCCLAddSubdirHelper.cmake) # Always include, this is used by subprojects as well. if (NOT CCCL_TOPLEVEL_PROJECT) include(cmake/CCCLAddSubdir.cmake) endif() diff --git a/cmake/CCCLAddSubdir.cmake b/cmake/CCCLAddSubdir.cmake index b76238442d..def0d1a5e4 100644 --- a/cmake/CCCLAddSubdir.cmake +++ b/cmake/CCCLAddSubdir.cmake @@ -1,6 +1,5 @@ -find_package(CCCL REQUIRED CONFIG - NO_DEFAULT_PATH # Only check the explicit path in HINTS: - HINTS "${CCCL_SOURCE_DIR}" - COMPONENTS ${CCCL_REQUIRED_COMPONENTS} - OPTIONAL_COMPONENTS ${CCCL_OPTIONAL_COMPONENTS} +cccl_add_subdir_helper(CCCL + # These component lists may be set by users to explicitly request subprojects: + REQUIRED_COMPONENTS "${CCCL_REQUIRED_COMPONENTS}" + OPTIONAL_COMPONENTS "${CCCL_OPTIONAL_COMPONENTS}" ) diff --git a/cmake/CCCLAddSubdirHelper.cmake b/cmake/CCCLAddSubdirHelper.cmake new file mode 100644 index 0000000000..d32492e1d2 --- /dev/null +++ b/cmake/CCCLAddSubdirHelper.cmake @@ -0,0 +1,43 @@ +# project_name: The name of the project when calling `find_package`. Case sensitive. +# `PACKAGE_FILEBASE` the name of the project in the config files, ie. ${PACKAGE_FILEBASE}-config.cmake. +# `PACKAGE_PATH` the path to the project's CMake package config files. +function(cccl_add_subdir_helper project_name) + set(options) + set(oneValueArgs PACKAGE_PATH PACKAGE_FILEBASE REQUIRED_COMPONENTS OPTIONAL_COMPONENTS) + set(multiValueArgs) + cmake_parse_arguments(CCCL_SUBDIR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if (DEFINED CCCL_SUBDIR_PACKAGE_FILEBASE) + set(package_filebase "${CCCL_SUBDIR_PACKAGE_FILEBASE}") + else() + string(TOLOWER "${project_name}" package_filebase) + endif() + + if (DEFINED CCCL_SUBDIR_PACKAGE_PATH) + set(package_prefix "${CCCL_SUBDIR_PACKAGE_PATH}/${package_filebase}") + else() + set(package_prefix "${CCCL_SOURCE_DIR}/lib/cmake/${package_filebase}/${package_filebase}") + endif() + + set(CMAKE_FIND_PACKAGE_NAME ${project_name}) + set(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) + if (DEFINED CCCL_SUBDIR_REQUIRED_COMPONENTS) + list(APPEND ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${CCCL_SUBDIR_REQUIRED_COMPONENTS}) + foreach(component IN LISTS CCCL_SUBDIR_REQUIRED_COMPONENTS) + set(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${component} TRUE) + endforeach() + endif() + + if (DEFINED CCCL_SUBDIR_OPTIONAL_COMPONENTS) + list(APPEND ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${CCCL_SUBDIR_OPTIONAL_COMPONENTS}) + endif() + + # This effectively does a `find_package` actually going through the find_package + # machinery. Using `find_package` works for the first configure, but creates + # inconsistencies during subsequent configurations when using CPM.. + # + # More details are in the discussion at + # https://github.com/NVIDIA/libcudacxx/pull/242#discussion_r794003857 + include("${package_prefix}-config-version.cmake") + include("${package_prefix}-config.cmake") +endfunction() diff --git a/cmake/CCCLInstallRules.cmake b/cmake/CCCLInstallRules.cmake index 9b32e1f493..c1c41ebe1d 100644 --- a/cmake/CCCLInstallRules.cmake +++ b/cmake/CCCLInstallRules.cmake @@ -4,6 +4,7 @@ include(GNUInstallDirs) # CCCL has no installable binaries, no need to build before installing: set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE) +# CMake package install(DIRECTORY "${CCCL_SOURCE_DIR}/lib/cmake/cccl" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/" ) diff --git a/cub/cmake/CubAddSubdir.cmake b/cub/cmake/CubAddSubdir.cmake index 99829b196c..5f04ab8d41 100644 --- a/cub/cmake/CubAddSubdir.cmake +++ b/cub/cmake/CubAddSubdir.cmake @@ -1,4 +1 @@ -find_package(CUB REQUIRED CONFIG - NO_DEFAULT_PATH # Only check the explicit path in HINTS: - HINTS "${CMAKE_CURRENT_LIST_DIR}/.." -) +cccl_add_subdir_helper(CUB) diff --git a/cub/cmake/CubBuildTargetList.cmake b/cub/cmake/CubBuildTargetList.cmake index 9517fec40a..90dfa2db2b 100644 --- a/cub/cmake/CubBuildTargetList.cmake +++ b/cub/cmake/CubBuildTargetList.cmake @@ -174,7 +174,7 @@ function(cub_build_target_list) # Set up the CUB target while testing out our find_package scripts. find_package(CUB REQUIRED CONFIG NO_DEFAULT_PATH # Only check the explicit path in HINTS: - HINTS "${CUB_SOURCE_DIR}" + HINTS "${CCCL_SOURCE_DIR}/lib/cmake/cub/" ) # TODO diff --git a/cub/cmake/CubInstallRules.cmake b/cub/cmake/CubInstallRules.cmake index 68a62c71a5..11d6b591e3 100644 --- a/cub/cmake/CubInstallRules.cmake +++ b/cub/cmake/CubInstallRules.cmake @@ -11,8 +11,8 @@ install(DIRECTORY "${CUB_SOURCE_DIR}/cub" PATTERN "*.hpp" ) -install(DIRECTORY "${CUB_SOURCE_DIR}/cub/cmake/" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub" +install(DIRECTORY "${CCCL_SOURCE_DIR}/lib/cmake/cub" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/" REGEX .*header-search.cmake.* EXCLUDE ) # Need to configure a file to store the infix specified in @@ -35,7 +35,7 @@ string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}") list(TRANSFORM from_install_prefix REPLACE ".+" "../") list(JOIN from_install_prefix "" from_install_prefix) -configure_file("${CUB_SOURCE_DIR}/cub/cmake/cub-header-search.cmake.in" +configure_file("${CCCL_SOURCE_DIR}/lib/cmake/cub/cub-header-search.cmake.in" "${CUB_BINARY_DIR}/cub/cmake/cub-header-search.cmake" @ONLY) install(FILES "${CUB_BINARY_DIR}/cub/cmake/cub-header-search.cmake" diff --git a/cudax/cmake/cudaxAddSubdir.cmake b/cudax/cmake/cudaxAddSubdir.cmake index 60e23ae395..bae94045a8 100644 --- a/cudax/cmake/cudaxAddSubdir.cmake +++ b/cudax/cmake/cudaxAddSubdir.cmake @@ -1,8 +1 @@ -# This effectively does a `find_package` actually going through the find_package -# machinery. Using `find_package` works for the first configure, but creates -# inconsistencies during subsequent configurations when using CPM.. -# -# More details are in the discussion at -# https://github.com/NVIDIA/libcudacxx/pull/242#discussion_r794003857 -include(${cudax_SOURCE_DIR}/lib/cmake/cudax/cudax-config-version.cmake) -include(${cudax_SOURCE_DIR}/lib/cmake/cudax/cudax-config.cmake) +cccl_add_subdir_helper(cudax) diff --git a/cudax/cmake/cudaxBuildTargetList.cmake b/cudax/cmake/cudaxBuildTargetList.cmake index 9dcd9a28a7..d2ed44e2be 100644 --- a/cudax/cmake/cudaxBuildTargetList.cmake +++ b/cudax/cmake/cudaxBuildTargetList.cmake @@ -141,7 +141,7 @@ function(cudax_build_target_list) # Set up the cudax::cudax target while testing out our find_package scripts. find_package(cudax REQUIRED CONFIG NO_DEFAULT_PATH # Only check the explicit path in HINTS: - HINTS "${cudax_SOURCE_DIR}" + HINTS "${CCCL_SOURCE_DIR}/lib/cmake/cudax/" ) # Build cudax_TARGETS diff --git a/cudax/cmake/cudaxInstallRules.cmake b/cudax/cmake/cudaxInstallRules.cmake index 1faefdd77c..1716db7a7b 100644 --- a/cudax/cmake/cudaxInstallRules.cmake +++ b/cudax/cmake/cudaxInstallRules.cmake @@ -8,6 +8,6 @@ install(DIRECTORY "${cudax_SOURCE_DIR}/include/cuda" ) # CMake package -install(DIRECTORY "${cudax_SOURCE_DIR}/lib/cmake/cudax" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake" +install(DIRECTORY "${CCCL_SOURCE_DIR}/lib/cmake/cudax" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/" ) diff --git a/lib/cmake/cccl/cccl-config.cmake b/lib/cmake/cccl/cccl-config.cmake index 45fbb0792b..8d32b745b3 100644 --- a/lib/cmake/cccl/cccl-config.cmake +++ b/lib/cmake/cccl/cccl-config.cmake @@ -26,6 +26,9 @@ if (NOT TARGET CCCL::CCCL) add_library(CCCL::CCCL INTERFACE IMPORTED GLOBAL) endif() +message(STATUS "Finding CCCL components: ${components}") +message(STATUS "cccl_cmake_dir: ${cccl_cmake_dir}") + foreach(component IN LISTS components) string(TOLOWER "${component}" component_lower) @@ -39,9 +42,7 @@ foreach(component IN LISTS components) ${cccl_quiet_flag} ${cccl_comp_required_flag} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${cccl_cmake_dir}/../../../libcudacxx/lib/cmake/" # Source layout (GitHub) - "${cccl_cmake_dir}/.." # Install layout + HINTS "${cccl_cmake_dir}/../libcudacxx/" ) # Can't alias other alias targets, so use the uglified target name instead # of libcudacxx::libcudacxx: @@ -54,9 +55,7 @@ foreach(component IN LISTS components) ${cccl_quiet_flag} ${cccl_comp_required_flag} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${cccl_cmake_dir}/../../../cub/cub/cmake/" # Source layout (GitHub) - "${cccl_cmake_dir}/.." # Install layout + HINTS "${cccl_cmake_dir}/../cub/" ) # Can't alias other alias targets, so use the uglified target name instead # of CUB::CUB: @@ -69,9 +68,7 @@ foreach(component IN LISTS components) ${cccl_quiet_flag} ${cccl_comp_required_flag} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${cccl_cmake_dir}/../../../thrust/thrust/cmake/" # Source layout (GitHub) - "${cccl_cmake_dir}/.." # Install layout + HINTS "${cccl_cmake_dir}/../thrust/" ) if (TARGET Thrust::Thrust AND NOT TARGET CCCL::Thrust) @@ -100,9 +97,7 @@ foreach(component IN LISTS components) ${cccl_quiet_flag} ${cccl_comp_required_flag} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${cccl_cmake_dir}/../../../cudax/lib/cmake/" # Source layout (GitHub) - "${cccl_cmake_dir}/.." # Install layout + HINTS "${cccl_cmake_dir}/../cudax/" ) if (TARGET cudax::cudax AND NOT TARGET CCCL::cudax) add_library(CCCL::cudax ALIAS cudax::cudax) diff --git a/cub/cub/cmake/cub-config-version.cmake b/lib/cmake/cub/cub-config-version.cmake similarity index 100% rename from cub/cub/cmake/cub-config-version.cmake rename to lib/cmake/cub/cub-config-version.cmake diff --git a/cub/cub/cmake/cub-config.cmake b/lib/cmake/cub/cub-config.cmake similarity index 96% rename from cub/cub/cmake/cub-config.cmake rename to lib/cmake/cub/cub-config.cmake index 9f86a4ebee..8358c3a540 100644 --- a/cub/cub/cmake/cub-config.cmake +++ b/lib/cmake/cub/cub-config.cmake @@ -64,9 +64,7 @@ if (NOT TARGET CUB::libcudacxx) find_package(libcudacxx ${cub_libcudacxx_version} CONFIG ${_CUB_QUIET_FLAG} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${_CUB_INCLUDE_DIR}/../libcudacxx" # Source layout - "${_CUB_CMAKE_DIR}/.." # Install layout + HINTS "${CMAKE_CURRENT_LIST_DIR}/../libcudacxx/" ) # A second required search allows externally packaged to be used and fails if diff --git a/cub/cub/cmake/cub-header-search.cmake b/lib/cmake/cub/cub-header-search.cmake similarity index 80% rename from cub/cub/cmake/cub-header-search.cmake rename to lib/cmake/cub/cub-header-search.cmake index 47ac7e605b..d4a907570e 100644 --- a/cub/cub/cmake/cub-header-search.cmake +++ b/lib/cmake/cub/cub-header-search.cmake @@ -1,5 +1,5 @@ # Parse version information from version.h in source tree -set(_CUB_VERSION_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..") +set(_CUB_VERSION_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../cub") if(EXISTS "${_CUB_VERSION_INCLUDE_DIR}/cub/version.cuh") set(_CUB_VERSION_INCLUDE_DIR "${_CUB_VERSION_INCLUDE_DIR}" CACHE FILEPATH "" FORCE) # Clear old result set_property(CACHE _CUB_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL) diff --git a/cub/cub/cmake/cub-header-search.cmake.in b/lib/cmake/cub/cub-header-search.cmake.in similarity index 100% rename from cub/cub/cmake/cub-header-search.cmake.in rename to lib/cmake/cub/cub-header-search.cmake.in diff --git a/cudax/lib/cmake/cudax/cudax-config-version.cmake b/lib/cmake/cudax/cudax-config-version.cmake similarity index 100% rename from cudax/lib/cmake/cudax/cudax-config-version.cmake rename to lib/cmake/cudax/cudax-config-version.cmake diff --git a/cudax/lib/cmake/cudax/cudax-config.cmake b/lib/cmake/cudax/cudax-config.cmake similarity index 92% rename from cudax/lib/cmake/cudax/cudax-config.cmake rename to lib/cmake/cudax/cudax-config.cmake index 76ff11ab4e..f30b176357 100644 --- a/cudax/lib/cmake/cudax/cudax-config.cmake +++ b/lib/cmake/cudax/cudax-config.cmake @@ -13,7 +13,12 @@ endif() set(cn_cmake_dir "${CMAKE_CURRENT_LIST_DIR}") set(cn_prefix_dir "${cn_cmake_dir}/../../..") -set(cn_include_dir "${cn_prefix_dir}/include") +find_path(cn_include_dir "cuda/experimental/version.cuh" + NO_DEFAULT_PATH NO_CACHE REQUIRED + HINTS + "${cn_prefix_dir}/cudax/include" # Source + "${cn_prefix_dir}/include" # Install +) if (NOT TARGET cudax::libcudacxx) if (NOT TARGET libcudacxx::libcudacxx) @@ -22,9 +27,7 @@ if (NOT TARGET cudax::libcudacxx) find_package(libcudacxx ${cudax_VERSION} CONFIG ${cn_quiet_flag} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${cn_prefix_dir}/../libcudacxx" # Source layout - "${cn_cmake_dir}/.." # Install layout + HINTS "${cn_cmake_dir}/../libcudacxx" ) # A second required search allows externally packaged to be used and fails if diff --git a/libcudacxx/lib/cmake/libcudacxx/libcudacxx-config-version.cmake b/lib/cmake/libcudacxx/libcudacxx-config-version.cmake similarity index 100% rename from libcudacxx/lib/cmake/libcudacxx/libcudacxx-config-version.cmake rename to lib/cmake/libcudacxx/libcudacxx-config-version.cmake diff --git a/libcudacxx/lib/cmake/libcudacxx/libcudacxx-config.cmake b/lib/cmake/libcudacxx/libcudacxx-config.cmake similarity index 100% rename from libcudacxx/lib/cmake/libcudacxx/libcudacxx-config.cmake rename to lib/cmake/libcudacxx/libcudacxx-config.cmake diff --git a/libcudacxx/lib/cmake/libcudacxx/libcudacxx-header-search.cmake b/lib/cmake/libcudacxx/libcudacxx-header-search.cmake similarity index 93% rename from libcudacxx/lib/cmake/libcudacxx/libcudacxx-header-search.cmake rename to lib/cmake/libcudacxx/libcudacxx-header-search.cmake index 4bbd765112..b58081b852 100644 --- a/libcudacxx/lib/cmake/libcudacxx/libcudacxx-header-search.cmake +++ b/lib/cmake/libcudacxx/libcudacxx-header-search.cmake @@ -1,5 +1,5 @@ # Parse version information from version header: -set(_libcudacxx_VERSION_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../include") +set(_libcudacxx_VERSION_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../libcudacxx/include") if(EXISTS "${_libcudacxx_VERSION_INCLUDE_DIR}/cuda/std/detail/__config") set(_libcudacxx_VERSION_INCLUDE_DIR "${_libcudacxx_VERSION_INCLUDE_DIR}" CACHE FILEPATH "" FORCE) # Clear old result set_property(CACHE _libcudacxx_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL) diff --git a/libcudacxx/lib/cmake/libcudacxx/libcudacxx-header-search.cmake.in b/lib/cmake/libcudacxx/libcudacxx-header-search.cmake.in similarity index 100% rename from libcudacxx/lib/cmake/libcudacxx/libcudacxx-header-search.cmake.in rename to lib/cmake/libcudacxx/libcudacxx-header-search.cmake.in diff --git a/thrust/thrust/cmake/FindTBB.cmake b/lib/cmake/thrust/FindTBB.cmake similarity index 100% rename from thrust/thrust/cmake/FindTBB.cmake rename to lib/cmake/thrust/FindTBB.cmake diff --git a/thrust/thrust/cmake/README.md b/lib/cmake/thrust/README.md similarity index 100% rename from thrust/thrust/cmake/README.md rename to lib/cmake/thrust/README.md diff --git a/thrust/thrust/cmake/thrust-config-version.cmake b/lib/cmake/thrust/thrust-config-version.cmake similarity index 100% rename from thrust/thrust/cmake/thrust-config-version.cmake rename to lib/cmake/thrust/thrust-config-version.cmake diff --git a/thrust/thrust/cmake/thrust-config.cmake b/lib/cmake/thrust/thrust-config.cmake similarity index 98% rename from thrust/thrust/cmake/thrust-config.cmake rename to lib/cmake/thrust/thrust-config.cmake index 7b3d5dfd31..05effef9fa 100644 --- a/thrust/thrust/cmake/thrust-config.cmake +++ b/lib/cmake/thrust/thrust-config.cmake @@ -550,10 +550,7 @@ macro(_thrust_find_CUDA required) ${_THRUST_QUIET_FLAG} ${required} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${_THRUST_INCLUDE_DIR}/dependencies/cub" # Source layout (GitHub) - "${_THRUST_INCLUDE_DIR}/../cub/cub/cmake" # Source layout (Perforce) - "${_THRUST_CMAKE_DIR}/.." # Install layout + HINTS "${_THRUST_CMAKE_DIR}/../cub/" ) if (TARGET CUB::CUB) @@ -709,9 +706,7 @@ if (NOT TARGET Thrust::libcudacxx) find_package(libcudacxx ${thrust_libcudacxx_version} CONFIG ${_THRUST_QUIET_FLAG} NO_DEFAULT_PATH # Only check the explicit HINTS below: - HINTS - "${_THRUST_INCLUDE_DIR}/../libcudacxx" # Source layout - "${_THRUST_CMAKE_DIR}/.." # Install layout + HINTS "${_THRUST_CMAKE_DIR}/../libcudacxx/" # Install layout ) # A second required search allows externally packaged to be used and fails if diff --git a/thrust/thrust/cmake/thrust-header-search.cmake b/lib/cmake/thrust/thrust-header-search.cmake similarity index 96% rename from thrust/thrust/cmake/thrust-header-search.cmake rename to lib/cmake/thrust/thrust-header-search.cmake index 3d69398a78..96f47554a0 100644 --- a/thrust/thrust/cmake/thrust-header-search.cmake +++ b/lib/cmake/thrust/thrust-header-search.cmake @@ -1,5 +1,5 @@ # Parse version information from version.h in source tree -set(_THRUST_VERSION_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..") +set(_THRUST_VERSION_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../thrust") if(EXISTS "${_THRUST_VERSION_INCLUDE_DIR}/thrust/version.h") set(_THRUST_VERSION_INCLUDE_DIR "${_THRUST_VERSION_INCLUDE_DIR}" CACHE FILEPATH "" FORCE) # Clear old result set_property(CACHE _THRUST_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL) diff --git a/thrust/thrust/cmake/thrust-header-search.cmake.in b/lib/cmake/thrust/thrust-header-search.cmake.in similarity index 100% rename from thrust/thrust/cmake/thrust-header-search.cmake.in rename to lib/cmake/thrust/thrust-header-search.cmake.in diff --git a/libcudacxx/cmake/libcudacxxAddSubdir.cmake b/libcudacxx/cmake/libcudacxxAddSubdir.cmake index 4c4ddd679e..86474aab9f 100644 --- a/libcudacxx/cmake/libcudacxxAddSubdir.cmake +++ b/libcudacxx/cmake/libcudacxxAddSubdir.cmake @@ -1,8 +1 @@ -# This effectively does a `find_package` actually going through the find_package -# machinery. Using `find_package` works for the first configure, but creates -# inconsistencies during subsequent configurations when using CPM.. -# -# More details are in the discussion at -# https://github.com/NVIDIA/libcudacxx/pull/242#discussion_r794003857 -include(${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx/libcudacxx-config-version.cmake) -include(${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx/libcudacxx-config.cmake) +cccl_add_subdir_helper(libcudacxx) diff --git a/libcudacxx/cmake/libcudacxxInstallRules.cmake b/libcudacxx/cmake/libcudacxxInstallRules.cmake index 0a63585bbb..05aae89c1c 100644 --- a/libcudacxx/cmake/libcudacxxInstallRules.cmake +++ b/libcudacxx/cmake/libcudacxxInstallRules.cmake @@ -20,7 +20,7 @@ install(DIRECTORY "${libcudacxx_SOURCE_DIR}/include/nv" ) # Libcudacxx cmake package -install(DIRECTORY "${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx" +install(DIRECTORY "${CCCL_SOURCE_DIR}/lib/cmake/libcudacxx" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake" REGEX .*header-search.cmake.* EXCLUDE ) @@ -46,7 +46,7 @@ string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}") list(TRANSFORM from_install_prefix REPLACE ".+" "../") list(JOIN from_install_prefix "" from_install_prefix) -configure_file("${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx/libcudacxx-header-search.cmake.in" +configure_file("${CCCL_SOURCE_DIR}/lib/cmake/libcudacxx/libcudacxx-header-search.cmake.in" "${libcudacxx_BINARY_DIR}/lib/cmake/libcudacxx/libcudacxx-header-search.cmake" @ONLY ) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt index 0c19a023ce..e476822923 100644 --- a/test/cmake/CMakeLists.txt +++ b/test/cmake/CMakeLists.txt @@ -35,7 +35,6 @@ foreach (root_type IN ITEMS SOURCE INSTALL) "${suffix}" ${cmake_opts} -D "CCCL_ROOT=${cccl_root}" - -D "ROOT_TYPE=${root_type}" -D "COMPONENTS=${components}" -D "PACKAGE_TYPE=${package_type}" -D "CCCL_ENABLE_UNSTABLE=${CCCL_ENABLE_UNSTABLE}" diff --git a/test/cmake/test_export/CMakeLists.txt b/test/cmake/test_export/CMakeLists.txt index 5e1973ed2d..38e5f8ec1e 100644 --- a/test/cmake/test_export/CMakeLists.txt +++ b/test/cmake/test_export/CMakeLists.txt @@ -2,8 +2,6 @@ # # Parameters: # - CCCL_ROOT [Path] Root of the CCCL repo, or an installation root. -# - ROOT_TYPE [String] {SOURCE | INSTALL} Whether CCCL_ROOT is an -# installation prefix or the source root. # - COMPONENTS [StringList] {Thrust CUB libcudacxx} Which CCCL subprojects # should be found. # - PACKAGE_TYPE [String] {CCCL | NATIVE | SUBDIR}: @@ -12,7 +10,6 @@ # - SUBDIR -> `set(CCCL_REQUIRED_COMPONENTS )` # `add_subdirectory(${cccl_root})` - cmake_minimum_required(VERSION 3.21) project(CCCLTestExport LANGUAGES CXX) @@ -21,9 +18,6 @@ enable_testing() set(CCCL_ROOT "" CACHE PATH "Root of the CCCL repo, or an installation root.") -set(ROOT_TYPE "" CACHE STRING - "{SOURCE | INSTALL} Whether CCCL_ROOT is an install prefix or source root.") -set_property(CACHE ROOT_TYPE PROPERTY STRINGS SOURCE INSTALL) set(COMPONENTS "" CACHE STRING "DEFAULT for no components, or semi-colon delimited list of Thrust, CUB, and/or libcudacxx.") set(PACKAGE_TYPE "" CACHE STRING @@ -31,31 +25,9 @@ set(PACKAGE_TYPE "" CACHE STRING set_property(CACHE PACKAGE_TYPE PROPERTY STRINGS CCCL NATIVE SUBDIR) message(STATUS "CCCL_ROOT=${CCCL_ROOT}") -message(STATUS "ROOT_TYPE=${ROOT_TYPE}") message(STATUS "COMPONENTS=${COMPONENTS}") message(STATUS "PACKAGE_TYPE=${PACKAGE_TYPE}") -# TODO `ROOT_TYPE` probably won't be needed after the configs are all moved -# to the CCCL repo. -if (ROOT_TYPE STREQUAL "SOURCE") - cmake_path(APPEND CCCL_ROOT thrust OUTPUT_VARIABLE Thrust_ROOT) - cmake_path(APPEND CCCL_ROOT cub OUTPUT_VARIABLE CUB_ROOT) - cmake_path(APPEND CCCL_ROOT libcudacxx OUTPUT_VARIABLE libcudacxx_ROOT) - cmake_path(APPEND CCCL_ROOT cudax OUTPUT_VARIABLE cudax_ROOT) -elseif (ROOT_TYPE STREQUAL "INSTALL") - set(Thrust_ROOT "${CCCL_ROOT}") - set(CUB_ROOT "${CCCL_ROOT}") - set(libcudacxx_ROOT "${CCCL_ROOT}") - set(cudax_ROOT "${CCCL_ROOT}") -else() - message(FATAL_ERROR "Invalid ROOT_TYPE: ${ROOT_TYPE}") -endif() - -message(STATUS "Thrust_ROOT=${Thrust_ROOT}") -message(STATUS "CUB_ROOT=${CUB_ROOT}") -message(STATUS "libcudacxx_ROOT=${libcudacxx_ROOT}") -message(STATUS "cudax_ROOT=${cudax_ROOT}") - function(do_find_package pkg_name pkg_prefix) list(APPEND arg_list REQUIRED @@ -85,7 +57,7 @@ elseif(PACKAGE_TYPE STREQUAL "NATIVE") message(FATAL_ERROR "COMPONENTS=DEFAULT incompatible with PACKAGE_TYPE=NATIVE") endif() foreach (component IN LISTS COMPONENTS) - do_find_package(${component} "${${component}_ROOT}") + do_find_package(${component} "${CCCL_ROOT}") endforeach() elseif(PACKAGE_TYPE STREQUAL "SUBDIR") if (COMPONENTS STREQUAL "DEFAULT") diff --git a/thrust/cmake/ThrustAddSubdir.cmake b/thrust/cmake/ThrustAddSubdir.cmake index d48aa14157..54502689b4 100644 --- a/thrust/cmake/ThrustAddSubdir.cmake +++ b/thrust/cmake/ThrustAddSubdir.cmake @@ -1,6 +1,5 @@ -find_package(Thrust REQUIRED CONFIG - NO_DEFAULT_PATH # Only check the explicit path in HINTS: - HINTS "${CMAKE_CURRENT_LIST_DIR}/.." - COMPONENTS ${THRUST_REQUIRED_SYSTEMS} +cccl_add_subdir_helper(Thrust + # These component lists may be set by users to explicitly request subprojects: + REQUIRED_COMPONENTS ${THRUST_REQUIRED_SYSTEMS} OPTIONAL_COMPONENTS ${THRUST_OPTIONAL_SYSTEMS} ) diff --git a/thrust/cmake/ThrustInstallRules.cmake b/thrust/cmake/ThrustInstallRules.cmake index 84e3bd5a3f..cf18bad122 100644 --- a/thrust/cmake/ThrustInstallRules.cmake +++ b/thrust/cmake/ThrustInstallRules.cmake @@ -11,8 +11,8 @@ install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust" PATTERN "*.inl" ) -install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust/cmake/" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust" +install(DIRECTORY "${CCCL_SOURCE_DIR}/lib/cmake/thrust" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/" REGEX .*header-search.cmake.* EXCLUDE ) @@ -36,7 +36,7 @@ string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}") list(TRANSFORM from_install_prefix REPLACE ".+" "../") list(JOIN from_install_prefix "" from_install_prefix) -configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in" +configure_file("${CCCL_SOURCE_DIR}/lib/cmake/thrust/thrust-header-search.cmake.in" "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake" @ONLY) install(FILES "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake"