Skip to content

Commit de554d9

Browse files
cmake: use C++17 with gtest 1.17 and later (#429)
The 1.17 branch of GoogleTest requires at least C++17; see https://github.com/google/googletest/releases/tag/v1.17.0. Based on a patch by Terje Røsten for the srpc package in Fedora, https://src.fedoraproject.org/rpms/srpc/pull-request/1, and on the version-detection that was present to handle GoogleTest 1.13.0 and C++14 before the overall C++ standard for the project was upgraded to C++14 in b26c810.
1 parent 4b10f08 commit de554d9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

test/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ else ()
6969
endif ()
7070

7171
set(CMAKE_CXX_STANDARD 14)
72+
if (GTest_VERSION VERSION_GREATER_EQUAL "1.17.0")
73+
set(CMAKE_CXX_STANDARD 17)
74+
else ()
75+
get_filename_component(GTEST_PATH ${GTEST_LIBRARY} DIRECTORY ABSOLUTE)
76+
execute_process(COMMAND grep Version "${GTEST_PATH}/pkgconfig/gtest.pc"
77+
RESULT_VARIABLE GTEST_VERSION_RESULT
78+
OUTPUT_VARIABLE GTEST_VERSION_OUTPUT)
79+
if (${GTEST_VERSION_RESULT} EQUAL "0")
80+
string(REPLACE " " ";" GTEST_VERSION_STR ${GTEST_VERSION_OUTPUT})
81+
list(GET GTEST_VERSION_STR 1 GTEST_VERSION)
82+
if (${GTEST_VERSION} VERSION_GREATER_EQUAL "1.17.0")
83+
set(CXX_STD "c++17")
84+
endif ()
85+
endif ()
86+
endif ()
7287

7388
if (WIN32)
7489
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP /wd4200")

0 commit comments

Comments
 (0)