Skip to content

Commit

Permalink
Add rapids_cpm_bs_thread_pool()
Browse files Browse the repository at this point in the history
Add a function to download and export bshoshany/thread-pool.
  • Loading branch information
KyleFromNVIDIA committed Jul 22, 2024
1 parent fef5453 commit e2ee60a
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 0 deletions.
131 changes: 131 additions & 0 deletions rapids-cmake/cpm/bs_thread_pool.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# =============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================
include_guard(GLOBAL)

#[=======================================================================[.rst:
rapids_cpm_bs_thread_pool
-------------------------
.. versionadded:: v24.10.00
Allow projects to find or build `thread-pool` via `CPM` with built-in
tracking of these dependencies for correct export support.
Uses the version of `thread-pool` :ref:`specified in the version file <cpm_versions>` for consistency
across all RAPIDS projects.
.. code-block:: cmake
rapids_cpm_bs_thread_pool( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[<CPM_ARGS> ...])
.. |PKG_NAME| replace:: bs_thread_pool
.. include:: common_package_args.txt
Result Targets
^^^^^^^^^^^^^^
`BS::thread_pool` target will be created
Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`bs_thread_pool_SOURCE_DIR` is set to the path to the source directory of `thread-pool`.
:cmake:variable:`bs_thread_pool_BINARY_DIR` is set to the path to the build directory of `thread-pool`.
:cmake:variable:`bs_thread_pool_ADDED` is set to a true value if `thread-pool` has not been added before.
:cmake:variable:`bs_thread_pool_VERSION` is set to the version of `thread-pool` specified by the versions.json.
#]=======================================================================]
function(rapids_cpm_bs_thread_pool)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.bs_thread_pool")

set(options)
set(one_value BUILD_EXPORT_SET INSTALL_EXPORT_SET)
set(multi_value)
cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})

# Fix up _RAPIDS_UNPARSED_ARGUMENTS to have EXPORT_SETS as this is need for rapids_cpm_find
if(_RAPIDS_INSTALL_EXPORT_SET)
list(APPEND _RAPIDS_EXPORT_ARGUMENTS INSTALL_EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET})
endif()
if(_RAPIDS_BUILD_EXPORT_SET)
list(APPEND _RAPIDS_EXPORT_ARGUMENTS BUILD_EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
endif()
set(_RAPIDS_UNPARSED_ARGUMENTS ${_RAPIDS_EXPORT_ARGUMENTS})

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(bs_thread_pool version repository tag shallow exclude)

include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake")
rapids_cpm_generate_patch_command(bs_thread_pool ${version} patch_command)

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(bs_thread_pool ${version} ${ARGN}
CPM_ARGS
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow} ${patch_command}
EXCLUDE_FROM_ALL ${exclude}
DOWNLOAD_ONLY ON)

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(bs_thread_pool)

# Extract the major version value of bs_thread_pool to use with `rapids-export` to setup
# compatibility rules
include("${rapids-cmake-dir}/cmake/parse_version.cmake")
rapids_cmake_parse_version(MAJOR ${version} ${version})

# Set up install rules Need to be re-entrant safe so only call when `bs_thread_pool_ADDED`
if(bs_thread_pool_ADDED)
if(NOT TARGET thread_pool)
add_library(thread_pool INTERFACE)
target_include_directories(thread_pool
INTERFACE "$<BUILD_INTERFACE:${bs_thread_pool_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
install(TARGETS thread_pool EXPORT bs_thread_pool-targets)
endif()
if(_RAPIDS_BUILD_EXPORT_SET)
include("${rapids-cmake-dir}/export/export.cmake")
rapids_export(BUILD bs_thread_pool
VERSION ${version}
EXPORT_SET bs_thread_pool-targets
GLOBAL_TARGETS thread_pool
NAMESPACE BS::)
include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(BUILD bs_thread_pool [=[${CMAKE_CURRENT_LIST_DIR}]=]
EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
endif()
if(_RAPIDS_INSTALL_EXPORT_SET AND NOT exclude)
include(GNUInstallDirs)
install(DIRECTORY "${bs_thread_pool_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
include("${rapids-cmake-dir}/export/export.cmake")
rapids_export(INSTALL bs_thread_pool
VERSION ${version}
EXPORT_SET bs_thread_pool-targets
GLOBAL_TARGETS thread_pool
NAMESPACE BS::)
endif()
endif()

if(NOT TARGET BS::thread_pool AND TARGET thread_pool)
add_library(BS::thread_pool ALIAS thread_pool)
endif()

# Propagate up variables that CPMFindPackage provide
set(bs_thread_pool_SOURCE_DIR "${bs_thread_pool_SOURCE_DIR}" PARENT_SCOPE)
set(bs_thread_pool_BINARY_DIR "${bs_thread_pool_BINARY_DIR}" PARENT_SCOPE)
set(bs_thread_pool_ADDED "${bs_thread_pool_ADDED}" PARENT_SCOPE)
set(bs_thread_pool_VERSION ${version} PARENT_SCOPE)
endfunction()
5 changes: 5 additions & 0 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"git_url": "https://github.com/google/benchmark.git",
"git_tag": "v${version}"
},
"bs_thread_pool": {
"version": "4.1.0",
"git_url": "https://github.com/bshoshany/thread-pool.git",
"git_tag": "097aa718f25d44315cadb80b407144ad455ee4f9"
},
"CCCL": {
"version": "2.5.0",
"git_shallow": false,
Expand Down
5 changes: 5 additions & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ add_cmake_config_test( cpm_generate_patch_command-override.cmake )
add_cmake_config_test( cpm_generate_patch_command-current_json_dir.cmake )
add_cmake_config_test( cpm_generate_patch_command-verify-copyright-header.cmake )

add_cmake_config_test( cpm_bs_thread_pool-simple.cmake )
add_cmake_config_test( cpm_bs_thread_pool-export.cmake )
add_cmake_build_test( cpm_bs_thread_pool-build-config-works.cmake )
add_cmake_build_test( cpm_bs_thread_pool-install-config-works.cmake )

add_cmake_config_test( cpm_cccl-simple.cmake )
add_cmake_config_test( cpm_cccl-export.cmake )
add_cmake_build_test( cpm_cccl-preserve-custom-install-loc )
Expand Down
40 changes: 40 additions & 0 deletions testing/cpm/cpm_bs_thread_pool-build-config-works.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#=============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/bs_thread_pool.cmake)

rapids_cpm_init()
rapids_cpm_bs_thread_pool(BUILD_EXPORT_SET test)

# Add a custom command that verifies that the expect files have
# been installed for each component
file(WRITE "${CMAKE_BINARY_DIR}/check_bs_thread_pool_dir/CMakeLists.txt" "
cmake_minimum_required(VERSION 3.26.4)
project(verify_bs_thread_pool LANGUAGES CXX)
set(CMAKE_PREFIX_PATH \"${CMAKE_BINARY_DIR}/\")
find_package(bs_thread_pool REQUIRED)
file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/stub.cpp\" \"#include <BS_thread_pool.hpp>\")
add_library(uses_bs_thread_pool SHARED stub.cpp)
target_link_libraries(uses_bs_thread_pool PRIVATE BS::thread_pool)
")

add_custom_target(verify_build_config ALL
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/check_bs_thread_pool_dir/build"
COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/check_bs_thread_pool_dir" -B="${CMAKE_BINARY_DIR}/build"
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}/build"
)
32 changes: 32 additions & 0 deletions testing/cpm/cpm_bs_thread_pool-export.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#=============================================================================
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/bs_thread_pool.cmake)

rapids_cpm_init()

rapids_cpm_bs_thread_pool(BUILD_EXPORT_SET test)
rapids_cpm_bs_thread_pool(INSTALL_EXPORT_SET test2)

get_target_property(packages rapids_export_build_test PACKAGE_NAMES)
if(NOT bs_thread_pool IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_bs_thread_pool failed to record bs_thread_pool needs to be exported")
endif()

get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES)
if(NOT bs_thread_pool IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_bs_thread_pool failed to record bs_thread_pool needs to be exported")
endif()
41 changes: 41 additions & 0 deletions testing/cpm/cpm_bs_thread_pool-install-config-works.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#=============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/bs_thread_pool.cmake)

rapids_cpm_init()
rapids_cpm_bs_thread_pool(BUILD_EXPORT_SET test)

# Add a custom command that verifies that the expect files have
# been installed for each component
file(WRITE "${CMAKE_BINARY_DIR}/check_bs_thread_pool_dir/CMakeLists.txt" "
cmake_minimum_required(VERSION 3.26.4)
project(verify_bs_thread_pool LANGUAGES CXX)
set(CMAKE_PREFIX_PATH \"${CMAKE_BINARY_DIR}/\")
find_package(bs_thread_pool REQUIRED)
file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/stub.cpp\" \"#include <BS_thread_pool.hpp>\")
add_library(uses_bs_thread_pool SHARED stub.cpp)
target_link_libraries(uses_bs_thread_pool PRIVATE BS::thread_pool)
")

add_custom_target(verify_build_config ALL
COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --prefix ./install/
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/check_bs_thread_pool_dir/build"
COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/check_bs_thread_pool_dir" -B="${CMAKE_BINARY_DIR}/build"
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}/build"
)
34 changes: 34 additions & 0 deletions testing/cpm/cpm_bs_thread_pool-simple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#=============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/bs_thread_pool.cmake)

rapids_cpm_init()

if(TARGET thread_pool)
message(FATAL_ERROR "Expected thread_pool not to exist")
endif()

rapids_cpm_bs_thread_pool()

if(NOT TARGET thread_pool)
message(FATAL_ERROR "Expected thread_pool target to exist")
endif()
if(NOT TARGET BS::thread_pool)
message(FATAL_ERROR "Expected BS::thread_pool target to exist")
endif()

rapids_cpm_bs_thread_pool()

0 comments on commit e2ee60a

Please sign in to comment.