Skip to content

Commit adc7db6

Browse files
committed
fix(vendor): fix compatibility with newer CMake
CMake 4.0 has deprecated CMakeLists.txt files with an old CMake version [1]. This causes CMake to reject googletest's CMake files. Apply googletest's upstream patches to make it compatible with CMake 4.0, fixing builds. [1] https://cmake.org/cmake/help/latest/release/4.0.html#deprecated-and-removed-features
1 parent a2798b3 commit adc7db6

File tree

7 files changed

+193
-33
lines changed

7 files changed

+193
-33
lines changed

vendor/README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ applications, and Google Mock, its companion mocking framework.
2828

2929
The following patches have been manually applied:
3030

31+
* googletest-cmake-3.5.patch
32+
* googletest-cmake-3.13.patch
3133
* googletest-werror.patch
3234

3335
Copyright: Copyright 2008, Google Inc.

vendor/googletest-cmake-3.13.patch

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
commit 4fed5f285030085b096c930ff03e42c7814739b2
2+
Author: Juan Ramos <[email protected]>
3+
Date: Mon Jun 19 11:21:44 2023 -0600
4+
5+
cmake: Raise min to 3.6
6+
7+
From the CMake 3.27 release notes:
8+
Compatibility with versions of CMake older than 3.5 is now
9+
deprecated and will be removed from a future version. Calls to
10+
cmake_minimum_required() or cmake_policy() that set the policy
11+
version to an older value now issue a deprecation diagnostic.
12+
13+
This PR also removes manually setting policy CMP0048. This is
14+
redundant since the CMake min is already 3.X
15+
16+
diff --git a/CMakeLists.txt b/CMakeLists.txt
17+
index 6af41437..33a6c6ff 100644
18+
--- a/CMakeLists.txt
19+
+++ b/CMakeLists.txt
20+
@@ -1,11 +1,7 @@
21+
# Note: CMake support is community-based. The maintainers do not use CMake
22+
# internally.
23+
24+
-cmake_minimum_required(VERSION 3.5)
25+
-
26+
-if (POLICY CMP0048)
27+
- cmake_policy(SET CMP0048 NEW)
28+
-endif (POLICY CMP0048)
29+
+cmake_minimum_required(VERSION 3.6)
30+
31+
if (POLICY CMP0069)
32+
cmake_policy(SET CMP0069 NEW)
33+
diff --git a/docs/pkgconfig.md b/docs/pkgconfig.md
34+
index 18a2546a..bf05d593 100644
35+
--- a/docs/pkgconfig.md
36+
+++ b/docs/pkgconfig.md
37+
@@ -19,19 +19,15 @@ examples here we assume you want to compile the sample
38+
Using `pkg-config` in CMake is fairly easy:
39+
40+
```cmake
41+
-cmake_minimum_required(VERSION 3.0)
42+
-
43+
-cmake_policy(SET CMP0048 NEW)
44+
-project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
45+
-
46+
find_package(PkgConfig)
47+
pkg_search_module(GTEST REQUIRED gtest_main)
48+
49+
-add_executable(testapp samples/sample3_unittest.cc)
50+
-target_link_libraries(testapp ${GTEST_LDFLAGS})
51+
-target_compile_options(testapp PUBLIC ${GTEST_CFLAGS})
52+
+add_executable(testapp)
53+
+target_sources(testapp PRIVATE samples/sample3_unittest.cc)
54+
+target_link_libraries(testapp PRIVATE ${GTEST_LDFLAGS})
55+
+target_compile_options(testapp PRIVATE ${GTEST_CFLAGS})
56+
57+
-include(CTest)
58+
+enable_testing()
59+
add_test(first_and_only_test testapp)
60+
```
61+
62+
diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt
63+
index 5c1f0daf..444c5ae8 100644
64+
--- a/googlemock/CMakeLists.txt
65+
+++ b/googlemock/CMakeLists.txt
66+
@@ -36,8 +36,7 @@ endif()
67+
# as ${gmock_SOURCE_DIR} and to the root binary directory as
68+
# ${gmock_BINARY_DIR}.
69+
# Language "C" is required for find_package(Threads).
70+
-cmake_minimum_required(VERSION 3.5)
71+
-cmake_policy(SET CMP0048 NEW)
72+
+cmake_minimum_required(VERSION 3.6)
73+
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
74+
75+
if (COMMAND set_up_hermetic_build)
76+
diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt
77+
index d06c1479..efc2c3cb 100644
78+
--- a/googletest/CMakeLists.txt
79+
+++ b/googletest/CMakeLists.txt
80+
@@ -46,8 +46,7 @@ endif()
81+
82+
# Project version:
83+
84+
-cmake_minimum_required(VERSION 3.5)
85+
-cmake_policy(SET CMP0048 NEW)
86+
+cmake_minimum_required(VERSION 3.6)
87+
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
88+
89+
if (POLICY CMP0063) # Visibility

vendor/googletest-cmake-3.5.patch

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
commit 62046339790b8fb8a37e8fde5d2edcbf4ffe2a3a
2+
Author: Abseil Team <[email protected]>
3+
Date: Fri Aug 20 17:47:35 2021 -0400
4+
5+
Googletest export
6+
7+
Bump `cmake_minimum_required` to 3.5.
8+
9+
Delete conditional branches exclusive to older versions.
10+
11+
Notable dependents:
12+
- github.com/grpc/grpc >= 3.5.1
13+
- github.com/abseil/abseil-cpp >= 3.5
14+
- github.com/googleapis/google-cloud-cpp >= 3.5
15+
16+
On the other hand, github.com/protocolbuffers/protobuf is >= 3.1.3, but it only depends on GoogleTest 1.10.
17+
18+
Fixes #3523
19+
20+
PiperOrigin-RevId: 392073834
21+
22+
diff --git a/CMakeLists.txt b/CMakeLists.txt
23+
index ea81ab12..7d2eb810 100644
24+
--- a/CMakeLists.txt
25+
+++ b/CMakeLists.txt
26+
@@ -1,7 +1,7 @@
27+
# Note: CMake support is community-based. The maintainers do not use CMake
28+
# internally.
29+
30+
-cmake_minimum_required(VERSION 2.8.12)
31+
+cmake_minimum_required(VERSION 3.5)
32+
33+
if (POLICY CMP0048)
34+
cmake_policy(SET CMP0048 NEW)
35+
@@ -10,10 +10,8 @@ endif (POLICY CMP0048)
36+
project(googletest-distribution)
37+
set(GOOGLETEST_VERSION 1.11.0)
38+
39+
-if (CMAKE_VERSION VERSION_GREATER "3.0.2")
40+
- if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
41+
- set(CMAKE_CXX_EXTENSIONS OFF)
42+
- endif()
43+
+if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
44+
+ set(CMAKE_CXX_EXTENSIONS OFF)
45+
endif()
46+
47+
enable_testing()
48+
diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt
49+
index e7df8ec5..2b55ba15 100644
50+
--- a/googlemock/CMakeLists.txt
51+
+++ b/googlemock/CMakeLists.txt
52+
@@ -36,13 +36,9 @@ endif()
53+
# as ${gmock_SOURCE_DIR} and to the root binary directory as
54+
# ${gmock_BINARY_DIR}.
55+
# Language "C" is required for find_package(Threads).
56+
-if (CMAKE_VERSION VERSION_LESS 3.0)
57+
- project(gmock CXX C)
58+
-else()
59+
- cmake_policy(SET CMP0048 NEW)
60+
- project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
61+
-endif()
62+
-cmake_minimum_required(VERSION 2.8.12)
63+
+cmake_minimum_required(VERSION 3.5)
64+
+cmake_policy(SET CMP0048 NEW)
65+
+project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
66+
67+
if (COMMAND set_up_hermetic_build)
68+
set_up_hermetic_build()
69+
diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt
70+
index abdd98b7..15b8f0c3 100644
71+
--- a/googletest/CMakeLists.txt
72+
+++ b/googletest/CMakeLists.txt
73+
@@ -46,14 +46,9 @@ endif()
74+
75+
# Project version:
76+
77+
-if (CMAKE_VERSION VERSION_LESS 3.0)
78+
- project(gtest CXX C)
79+
- set(PROJECT_VERSION ${GOOGLETEST_VERSION})
80+
-else()
81+
- cmake_policy(SET CMP0048 NEW)
82+
- project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
83+
-endif()
84+
-cmake_minimum_required(VERSION 2.8.12)
85+
+cmake_minimum_required(VERSION 3.5)
86+
+cmake_policy(SET CMP0048 NEW)
87+
+project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
88+
89+
if (POLICY CMP0063) # Visibility
90+
cmake_policy(SET CMP0063 NEW)

vendor/googletest/CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# Note: CMake support is community-based. The maintainers do not use CMake
22
# internally.
33

4-
cmake_minimum_required(VERSION 2.8.12)
5-
6-
if (POLICY CMP0048)
7-
cmake_policy(SET CMP0048 NEW)
8-
endif (POLICY CMP0048)
4+
cmake_minimum_required(VERSION 3.6)
95

106
project(googletest-distribution)
117
set(GOOGLETEST_VERSION 1.11.0)
128

13-
if (CMAKE_VERSION VERSION_GREATER "3.0.2")
14-
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
15-
set(CMAKE_CXX_EXTENSIONS OFF)
16-
endif()
9+
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
10+
set(CMAKE_CXX_EXTENSIONS OFF)
1711
endif()
1812

1913
enable_testing()

vendor/googletest/docs/pkgconfig.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@ examples here we assume you want to compile the sample
1919
Using `pkg-config` in CMake is fairly easy:
2020

2121
```cmake
22-
cmake_minimum_required(VERSION 3.0)
23-
24-
cmake_policy(SET CMP0048 NEW)
25-
project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
26-
2722
find_package(PkgConfig)
2823
pkg_search_module(GTEST REQUIRED gtest_main)
2924
30-
add_executable(testapp samples/sample3_unittest.cc)
31-
target_link_libraries(testapp ${GTEST_LDFLAGS})
32-
target_compile_options(testapp PUBLIC ${GTEST_CFLAGS})
25+
add_executable(testapp)
26+
target_sources(testapp PRIVATE samples/sample3_unittest.cc)
27+
target_link_libraries(testapp PRIVATE ${GTEST_LDFLAGS})
28+
target_compile_options(testapp PRIVATE ${GTEST_CFLAGS})
3329
34-
include(CTest)
30+
enable_testing()
3531
add_test(first_and_only_test testapp)
3632
```
3733

vendor/googletest/googlemock/CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ endif()
3636
# as ${gmock_SOURCE_DIR} and to the root binary directory as
3737
# ${gmock_BINARY_DIR}.
3838
# Language "C" is required for find_package(Threads).
39-
if (CMAKE_VERSION VERSION_LESS 3.0)
40-
project(gmock CXX C)
41-
else()
42-
cmake_policy(SET CMP0048 NEW)
43-
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
44-
endif()
45-
cmake_minimum_required(VERSION 2.8.12)
39+
cmake_minimum_required(VERSION 3.6)
40+
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
4641

4742
if (COMMAND set_up_hermetic_build)
4843
set_up_hermetic_build()

vendor/googletest/googletest/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,8 @@ endif()
4646

4747
# Project version:
4848

49-
if (CMAKE_VERSION VERSION_LESS 3.0)
50-
project(gtest CXX C)
51-
set(PROJECT_VERSION ${GOOGLETEST_VERSION})
52-
else()
53-
cmake_policy(SET CMP0048 NEW)
54-
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
55-
endif()
56-
cmake_minimum_required(VERSION 2.8.12)
49+
cmake_minimum_required(VERSION 3.6)
50+
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
5751

5852
if (POLICY CMP0063) # Visibility
5953
cmake_policy(SET CMP0063 NEW)

0 commit comments

Comments
 (0)