Skip to content
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

rapids_cpm_gtest adds support for BUILD_STATIC #576

Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@
},
"rapids_cpm_gtest": {
"pargs": {
"nargs": 0
"nargs": 0,
"flags": [
"BUILD_STATIC"
]
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
Expand Down
16 changes: 15 additions & 1 deletion rapids-cmake/cpm/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ across all RAPIDS projects.

rapids_cpm_gtest( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[BUILD_STATIC]
[<CPM_ARGS> ...])

.. |PKG_NAME| replace:: GTest
.. include:: common_package_args.txt

.. versionadded:: v24.06.00

``BUILD_STATIC``
Will build `Google Test` statically. No local searching for a previously
built version will occur.

Result Targets
^^^^^^^^^^^^^^
GTest::gtest, GTest::gmock, GTest::gtest_main, GTest::gmock_main targets will be created
Expand All @@ -56,6 +63,12 @@ function(rapids_cpm_gtest)
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(GTest version repository tag shallow exclude)

Expand All @@ -70,7 +83,8 @@ function(rapids_cpm_gtest)
GIT_TAG ${tag}
GIT_SHALLOW ${shallow} ${patch_command}
EXCLUDE_FROM_ALL ${exclude}
OPTIONS "INSTALL_GTEST ${to_install}" "CMAKE_POSITION_INDEPENDENT_CODE ON")
OPTIONS "INSTALL_GTEST ${to_install}" "CMAKE_POSITION_INDEPENDENT_CODE ON"
"BUILD_SHARED_LIBS ${build_shared}")

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(GTest)
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ 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 )
add_cmake_config_test( cpm_gtest-static.cmake )
add_cmake_config_test( cpm_gtest-explicit-static.cmake )

add_cmake_config_test( cpm_libcudacxx-after_cpmfind.cmake SERIAL)
add_cmake_config_test( cpm_libcudacxx-export.cmake )
Expand Down
41 changes: 41 additions & 0 deletions testing/cpm/cpm_gtest-explicit-static.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/gtest.cmake)

rapids_cpm_init()
rapids_cpm_gtest(BUILD_STATIC)

get_target_property(type gtest TYPE)
if(NOT type STREQUAL STATIC_LIBRARY)
message(FATAL_ERROR "rapids_cpm_gtest failed to get a static version of gtest")
endif()

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/use_gtest.cpp" [=[
#include <gtest/gtest.h>

// The fixture for testing class Foo.
class FooTest : public testing::Test {

FooTest() {}
~FooTest() override { }

void SetUp() override {}
void TearDown() override {}
};
]=])
add_library(uses_gtest SHARED ${CMAKE_CURRENT_BINARY_DIR}/use_gtest.cpp)
target_link_libraries(uses_gtest PRIVATE GTest::gtest)
Loading