From 36bc687232f27226dfd5ffd34049929dc4aff536 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 17 Oct 2023 14:19:58 -0400 Subject: [PATCH] Support static builds of gbench and nvbench. Since we updated nvbench, we also support installing nvbench. --- cmake-format-rapids-cmake.json | 9 +++-- rapids-cmake/cpm/gbench.cmake | 14 +++++++- rapids-cmake/cpm/nvbench.cmake | 34 +++++++++++-------- .../cpm/patches/nvbench/use_existing_fmt.diff | 12 ------- rapids-cmake/cpm/versions.json | 9 +---- testing/cpm/CMakeLists.txt | 4 ++- testing/cpm/cpm_gbench-explicit-static.cmake | 25 ++++++++++++++ testing/cpm/cpm_nvbench-explicit-static.cmake | 25 ++++++++++++++ testing/cpm/cpm_nvbench-export.cmake | 9 +++-- 9 files changed, 99 insertions(+), 42 deletions(-) delete mode 100644 rapids-cmake/cpm/patches/nvbench/use_existing_fmt.diff create mode 100644 testing/cpm/cpm_gbench-explicit-static.cmake create mode 100644 testing/cpm/cpm_nvbench-explicit-static.cmake diff --git a/cmake-format-rapids-cmake.json b/cmake-format-rapids-cmake.json index a508e44f..0590a6ff 100644 --- a/cmake-format-rapids-cmake.json +++ b/cmake-format-rapids-cmake.json @@ -108,7 +108,8 @@ }, "rapids_cpm_gbench": { "pargs": { - "nargs": 0 + "nargs": 0, + "flags": ["BUILD_STATIC"] }, "kwargs": { "BUILD_EXPORT_SET": 1, @@ -135,10 +136,12 @@ }, "rapids_cpm_nvbench": { "pargs": { - "nargs": 0 + "nargs": 0, + "flags": ["BUILD_STATIC"] }, "kwargs": { - "BUILD_EXPORT_SET": 1 + "BUILD_EXPORT_SET": 1, + "INSTALL_EXPORT_SET": 1 } }, "rapids_cpm_nvcomp": { diff --git a/rapids-cmake/cpm/gbench.cmake b/rapids-cmake/cpm/gbench.cmake index d21dc630..fc6e02cd 100644 --- a/rapids-cmake/cpm/gbench.cmake +++ b/rapids-cmake/cpm/gbench.cmake @@ -31,11 +31,17 @@ across all RAPIDS projects. rapids_cpm_gbench( [BUILD_EXPORT_SET ] [INSTALL_EXPORT_SET ] + [BUILD_STATIC] [ ...]) .. |PKG_NAME| replace:: benchmark .. include:: common_package_args.txt +.. versionadded:: v23.12.00 +``BUILD_STATIC`` + Will build Google Benchmark statically. No local searching for a previously + built version will occur. + Result Targets ^^^^^^^^^^^^^^ benchmark::benchmark targets will be created @@ -49,6 +55,12 @@ function(rapids_cpm_gbench) set(to_install ON) endif() + set(build_shared ON) + if(BUILD_STATIC IN_LIST ARGN) + set(build_shared OFF) + set(CPM_DOWNLOAD_benchmark ON) # Since we need static we build from source + endif() + include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") rapids_cpm_package_details(benchmark version repository tag shallow exclude) @@ -69,7 +81,7 @@ function(rapids_cpm_gbench) EXCLUDE_FROM_ALL ${exclude} OPTIONS "BENCHMARK_ENABLE_GTEST_TESTS OFF" "BENCHMARK_ENABLE_TESTING OFF" "BENCHMARK_ENABLE_INSTALL ${to_install}" - "CMAKE_INSTALL_LIBDIR ${lib_dir}") + "CMAKE_INSTALL_LIBDIR ${lib_dir}" "BUILD_SHARED_LIBS ${build_shared}") include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake") rapids_cpm_display_patch_status(benchmark) diff --git a/rapids-cmake/cpm/nvbench.cmake b/rapids-cmake/cpm/nvbench.cmake index 3dd7b283..593b2a75 100644 --- a/rapids-cmake/cpm/nvbench.cmake +++ b/rapids-cmake/cpm/nvbench.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,19 +30,17 @@ across all RAPIDS projects. .. code-block:: cmake rapids_cpm_nvbench( [BUILD_EXPORT_SET ] + [INSTALL_EXPORT_SET ] + [BUILD_STATIC] [ ...]) -``BUILD_EXPORT_SET`` - Record that a :cmake:command:`CPMFindPackage(nvbench)` call needs to occur as part of - our build directory export set. +.. |PKG_NAME| replace:: nvbench +.. include:: common_package_args.txt -``CPM_ARGS`` - Any arguments after `CPM_ARGS` will be forwarded to the underlying :cmake:command:`CPMFindPackage( ...)` call - -.. note:: - - RAPIDS-cmake will error out if an INSTALL_EXPORT_SET is provided, as nvbench - doesn't provide any support for installation. +.. versionadded:: v23.12.00 +``BUILD_STATIC`` + Will build nvbench statically. No local searching for a previously + built version will occur. Result Targets ^^^^^^^^^^^^^^ @@ -61,10 +59,15 @@ Result Variables function(rapids_cpm_nvbench) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.nvbench") - set(to_install FALSE) + set(to_install OFF) if(INSTALL_EXPORT_SET IN_LIST ARGN) - message(FATAL_ERROR "nvbench doesn't provide install rules. - It can't be part of an INSTALL_EXPORT_SET") + set(to_install ON) + endif() + + set(build_shared ON) + if(BUILD_STATIC IN_LIST ARGN) + set(build_shared OFF) + set(CPM_DOWNLOAD_nvbench ON) # Since we need static we build from source endif() include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") @@ -90,7 +93,8 @@ function(rapids_cpm_nvbench) PATCH_COMMAND ${patch_command} EXCLUDE_FROM_ALL ${exclude} OPTIONS "NVBench_ENABLE_NVML ${nvbench_with_nvml}" "NVBench_ENABLE_EXAMPLES OFF" - "NVBench_ENABLE_TESTING OFF") + "NVBench_ENABLE_TESTING OFF" "NVBench_ENABLE_INSTALL_RULES ${to_install}" + "BUILD_SHARED_LIBS ${build_shared}") include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake") rapids_cpm_display_patch_status(nvbench) diff --git a/rapids-cmake/cpm/patches/nvbench/use_existing_fmt.diff b/rapids-cmake/cpm/patches/nvbench/use_existing_fmt.diff deleted file mode 100644 index b3a11474..00000000 --- a/rapids-cmake/cpm/patches/nvbench/use_existing_fmt.diff +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/cmake/NVBenchDependencies.cmake b/cmake/NVBenchDependencies.cmake -index d0daa90..c058cbc 100644 ---- a/cmake/NVBenchDependencies.cmake -+++ b/cmake/NVBenchDependencies.cmake -@@ -1,6 +1,7 @@ - ################################################################################ - # fmtlib/fmt - rapids_cpm_find(fmt 9.1.0 -+ GLOBAL_TARGETS fmt fmt::fmt - CPM_ARGS - GITHUB_REPOSITORY fmtlib/fmt - GIT_TAG 9.1.0 diff --git a/rapids-cmake/cpm/versions.json b/rapids-cmake/cpm/versions.json index 6a94a242..b495ff7c 100644 --- a/rapids-cmake/cpm/versions.json +++ b/rapids-cmake/cpm/versions.json @@ -59,14 +59,7 @@ "version" : "0.0", "git_shallow" : false, "git_url" : "https://github.com/NVIDIA/nvbench.git", - "git_tag" : "083fdc2fc130d84805827c0129f84bb7449ec059", - "patches" : [ - { - "file" : "nvbench/use_existing_fmt.diff", - "issue" : "Fix add support for using an existing fmt [https://github.com/NVIDIA/nvbench/pull/125]", - "fixed_in" : "" - } - ] + "git_tag" : "b8f0f6b5832dd632006492fd2434c81fdef0f2de" }, "nvcomp" : { "version" : "2.6.1", diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 505e76c4..13adf187 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -53,6 +53,7 @@ add_cmake_build_test( cpm_fmt-static-lib.cmake ) add_cmake_config_test( cpm_gbench-export.cmake ) add_cmake_config_test( cpm_gbench-simple.cmake ) +add_cmake_config_test( cpm_gbench-explicit-static.cmake) add_cmake_config_test( cpm_gtest-export.cmake ) add_cmake_config_test( cpm_gtest-simple.cmake ) @@ -63,11 +64,12 @@ add_cmake_config_test( cpm_libcudacxx-export.cmake ) add_cmake_config_test( cpm_libcudacxx-simple.cmake ) add_cmake_build_test( cpm_libcudacxx-verify-install-custom-libdir ) -add_cmake_config_test( cpm_nvbench-export.cmake SERIAL ) +add_cmake_config_test( cpm_nvbench-export.cmake SERIAL) add_cmake_config_test( cpm_nvbench-simple.cmake SERIAL) add_cmake_config_test( cpm_nvbench-already-found-fmt.cmake SERIAL) add_cmake_build_test( cpm_nvbench-conda.cmake SERIAL) add_cmake_build_test( cpm_nvbench-conda-fmt.cmake SERIAL) +add_cmake_config_test( cpm_nvbench-explicit-static.cmake SERIAL) add_cmake_config_test( cpm_nvcomp-export.cmake ) add_cmake_config_test( cpm_nvcomp-proprietary-off.cmake ) diff --git a/testing/cpm/cpm_gbench-explicit-static.cmake b/testing/cpm/cpm_gbench-explicit-static.cmake new file mode 100644 index 00000000..11c9fe48 --- /dev/null +++ b/testing/cpm/cpm_gbench-explicit-static.cmake @@ -0,0 +1,25 @@ +#============================================================================= +# Copyright (c) 2023, 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/gbench.cmake) + +rapids_cpm_init() +rapids_cpm_gbench(BUILD_STATIC) + +get_target_property(type benchmark TYPE) +if(NOT type STREQUAL STATIC_LIBRARY) + message(FATAL_ERROR "rapids_cpm_gbench failed to get a static version of gbench") +endif() diff --git a/testing/cpm/cpm_nvbench-explicit-static.cmake b/testing/cpm/cpm_nvbench-explicit-static.cmake new file mode 100644 index 00000000..a619e508 --- /dev/null +++ b/testing/cpm/cpm_nvbench-explicit-static.cmake @@ -0,0 +1,25 @@ +#============================================================================= +# Copyright (c) 2023, 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/nvbench.cmake) + +rapids_cpm_init() +rapids_cpm_nvbench(BUILD_STATIC) + +get_target_property(type nvbench TYPE) +if(NOT type STREQUAL STATIC_LIBRARY) + message(FATAL_ERROR "rapids_cpm_nvbench failed to get a static version of nvbench") +endif() diff --git a/testing/cpm/cpm_nvbench-export.cmake b/testing/cpm/cpm_nvbench-export.cmake index 28a484ca..d42d0b72 100644 --- a/testing/cpm/cpm_nvbench-export.cmake +++ b/testing/cpm/cpm_nvbench-export.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ include(${rapids-cmake-dir}/cpm/nvbench.cmake) rapids_cpm_init() set(CMAKE_CUDA_ARCHITECTURES OFF) rapids_cpm_nvbench(BUILD_EXPORT_SET test) -rapids_cpm_nvbench(BUILD_EXPORT_SET test2) +rapids_cpm_nvbench(BUILD_EXPORT_SET test2 INSTALL_EXPORT_SET test2) get_target_property(packages rapids_export_build_test PACKAGE_NAMES) if(NOT nvbench IN_LIST packages) @@ -30,3 +30,8 @@ get_target_property(packages rapids_export_build_test2 PACKAGE_NAMES) if(NOT nvbench IN_LIST packages) message(FATAL_ERROR "rapids_cpm_nvbench failed to record nvbench needs to be exported") endif() + +get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES) +if(NOT nvbench IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_nvbench failed to record nvbench needs to be exported") +endif()