Skip to content

Commit a8df774

Browse files
committed
Make failure report a little friendlier
If configuration fails by not finding GTest when testing was turned on, complete successfully and warn about the lack of GTest and provide a reference to the cmake script to download from GitHub.
1 parent 1fd6028 commit a8df774

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

CMakeLists.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,26 @@ target_sources(
2828
)
2929

3030
if(OPTIONAL_ENABLE_TESTING)
31+
find_package(GTest QUIET)
32+
if(GTest_FOUND)
3133
# Create the library target and named header set for testing beman_optional
3234
# and mark the set private
3335
add_executable(beman_optional_test)
3436
target_sources(
35-
beman_optional_test
36-
PRIVATE
37-
FILE_SET beman_optional_test_headers
38-
TYPE HEADERS
39-
BASE_DIRS tests
37+
beman_optional_test
38+
PRIVATE
39+
FILE_SET beman_optional_test_headers
40+
TYPE HEADERS
41+
BASE_DIRS tests
4042
)
41-
43+
# Tests
4244
add_subdirectory(tests/beman/optional)
45+
else()
46+
message(WARNING "
47+
No provider for GTest. Unable to build tests.
48+
Consider using CMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/use-fetch-content.cmake as documented in the README.md
49+
")
50+
endif()
4351
endif()
4452

4553
add_subdirectory(include/beman/optional)

cmake/use-fetch-content.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function(BemanOptional_provideDependency method package_name)
149149
"to FetchContent logic fetching ${BemanOptional_repo} at "
150150
"${BemanOptional_tag} according to ${BemanOptional_lockfile}."
151151
)
152-
message(DEBUG "${BemanOptional_debug}")
152+
message(STATUS "${BemanOptional_debug}")
153153
FetchContent_Declare(
154154
"${BemanOptional_name}"
155155
GIT_REPOSITORY "${BemanOptional_repo}"
@@ -161,12 +161,13 @@ function(BemanOptional_provideDependency method package_name)
161161

162162
# Important! <PackageName>_FOUND tells CMake that `find_package` is
163163
# not needed for this package anymore
164+
message(STATUS "setting ${BemanOptional_pkgName}_FOUND to true")
164165
set("${BemanOptional_pkgName}_FOUND" TRUE PARENT_SCOPE)
165166
endif()
166167
endif()
167168
endforeach()
168169

169-
set(GTest_FOUND TRUE PARENT_SCOPE)
170+
# set(GTest_FOUND TRUE PARENT_SCOPE)
170171
endfunction()
171172

172173
cmake_language(

tests/beman/optional/CMakeLists.txt

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,36 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
# cmake-format: on
55

6-
find_package(GTest REQUIRED)
7-
8-
# Tests
9-
target_sources(
10-
beman_optional_test
11-
PRIVATE
12-
optional.t.cpp
13-
optional_constexpr.t.cpp
14-
optional_monadic.t.cpp
15-
optional_range_support.t.cpp
16-
optional_ref.t.cpp
17-
optional_ref_monadic.t.cpp
18-
)
19-
20-
target_sources(
21-
beman_optional_test
22-
PRIVATE
23-
FILE_SET beman_optional_test_headers
24-
TYPE HEADERS
25-
FILES test_types.hpp test_utilities.hpp
26-
)
27-
28-
target_link_libraries(
29-
beman_optional_test
30-
PRIVATE beman_optional GTest::gtest GTest::gtest_main
31-
)
32-
33-
# Issue #32: Re-enable ASAN run CI/clang-19.
34-
#
35-
# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some
36-
# platforms. Temporary switch to gtest_add_tests and skip some Asan checks.
37-
# Change also applied for CI flows.
38-
include(GoogleTest)
39-
gtest_add_tests(TARGET beman_optional_test "" AUTO)
6+
target_sources(
7+
beman_optional_test
8+
PRIVATE
9+
optional.t.cpp
10+
optional_constexpr.t.cpp
11+
optional_monadic.t.cpp
12+
optional_range_support.t.cpp
13+
optional_ref.t.cpp
14+
optional_ref_monadic.t.cpp
15+
)
16+
17+
target_sources(
18+
beman_optional_test
19+
PRIVATE
20+
FILE_SET beman_optional_test_headers
21+
TYPE HEADERS
22+
FILES test_types.hpp test_utilities.hpp
23+
)
24+
25+
target_link_libraries(
26+
beman_optional_test
27+
PRIVATE beman_optional GTest::gtest GTest::gtest_main
28+
)
29+
# Issue #32: Re-enable ASAN run CI/clang-19.
30+
#
31+
# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some
32+
# platforms. Temporary switch to gtest_add_tests and skip some Asan checks.
33+
# Change also applied for CI flows.
34+
include(GoogleTest)
35+
gtest_add_tests(TARGET beman_optional_test "" AUTO)
4036

4137
add_library(constructor_fails test_constructor_fail.cpp)
4238

0 commit comments

Comments
 (0)