From 4f56b232a600948dbe6bf1858184e8c5aaa5154b Mon Sep 17 00:00:00 2001 From: Allison Piper Date: Tue, 3 Sep 2024 19:07:20 +0000 Subject: [PATCH] Introduce `cccl_configure_target` cmake function. Currently this encapsulates common operations such as setting the CXX/CUDA standard dialect and binary output locations. --- CMakeLists.txt | 2 + cmake/CCCLConfigureTarget.cmake | 57 ++++++++++++++++++++ cub/CMakeLists.txt | 5 -- cub/benchmarks/CMakeLists.txt | 8 +-- cub/benchmarks/nvbench_helper/CMakeLists.txt | 8 +-- cub/cmake/CubBuildTargetList.cmake | 14 +---- cudax/cmake/cudaxBuildTargetList.cmake | 18 +------ thrust/CMakeLists.txt | 5 -- thrust/benchmarks/CMakeLists.txt | 9 +--- thrust/cmake/ThrustBuildTargetList.cmake | 38 +------------ 10 files changed, 68 insertions(+), 96 deletions(-) create mode 100644 cmake/CCCLConfigureTarget.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b229771f5b..4aca13563c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,9 @@ enable_testing() if (CCCL_TOPLEVEL_PROJECT) include(cmake/AppendOptionIfAvailable.cmake) include(cmake/CCCLUtilities.cmake) # include this before other CCCL helpers + include(cmake/CCCLBuildCompilerTargets.cmake) + include(cmake/CCCLConfigureTarget.cmake) include(cmake/CCCLClangdCompileInfo.cmake) cccl_build_compiler_targets() diff --git a/cmake/CCCLConfigureTarget.cmake b/cmake/CCCLConfigureTarget.cmake new file mode 100644 index 0000000000..f131c74af7 --- /dev/null +++ b/cmake/CCCLConfigureTarget.cmake @@ -0,0 +1,57 @@ +set(CCCL_EXECUTABLE_OUTPUT_DIR "${CCCL_BINARY_DIR}/bin") +set(CCCL_LIBRARY_OUTPUT_DIR "${CCCL_BINARY_DIR}/lib") + +# Setup common properties for all test/example/etc targets. +function(cccl_configure_target target_name) + set(options) + set(oneValueArgs DIALECT) + set(multiValueArgs) + cmake_parse_arguments(CCT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + get_target_property(type ${target_name} TYPE) + + if (DEFINED CCT_DIALECT) + set_target_properties(${target_name} + PROPERTIES + CXX_STANDARD ${CCT_DIALECT} + CUDA_STANDARD ${CCT_DIALECT} + # Must manually request that the standards above are actually respected + # or else CMake will silently fail to configure the targets correctly... + # Note that this doesn't actually work as of CMake 3.16: + # https://gitlab.kitware.com/cmake/cmake/-/issues/20953 + # We'll leave these properties enabled in hopes that they will someday + # work. + CXX_STANDARD_REQUIRED ON + CUDA_STANDARD_REQUIRED ON + ) + + get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES) + set(dialect_features) + if (CUDA IN_LIST langs) + list(APPEND dialect_features cuda_std_${CCT_DIALECT}) + endif() + if (CXX IN_LIST langs) + list(APPEND dialect_features cxx_std_${CCT_DIALECT}) + endif() + + get_target_property(type ${target_name} TYPE) + if (${type} STREQUAL "INTERFACE_LIBRARY") + target_compile_features(${target_name} INTERFACE + ${dialect_features} + ) + else() + target_compile_features(${target_name} PUBLIC + ${dialect_features} + ) + endif() + endif() + + if (NOT ${type} STREQUAL "INTERFACE_LIBRARY") + set_target_properties(${target_name} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CCCL_LIBRARY_OUTPUT_DIR}" + LIBRARY_OUTPUT_DIRECTORY "${CCCL_LIBRARY_OUTPUT_DIR}" + RUNTIME_OUTPUT_DIRECTORY "${CCCL_EXECUTABLE_OUTPUT_DIR}" + ) + endif() +endfunction() diff --git a/cub/CMakeLists.txt b/cub/CMakeLists.txt index 0455a2dd1a..b61a756379 100644 --- a/cub/CMakeLists.txt +++ b/cub/CMakeLists.txt @@ -78,11 +78,6 @@ endif () set(CMAKE_CXX_EXTENSIONS OFF) -# Where to put build outputs. Use CMAKE_BINARY_DIR so they'll show up alongside -# Thrust targets when building as part of Thrust. -set(CUB_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib") -set(CUB_EXECUTABLE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin") - cub_build_compiler_targets() cub_build_target_list() diff --git a/cub/benchmarks/CMakeLists.txt b/cub/benchmarks/CMakeLists.txt index 1c3102d0d7..380ad10c68 100644 --- a/cub/benchmarks/CMakeLists.txt +++ b/cub/benchmarks/CMakeLists.txt @@ -70,14 +70,8 @@ function(add_bench target_name bench_name bench_src) set(${target_name} ${bench_target} PARENT_SCOPE) add_executable(${bench_target} "${bench_src}") + cccl_configure_target(${bench_target} DIALECT 17) target_link_libraries(${bench_target} PRIVATE nvbench_helper nvbench::main) - set_target_properties(${bench_target} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${CUB_EXECUTABLE_OUTPUT_DIR}" - CUDA_STANDARD 17 - CXX_STANDARD 17) endfunction() function(add_bench_dir bench_dir) diff --git a/cub/benchmarks/nvbench_helper/CMakeLists.txt b/cub/benchmarks/nvbench_helper/CMakeLists.txt index 008d9cce42..48eab957f3 100644 --- a/cub/benchmarks/nvbench_helper/CMakeLists.txt +++ b/cub/benchmarks/nvbench_helper/CMakeLists.txt @@ -29,17 +29,11 @@ if (CUB_ENABLE_NVBENCH_HELPER_TESTS) test/gen_uniform_distribution.cu test/gen_power_law_distribution.cu test/main.cpp) + cccl_configure_target(${nvbench_helper_test_target} DIALECT 17) target_link_libraries(${nvbench_helper_test_target} PRIVATE nvbench_helper Catch2::Catch2 Boost::math) if ("${device_system}" STREQUAL "cpp") target_compile_definitions(${nvbench_helper_test_target} PRIVATE THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP) endif() - set_target_properties(${nvbench_helper_test_target} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${CUB_EXECUTABLE_OUTPUT_DIR}" - CUDA_STANDARD 17 - CXX_STANDARD 17) endfunction() add_nvbench_helper_test(cpp) diff --git a/cub/cmake/CubBuildTargetList.cmake b/cub/cmake/CubBuildTargetList.cmake index 1539972482..9517fec40a 100644 --- a/cub/cmake/CubBuildTargetList.cmake +++ b/cub/cmake/CubBuildTargetList.cmake @@ -49,23 +49,13 @@ define_property(TARGET PROPERTY _CUB_PREFIX ) function(cub_set_target_properties target_name dialect prefix) + cccl_configure_target(${target_name} DIALECT ${dialect}) + set_target_properties(${target_name} PROPERTIES _CUB_DIALECT ${dialect} _CUB_PREFIX ${prefix} ) - - get_target_property(type ${target_name} TYPE) - if (NOT ${type} STREQUAL "INTERFACE_LIBRARY") - set_target_properties(${target_name} - PROPERTIES - CXX_STANDARD ${dialect} - CUDA_STANDARD ${dialect} - ARCHIVE_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${CUB_EXECUTABLE_OUTPUT_DIR}" - ) - endif() endfunction() # Get a cub property from a target and store it in var_name diff --git a/cudax/cmake/cudaxBuildTargetList.cmake b/cudax/cmake/cudaxBuildTargetList.cmake index 2e685ffb14..9dcd9a28a7 100644 --- a/cudax/cmake/cudaxBuildTargetList.cmake +++ b/cudax/cmake/cudaxBuildTargetList.cmake @@ -33,10 +33,6 @@ # to ensure that dialect information is updated correctly, e.g. # `_cn_clone_target_properties(${my_cudax_test} ${some_cudax_target})` -# Place build outputs in the root project dir: -set(cudax_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib") -set(cudax_EXECUTABLE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin") - # Define available dialects: set(cudax_CPP_DIALECT_OPTIONS 17 20 @@ -66,23 +62,13 @@ define_property(TARGET PROPERTY _cudax_PREFIX ) function(cudax_set_target_properties target_name dialect prefix) + cccl_configure_target(${target_name} DIALECT 17) + set_target_properties(${target_name} PROPERTIES _cudax_DIALECT ${dialect} _cudax_PREFIX ${prefix} ) - - get_target_property(type ${target_name} TYPE) - if (NOT ${type} STREQUAL "INTERFACE_LIBRARY") - set_target_properties(${target_name} - PROPERTIES - CXX_STANDARD ${dialect} - CUDA_STANDARD ${dialect} - ARCHIVE_OUTPUT_DIRECTORY "${cudax_LIBRARY_OUTPUT_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${cudax_LIBRARY_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${cudax_EXECUTABLE_OUTPUT_DIR}" - ) - endif() endfunction() # Get a cudax property from a target and store it in var_name diff --git a/thrust/CMakeLists.txt b/thrust/CMakeLists.txt index 8e16503b7c..ecbb08d360 100644 --- a/thrust/CMakeLists.txt +++ b/thrust/CMakeLists.txt @@ -92,11 +92,6 @@ endif () # Disable compiler extensions: set(CMAKE_CXX_EXTENSIONS OFF) -# Where to put build outputs. Use CMAKE_BINARY_DIR so they'll show up in the -# top-level project's dir when building Thrust via add_subdirectory. -set(THRUST_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib") -set(THRUST_EXECUTABLE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin") - thrust_configure_multiconfig() thrust_find_thrust() thrust_build_compiler_targets() diff --git a/thrust/benchmarks/CMakeLists.txt b/thrust/benchmarks/CMakeLists.txt index a131f64bd9..9d2ec1bc6f 100644 --- a/thrust/benchmarks/CMakeLists.txt +++ b/thrust/benchmarks/CMakeLists.txt @@ -32,14 +32,7 @@ function(add_bench target_name bench_name bench_src) set(${target_name} ${bench_target} PARENT_SCOPE) add_executable(${bench_target} "${bench_src}") - - set_target_properties(${bench_target} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${THRUST_LIBRARY_OUTPUT_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${THRUST_LIBRARY_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${THRUST_EXECUTABLE_OUTPUT_DIR}" - CUDA_STANDARD 17 - CXX_STANDARD 17) + cccl_configure_target(${bench_target} DIALECT 17) target_link_libraries(${bench_target} PRIVATE nvbench_helper nvbench::main) endfunction() diff --git a/thrust/cmake/ThrustBuildTargetList.cmake b/thrust/cmake/ThrustBuildTargetList.cmake index f613ede431..f1e9cbcaf2 100644 --- a/thrust/cmake/ThrustBuildTargetList.cmake +++ b/thrust/cmake/ThrustBuildTargetList.cmake @@ -52,6 +52,8 @@ define_property(TARGET PROPERTY _THRUST_PREFIX ) function(thrust_set_target_properties target_name host device dialect prefix) + cccl_configure_target(${target_name} DIALECT ${dialect}) + set_target_properties(${target_name} PROPERTIES _THRUST_HOST ${host} @@ -59,42 +61,6 @@ function(thrust_set_target_properties target_name host device dialect prefix) _THRUST_DIALECT ${dialect} _THRUST_PREFIX ${prefix} ) - - get_property(langs GLOBAL PROPERTY ENABLED_LANGUAGES) - set(standard_features) - if (CUDA IN_LIST langs) - list(APPEND standard_features cuda_std_${dialect}) - endif() - if (CXX IN_LIST langs) - list(APPEND standard_features cxx_std_${dialect}) - endif() - - get_target_property(type ${target_name} TYPE) - if (${type} STREQUAL "INTERFACE_LIBRARY") - target_compile_features(${target_name} INTERFACE - ${standard_features} - ) - else() - target_compile_features(${target_name} PUBLIC - ${standard_features} - ) - set_target_properties(${target_name} - PROPERTIES - CXX_STANDARD ${dialect} - CUDA_STANDARD ${dialect} - # Must manually request that the standards above are actually respected - # or else CMake will silently fail to configure the targets correctly... - # Note that this doesn't actually work as of CMake 3.16: - # https://gitlab.kitware.com/cmake/cmake/-/issues/20953 - # We'll leave these properties enabled in hopes that they will someday - # work. - CXX_STANDARD_REQUIRED ON - CUDA_STANDARD_REQUIRED ON - ARCHIVE_OUTPUT_DIRECTORY "${THRUST_LIBRARY_OUTPUT_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${THRUST_LIBRARY_OUTPUT_DIR}" - RUNTIME_OUTPUT_DIRECTORY "${THRUST_EXECUTABLE_OUTPUT_DIR}" - ) - endif() endfunction() # Get a thrust property from a target and store it in var_name