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

Refactor away per-project TOPLEVEL flags. #2498

Merged
merged 2 commits into from
Oct 3, 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
23 changes: 6 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -57,22 +62,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)
Expand Down
14 changes: 4 additions & 10 deletions cub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions cudax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 2 additions & 8 deletions libcudacxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
35 changes: 7 additions & 28 deletions thrust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<$<COMPILE_LANGUAGE:CUDA>:-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
Expand All @@ -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()
Expand All @@ -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}")
Expand Down
17 changes: 17 additions & 0 deletions thrust/cmake/ThrustUtilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<$<COMPILE_LANGUAGE:CUDA>:-include${clang_fix_header_path}>")
endif()
endfunction()
Loading