From 1cfe171ee948626668aa90a1922d744ff69b9ecd Mon Sep 17 00:00:00 2001 From: Allison Piper Date: Thu, 3 Oct 2024 14:45:15 -0400 Subject: [PATCH] Refactor away per-project TOPLEVEL flags. (#2498) * Refactor away per-project TOPLEVEL flags. These will never be toplevel projects ever again now that we're a monorepo. They're redundant with the `CCCL_ENABLE_` flags. * Disable cudax when unstable is off. --- CMakeLists.txt | 23 +++++--------------- cub/CMakeLists.txt | 14 ++++-------- cudax/CMakeLists.txt | 8 ++----- libcudacxx/CMakeLists.txt | 10 ++------- thrust/CMakeLists.txt | 35 ++++++------------------------ thrust/cmake/ThrustUtilities.cmake | 17 +++++++++++++++ 6 files changed, 38 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d99bbbde54..f87ad146174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,12 @@ option(CCCL_ENABLE_C "Enable CUDA C Core Library." OFF) option(CCCL_ENABLE_UNSTABLE "Enable targets and developer build options for unstable projects." OFF) if (CCCL_ENABLE_UNSTABLE) - option(CCCL_ENABLE_CUDAX "Enable the CUDA Experimental developer build." ON) + option(CCCL_ENABLE_CUDAX "Enable the CUDA Experimental developer build." ${CCCL_TOPLEVEL_PROJECT}) +else() + # Always off if unstable disabled: + # Note that this doesn't override the cache variable, but rather creates a new + # directory-scoped variable that shadows it. This is sufficient for our purposes. + set(CCCL_ENABLE_CUDAX OFF) endif() include(CTest) @@ -58,22 +63,6 @@ if (CCCL_TOPLEVEL_PROJECT) cccl_build_compiler_targets() endif() -if (CCCL_ENABLE_LIBCUDACXX) - set(LIBCUDACXX_TOPLEVEL_PROJECT ${CCCL_TOPLEVEL_PROJECT}) -endif() - -if (CCCL_ENABLE_CUB) - set(CUB_TOPLEVEL_PROJECT ${CCCL_TOPLEVEL_PROJECT}) -endif() - -if (CCCL_ENABLE_THRUST) - set(THRUST_TOPLEVEL_PROJECT ${CCCL_TOPLEVEL_PROJECT}) -endif() - -if (CCCL_ENABLE_CUDAX) - set(cudax_TOPLEVEL_PROJECT ${CCCL_TOPLEVEL_PROJECT}) -endif() - add_subdirectory(libcudacxx) add_subdirectory(cub) add_subdirectory(thrust) diff --git a/cub/CMakeLists.txt b/cub/CMakeLists.txt index 944f3931169..abc7b1174ae 100644 --- a/cub/CMakeLists.txt +++ b/cub/CMakeLists.txt @@ -3,26 +3,20 @@ # 3.27.5 is the minimum for MSVC build with RDC=true. cmake_minimum_required(VERSION 3.15) -project(CUB LANGUAGES NONE) - -# Determine whether CUB is the top-level project or included into -# another project via add_subdirectory(). -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - set(CUB_TOPLEVEL_PROJECT ON) -endif () - # This must be done before any languages are enabled: -if (CUB_TOPLEVEL_PROJECT) +if (CCCL_ENABLE_CUB) cmake_minimum_required(VERSION 3.21) endif() +project(CUB LANGUAGES NONE) + # This must appear before the installation rules, as it is required by the # GNUInstallDirs CMake module. enable_language(CXX) # Support adding CUB to a parent project via add_subdirectory. # See examples/cmake/add_subdir/CMakeLists.txt for details. -if (NOT CUB_TOPLEVEL_PROJECT) +if (NOT CCCL_ENABLE_CUB) include(cmake/CubAddSubdir.cmake) return() endif() diff --git a/cudax/CMakeLists.txt b/cudax/CMakeLists.txt index 4175cfc98c7..787b4cc580b 100644 --- a/cudax/CMakeLists.txt +++ b/cudax/CMakeLists.txt @@ -2,18 +2,14 @@ # 3.21 is the minimum for the developer build. cmake_minimum_required(VERSION 3.15) -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - set(cudax_TOPLEVEL_PROJECT ON) -endif() - # This must be done before any languages are enabled: -if (cudax_TOPLEVEL_PROJECT) +if (CCCL_ENABLE_CUDAX) cmake_minimum_required(VERSION 3.21) endif() project(cudax LANGUAGES CUDA CXX) -if (NOT cudax_TOPLEVEL_PROJECT) +if (NOT CCCL_ENABLE_CUDAX) include(cmake/cudaxAddSubdir.cmake) return() endif() diff --git a/libcudacxx/CMakeLists.txt b/libcudacxx/CMakeLists.txt index 4c4673d3a06..1ccfb6a92ff 100644 --- a/libcudacxx/CMakeLists.txt +++ b/libcudacxx/CMakeLists.txt @@ -3,13 +3,7 @@ # 3.21 is the minimum for the developer build. cmake_minimum_required(VERSION 3.15) -# Determine whether libcudacxx is the top-level project or included into -# another project via add_subdirectory(). -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - set(LIBCUDACXX_TOPLEVEL_PROJECT ON) -endif() - -if (LIBCUDACXX_TOPLEVEL_PROJECT) +if (CCCL_ENABLE_LIBCUDACXX) cmake_minimum_required(VERSION 3.21) endif() @@ -18,7 +12,7 @@ set(PACKAGE_VERSION 11.0) set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") project(libcudacxx LANGUAGES CXX) -if (NOT LIBCUDACXX_TOPLEVEL_PROJECT) +if (NOT CCCL_ENABLE_LIBCUDACXX) include(cmake/libcudacxxAddSubdir.cmake) return() endif() diff --git a/thrust/CMakeLists.txt b/thrust/CMakeLists.txt index bfc03b37007..562a0d1bc04 100644 --- a/thrust/CMakeLists.txt +++ b/thrust/CMakeLists.txt @@ -2,36 +2,13 @@ # 3.21 is the minimum for the developer build. cmake_minimum_required(VERSION 3.15) -project(Thrust LANGUAGES NONE) - -# Determine whether Thrust is the top-level project or included into -# another project via add_subdirectory() -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - set(THRUST_TOPLEVEL_PROJECT ON) -endif() - -## thrust_fix_clang_nvcc_build_for -# -# Modifies the given target to include a fix for the clang host compiler case. -# The fix consists of force-including a header into each compilation unit. -# -function(thrust_fix_clang_nvcc_build_for target) - if (UNIX) - # Path to the header containing the fix for clang + nvcc < 11.6. For more info, - # check the content of this header. - set(clang_fix_header_path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/testing/fix_clang_nvcc_11.5.h") - - # Only affects host compiler - target_compile_options(${target} PRIVATE - "$<$:-include${clang_fix_header_path}>") - endif() -endfunction() - # This must be done before any languages are enabled: -if (THRUST_TOPLEVEL_PROJECT) +if (CCCL_ENABLE_THRUST) cmake_minimum_required(VERSION 3.21) endif() +project(Thrust LANGUAGES NONE) + # This must appear after our Compiler Hacks or else CMake will delete the cache # and reconfigure from scratch. # This must also appear before the installation rules, as it is required by the @@ -40,7 +17,7 @@ enable_language(CXX) # Support adding Thrust to a parent project via add_subdirectory. # See examples/cmake/add_subdir/CMakeLists.txt for details. -if (NOT THRUST_TOPLEVEL_PROJECT) +if (NOT CCCL_ENABLE_THRUST) include(cmake/ThrustAddSubdir.cmake) return() endif() @@ -67,11 +44,13 @@ if (NOT (THRUST_ENABLE_HEADER_TESTING OR return() endif() +#include first: +include(cmake/ThrustUtilities.cmake) + include(cmake/ThrustBuildCompilerTargets.cmake) include(cmake/ThrustBuildTargetList.cmake) include(cmake/ThrustFindThrust.cmake) include(cmake/ThrustMultiConfig.cmake) -include(cmake/ThrustUtilities.cmake) # Add cache string options for CMAKE_BUILD_TYPE and default to RelWithDebInfo. if ("" STREQUAL "${CMAKE_BUILD_TYPE}") diff --git a/thrust/cmake/ThrustUtilities.cmake b/thrust/cmake/ThrustUtilities.cmake index 3b9828deaee..3e8c444577a 100644 --- a/thrust/cmake/ThrustUtilities.cmake +++ b/thrust/cmake/ThrustUtilities.cmake @@ -41,3 +41,20 @@ function(thrust_configure_cuda_target target_name) CUDA_SEPARABLE_COMPILATION OFF) endif() endfunction() + +## thrust_fix_clang_nvcc_build_for +# +# Modifies the given target to include a fix for the clang host compiler case. +# The fix consists of force-including a header into each compilation unit. +# +function(thrust_fix_clang_nvcc_build_for target) + if (UNIX) + # Path to the header containing the fix for clang + nvcc < 11.6. For more info, + # check the content of this header. + set(clang_fix_header_path "${Thrust_SOURCE_DIR}/testing/fix_clang_nvcc_11.5.h") + + # Only affects host compiler + target_compile_options(${target} PRIVATE + "$<$:-include${clang_fix_header_path}>") + endif() +endfunction()