Skip to content

Commit f9f1858

Browse files
committed
Fix required C++ version for CMake builds
Current GTest versions required C++14 or C++17, so set the appropriate version in the compile_features. Also change the library from using CMAKE_CXX_STANDARD to the equivalent target_compile_features. This avoids downgrading the used standard version and is properly exported to CMake Target. Fixes #539.
1 parent 2824eb4 commit f9f1858

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ cmake_minimum_required(VERSION 3.5...4.0)
88
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # custom CMake modules like FindSQLiteCpp
99
project(SQLiteCpp VERSION 3.3.3)
1010

11-
# SQLiteC++ 3.x requires C++11 features
12-
if (NOT CMAKE_CXX_STANDARD)
13-
set(CMAKE_CXX_STANDARD 11)
14-
elseif (CMAKE_CXX_STANDARD LESS 11)
15-
message(WARNING "CMAKE_CXX_STANDARD has been set to '${CMAKE_CXX_STANDARD}' which is lower than the minimum required standard (c++11).")
16-
endif ()
17-
message(STATUS "Using c++ standard c++${CMAKE_CXX_STANDARD}")
18-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
19-
2011
message (STATUS "CMake version: ${CMAKE_VERSION}")
2112
message (STATUS "Project version: ${PROJECT_VERSION}")
2213

@@ -212,6 +203,8 @@ endif()
212203

213204
# add sources of the wrapper as a "SQLiteCpp" static library
214205
add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT})
206+
# SQLiteC++ 3.x requires C++11 features
207+
target_compile_features(SQLiteCpp PUBLIC cxx_std_11)
215208

216209
# Options relative to SQLite and SQLiteC++ functions
217210

@@ -475,10 +468,15 @@ if (SQLITECPP_BUILD_TESTS)
475468
target_link_libraries(SQLiteCpp_tests SQLiteCpp)
476469

477470
find_package(GTest)
478-
if (GTEST_FOUND)
471+
if (GTest_FOUND)
479472
message(STATUS "Link to GTest system library")
480473
target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main)
481-
else (GTEST_FOUND)
474+
if (GTest_VERSION AND (GTest_VERSION VERSION_LESS 1.17))
475+
target_compile_features(SQLiteCpp_tests PRIVATE cxx_std_14)
476+
else()
477+
target_compile_features(SQLiteCpp_tests PRIVATE cxx_std_17)
478+
endif()
479+
else (GTest_FOUND)
482480
message(STATUS "Compile googletest from source in submodule")
483481
# deactivate some warnings for compiling the googletest library
484482
if (NOT MSVC)
@@ -505,7 +503,8 @@ if (SQLITECPP_BUILD_TESTS)
505503
endif (MSVC)
506504

507505
target_link_libraries(SQLiteCpp_tests gtest_main)
508-
endif (GTEST_FOUND)
506+
target_compile_features(SQLiteCpp_tests PUBLIC cxx_std_17)
507+
endif (GTest_FOUND)
509508

510509
# add a "test" target:
511510
enable_testing()

0 commit comments

Comments
 (0)