Skip to content

Commit 0a8d82b

Browse files
committed
Modernize GoogleTest fetch (FetchContent v1.16.0), version 1.1.6
The legacy pre-FetchContent GoogleTest download mechanism (configure_file test/CMakeLists.txt.in + execute_process git clone) pinned googletest at an old release whose inner subdirectories use `cmake_minimum_required(VERSION ...)` below the floor CMake 4 still supports. Configures with CMake 4 now error out with: Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument <min> value. Fix: replace the legacy mechanism with `FetchContent_Declare` pinned at googletest v1.16.0. Delete test/CMakeLists.txt.in entirely. Also wires googletest into the standard preset pattern: - Root CMakeLists.txt: GOOGLETEST added to the graceful-fallback foreach alongside XMLPARSER, so a missing sibling silently falls back to remote. - CMakePresets.json: `local` base now also overrides FETCHCONTENT_SOURCE_DIR_GOOGLETEST to ${sourceDir}/../googletest. README updated: removed the stale note about GoogleTest using a legacy non-overridable mechanism; sibling table now includes the googletest override. Project VERSION: 1.1.5 -> 1.1.6.
1 parent f89b91a commit 0a8d82b

5 files changed

Lines changed: 26 additions & 58 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
cmake_minimum_required(VERSION 3.15)
22

3-
project( THMXParser VERSION 1.1.5 LANGUAGES CXX )
3+
project( THMXParser VERSION 1.1.6 LANGUAGES CXX )
44
set(LIB_NAME ${PROJECT_NAME})
55

66
# Graceful local-sibling fallback: the `local` CMake preset sets
77
# FETCHCONTENT_SOURCE_DIR_<NAME> to ${sourceDir}/../<DepName> for each declared
88
# dependency. If a sibling working copy is missing, unset that variable here so
99
# FetchContent falls back to the declared remote instead of erroring out.
10-
foreach(_lbnl_dep XMLPARSER)
10+
foreach(_lbnl_dep XMLPARSER GOOGLETEST)
1111
if(DEFINED FETCHCONTENT_SOURCE_DIR_${_lbnl_dep})
1212
if(NOT EXISTS "${FETCHCONTENT_SOURCE_DIR_${_lbnl_dep}}/CMakeLists.txt")
1313
message(STATUS

CMakePresets.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
{
2929
"name": "local",
3030
"hidden": true,
31-
"description": "Base: prefers sibling working copies of dependencies (../XMLParser); falls back to remote per-dep when missing. Inherited by local-debug, local-release, and personal compiler presets.",
31+
"description": "Base: prefers sibling working copies of dependencies (../XMLParser, ../googletest); falls back to remote per-dep when missing. Inherited by local-debug, local-release, and personal compiler presets.",
3232
"inherits": "default",
3333
"cacheVariables": {
34-
"FETCHCONTENT_SOURCE_DIR_XMLPARSER": "${sourceDir}/../XMLParser"
34+
"FETCHCONTENT_SOURCE_DIR_XMLPARSER": "${sourceDir}/../XMLParser",
35+
"FETCHCONTENT_SOURCE_DIR_GOOGLETEST": "${sourceDir}/../googletest"
3536
}
3637
},
3738
{

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ include(FetchContent)
1717
FetchContent_Declare(
1818
THMXParser
1919
GIT_REPOSITORY https://github.com/LBNL-ETA/THMXParser.git
20-
GIT_TAG v1.1.5
20+
GIT_TAG v1.1.6
2121
)
2222
FetchContent_MakeAvailable(THMXParser)
2323
@@ -52,10 +52,9 @@ ctest --test-dir build/default-release -C Release --output-on-failure
5252
| Dependency | Expected sibling path |
5353
|------------|----------------------|
5454
| XMLParser | `../XMLParser` |
55+
| GoogleTest | `../googletest` |
5556

56-
Missing siblings fall back to the declared remote automatically, so `local-*` is safe to invoke even if you don't have the sibling checked out.
57-
58-
> **Note:** The test target's GoogleTest dependency is fetched via a legacy pre-FetchContent download mechanism in `test/CMakeLists.txt`, not by `FetchContent_Declare`. It is not currently overridable via `FETCHCONTENT_SOURCE_DIR_GOOGLETEST`.
57+
Missing siblings fall back to the declared remote automatically, so `local-*` is safe to invoke even if you don't have the siblings checked out.
5958

6059
#### Per-machine compiler presets (`CMakeUserPresets.json`)
6160

test/CMakeLists.txt

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,26 @@ include_directories("${PROJECT_SOURCE_DIR}")
33
set(PROJECT_TEST_NAME ${LIB_NAME}-test)
44

55
if(DOWNLOAD_GTEST STREQUAL ON)
6-
# Download and unpack googletest at configure time
7-
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
8-
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
9-
RESULT_VARIABLE result
10-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
11-
if(result)
12-
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
13-
endif()
14-
execute_process(COMMAND ${CMAKE_COMMAND} --build .
15-
RESULT_VARIABLE result
16-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
17-
if(result)
18-
message(FATAL_ERROR "Build step for googletest failed: ${result}")
19-
endif()
20-
# Prevent overriding the parent project's compiler/linker
21-
# settings on Windows
22-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
23-
24-
# Add googletest directly to our build. This defines
25-
# the gtest and gtest_main targets.
26-
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
27-
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
28-
EXCLUDE_FROM_ALL)
29-
6+
if(MSVC)
7+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
8+
endif()
9+
10+
if(NOT TARGET gtest)
11+
include(FetchContent)
12+
FetchContent_Declare(
13+
googletest
14+
GIT_REPOSITORY https://github.com/google/googletest.git
15+
GIT_TAG v1.16.0
16+
GIT_SHALLOW TRUE
17+
)
18+
FetchContent_MakeAvailable(googletest)
19+
endif()
3020
endif()
3121

32-
add_executable(${PROJECT_TEST_NAME}
33-
read_cs_03.unit.cpp
34-
read_cma_example.cpp
35-
main.cpp
22+
add_executable(${PROJECT_TEST_NAME}
23+
read_cs_03.unit.cpp
24+
read_cma_example.cpp
25+
main.cpp
3626
)
3727

3828
include_directories(${PROJECT_SOURCE_DIR}/src)
@@ -42,4 +32,3 @@ target_link_libraries(${PROJECT_TEST_NAME} gmock_main ${LIB_NAME})
4232
target_compile_features(${PROJECT_TEST_NAME} PRIVATE cxx_std_17)
4333

4434
add_test(NAME ${PROJECT_TEST_NAME}-runner COMMAND ${PROJECT_TEST_NAME} "${CMAKE_CURRENT_LIST_DIR}")
45-

test/CMakeLists.txt.in

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)