Skip to content

Commit

Permalink
Introduce cccl_configure_target cmake function.
Browse files Browse the repository at this point in the history
Currently this encapsulates common operations such as setting the
CXX/CUDA standard dialect and binary output locations.
  • Loading branch information
alliepiper committed Sep 6, 2024
1 parent 082f697 commit 4f56b23
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 96 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
57 changes: 57 additions & 0 deletions cmake/CCCLConfigureTarget.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 0 additions & 5 deletions cub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 1 addition & 7 deletions cub/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions cub/benchmarks/nvbench_helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 2 additions & 12 deletions cub/cmake/CubBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions cudax/cmake/cudaxBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions thrust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 1 addition & 8 deletions thrust/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
38 changes: 2 additions & 36 deletions thrust/cmake/ThrustBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,15 @@ 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}
_THRUST_DEVICE ${device}
_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
Expand Down

0 comments on commit 4f56b23

Please sign in to comment.