Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
79 changes: 78 additions & 1 deletion cpp/librtcx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(cmake/rapids_config.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-export)
include(rapids-find)
rapids_cpm_init()
endif()

Expand All @@ -23,7 +25,11 @@ project(
option(RTCX_STATIC_LINK_NVRTC "Use static linking for NVRTC" OFF)
option(RTCX_STATIC_LINK_NVJITLINK "Use static linking for nvJitLink" OFF)

find_package(CUDAToolkit REQUIRED)
rapids_find_package(
CUDAToolkit REQUIRED
BUILD_EXPORT_SET rtcx-exports
INSTALL_EXPORT_SET rtcx-exports
)

if(NOT TARGET zstd)
set(CPM_DOWNLOAD_zstd ON)
Expand Down Expand Up @@ -87,3 +93,74 @@ if(RTCX_STATIC_LINK_NVJITLINK)
else()
target_compile_definitions(rtcx PRIVATE RTCX_STATIC_LINK_LIBNVJITLINK=0)
endif()

# =============================================================================
# Install / Export
# =============================================================================
include(GNUInstallDirs)
include(${rapids-cmake-dir}/cmake/install_lib_dir.cmake)
rapids_cmake_install_lib_dir(lib_dir)

# Option to control install (default ON when built standalone, OFF when used as subdirectory)
option(RTCX_INSTALL "Enable installation of rtcx targets" ${PROJECT_IS_TOP_LEVEL})

set(rtcx_install_code_string
[=[
# Embed functions (add_embed, embed_includes, embed_blob, embed)
# are included automatically so consumers don't need explicit include().
include("${CMAKE_CURRENT_LIST_DIR}/embed.cmake")

# Set rtcx_LIBCXX_DIR for consumers using embed_includes with libcxx headers.
set(rtcx_LIBCXX_DIR "${PACKAGE_PREFIX_DIR}/share/rtcx/libcxx")
]=]
)

string(
CONFIGURE
[=[
# Embed functions (add_embed, embed_includes, embed_blob, embed)
# are included automatically so consumers don't need explicit include().
include("@CMAKE_CURRENT_SOURCE_DIR@/embed.cmake")

# Set rtcx_LIBCXX_DIR for consumers using embed_includes with libcxx headers.
set(rtcx_LIBCXX_DIR "@CMAKE_CURRENT_SOURCE_DIR@/libcxx")
]=]
rtcx_build_code_string
@ONLY
)

if(NOT RTCX_INSTALL)
set(rtcx_exclude_from_install EXCLUDE_FROM_ALL)
endif()

install(
TARGETS rtcx
EXPORT rtcx-exports
ARCHIVE DESTINATION ${lib_dir}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
${rtcx_exclude_from_install}
)

if(RTCX_INSTALL)
install(FILES rtcx.hpp sha256.hpp embed.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rtcx)
install(FILES embed.cmake embed.in.cpp DESTINATION ${lib_dir}/cmake/rtcx)
install(DIRECTORY libcxx/ DESTINATION ${CMAKE_INSTALL_DATADIR}/rtcx/libcxx)

rapids_export(
INSTALL rtcx
EXPORT_SET rtcx-exports
GLOBAL_TARGETS rtcx
NAMESPACE rtcx::
FINAL_CODE_BLOCK rtcx_install_code_string
)
endif()

# Build-tree export (always, so CPM consumers can find_package from the build tree)
rapids_export(
BUILD rtcx
EXPORT_SET rtcx-exports
GLOBAL_TARGETS rtcx
NAMESPACE rtcx::
FINAL_CODE_BLOCK rtcx_build_code_string
)
1 change: 1 addition & 0 deletions cpp/librtcx/RAPIDS_BRANCH
1 change: 1 addition & 0 deletions cpp/librtcx/VERSION
6 changes: 3 additions & 3 deletions cpp/librtcx/cmake/rapids_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0
# cmake-format: on
# =============================================================================
file(READ "${CMAKE_CURRENT_LIST_DIR}/../../../VERSION" _rapids_version)
file(READ "${CMAKE_CURRENT_LIST_DIR}/../VERSION" _rapids_version)
if(_rapids_version MATCHES [[^([0-9][0-9])\.([0-9][0-9])\.([0-9][0-9])]])
set(RAPIDS_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(RAPIDS_VERSION_MINOR "${CMAKE_MATCH_2}")
Expand All @@ -19,11 +19,11 @@ else()
)
endif()

file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/../../../RAPIDS_BRANCH" RAPIDS_BRANCH)
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/../RAPIDS_BRANCH" RAPIDS_BRANCH)
if(NOT RAPIDS_BRANCH)
message(
FATAL_ERROR
"Could not determine branch name to use for checking out rapids-cmake. The file \"${CMAKE_CURRENT_LIST_DIR}/../../../RAPIDS_BRANCH\" is missing."
"Could not determine branch name to use for checking out rapids-cmake. The file \"${CMAKE_CURRENT_LIST_DIR}/../RAPIDS_BRANCH\" is missing."
)
endif()

Expand Down
18 changes: 10 additions & 8 deletions cpp/librtcx/embed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
# cmake-format: on
# =============================================================================

if(NOT TARGET zstd)
message(
FATAL_ERROR "zstd library is required for JIT embedding. Please ensure it is found by CMake."
)
endif()

# This function initializes a target for JIT embedding. It must be called before any calls to
# embed_includes() or embed_blob() for the target. It creates a dedicated INTERFACE library target
# that is used to track registered files and dependencies via target properties. The TARGET argument
Expand Down Expand Up @@ -274,8 +268,16 @@ function(embed TARGET)

set(RUNNER "${TARGET}__jit_embed_run")
add_executable(${RUNNER} EXCLUDE_FROM_ALL "${EMBED_SCRIPT}")
target_include_directories(${RUNNER} PRIVATE ${ZSTD_INCLUDE_DIR})
target_link_libraries(${RUNNER} PRIVATE ${CMAKE_DL_LIBS} zstd)
target_link_libraries(${RUNNER} PRIVATE ${CMAKE_DL_LIBS})
if(NOT ARG_COMPRESSION STREQUAL "none")
if(NOT TARGET zstd)
message(
FATAL_ERROR "embed(): zstd target is required when COMPRESSION is not none."
)
endif()
target_include_directories(${RUNNER} PRIVATE ${ZSTD_INCLUDE_DIR})
target_link_libraries(${RUNNER} PRIVATE zstd)
endif()
set_target_properties(${RUNNER} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED YES)
target_include_directories(${RUNNER} PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR})

Expand Down
Loading