Skip to content

Use CMake's FILE_SET for better modeling project. #1412

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

Merged
merged 2 commits into from
Dec 30, 2024
Merged
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
73 changes: 49 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ set(stdexec_export_targets)
# Define the main library
add_library(stdexec INTERFACE)

file(GLOB_RECURSE exec_headers CONFIGURE_DEPENDS include/exec/*.hpp)
file(GLOB_RECURSE stdexec_headers CONFIGURE_DEPENDS include/stdexec/*.hpp)
target_sources(stdexec
PUBLIC
FILE_SET headers
TYPE HEADERS
BASE_DIRS include
FILES
${exec_headers}
${stdexec_headers}
# stdexec_version_config.hpp is generated by rapids' script
FILE_SET version_config
TYPE HEADERS
BASE_DIRS ${CMAKE_BINARY_DIR}/include
FILES
${CMAKE_BINARY_DIR}/include/stdexec_version_config.hpp
)
list(APPEND stdexec_export_targets stdexec)

# Set library version
Expand All @@ -160,10 +177,6 @@ set_target_properties(stdexec PROPERTIES

# Declare the public include directories
include(GNUInstallDirs)
target_include_directories(stdexec INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_link_libraries(stdexec INTERFACE Threads::Threads)

Expand Down Expand Up @@ -269,9 +282,15 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
endif()

if(STDEXEC_ENABLE_CUDA)

file(GLOB_RECURSE nvexec_sources include/nvexec/*.cuh)
add_library(nvexec INTERFACE ${nvexec_sources})
file(GLOB_RECURSE nvexec_headers CONFIGURE_DEPENDS include/nvexec/*.cuh)
add_library(nvexec INTERFACE)
target_sources(nvexec
PUBLIC
FILE_SET headers
TYPE HEADERS
BASE_DIRS include
FILES ${nvexec_headers}
)
list(APPEND stdexec_export_targets nvexec)
add_library(STDEXEC::nvexec ALIAS nvexec)

Expand All @@ -283,6 +302,10 @@ if(STDEXEC_ENABLE_CUDA)
target_link_options(nvexec INTERFACE
$<$<AND:$<CXX_COMPILER_ID:NVHPC>,$<COMPILE_LANGUAGE:CXX>>:-stdpar -gpu=cc${CMAKE_CUDA_ARCHITECTURES}>)

install(TARGETS nvexec
EXPORT stdexec-exports
FILE_SET headers)

if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC"))
include(rapids-cuda)
# Needs to run before `enable_language(CUDA)`
Expand Down Expand Up @@ -330,16 +353,29 @@ if (STDEXEC_ENABLE_TBB)
INSTALL_EXPORT_SET stdexec-exports
)

file(GLOB_RECURSE tbbpool_sources include/execpools/tbb/*.hpp)
add_library(tbbpool INTERFACE ${tbbpool_sources})
# CONFIGURE_DEPENDS ensures that CMake reconfigures when a relevant hpp file is
# added or removed.
file(GLOB_RECURSE tbbpool_headers CONFIGURE_DEPENDS include/execpools/tbb/*.hpp)
add_library(tbbpool INTERFACE)
list(APPEND stdexec_export_targets tbbpool)
add_library(STDEXEC::tbbpool ALIAS tbbpool)
target_sources(tbbpool
PUBLIC
FILE_SET headers
TYPE HEADERS
BASE_DIRS include
FILES ${tbbpool_headers}
)

target_link_libraries(tbbpool
INTERFACE
STDEXEC::stdexec
TBB::tbb
)

install(TARGETS tbbpool
EXPORT stdexec-exports
FILE_SET headers)
endif()

option(STDEXEC_ENABLE_TASKFLOW "Enable TaskFlow targets" OFF)
Expand Down Expand Up @@ -435,10 +471,6 @@ endif()

set(SYSTEM_CONTEXT_SOURCES src/system_context/system_context.cpp)
add_library(system_context STATIC ${SYSTEM_CONTEXT_SOURCES})
target_include_directories(system_context PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(system_context PUBLIC cxx_std_20)
set_target_properties(system_context PROPERTIES
CXX_STANDARD 20
Expand All @@ -448,7 +480,7 @@ target_compile_options(system_context PUBLIC
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/Zc:__cplusplus /Zc:preprocessor>
)
add_library(STDEXEC::system_context ALIAS system_context)

target_link_libraries(system_context PUBLIC stdexec)


if(CMAKE_CROSSCOMPILING)
Expand Down Expand Up @@ -499,16 +531,9 @@ endif()
include(CPack)

install(TARGETS stdexec system_context
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT stdexec-exports)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/include/stdexec_version_config.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
EXPORT stdexec-exports
FILE_SET headers
FILE_SET version_config)

##############################################################################
# Install exports ------------------------------------------------------------
Expand Down
Loading