Skip to content

Commit 3b5314c

Browse files
committed
CMake: replace '-std=c++11' by CXX_STANDARD
This allow to specify another standard from the command line, e.g. for C++17: cmake -DCMAKE_CXX_STANDARD=17 ...
1 parent 494a577 commit 3b5314c

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_executable(schemagen GraphQLTree.cpp SchemaGenerator.cpp)
1515
target_link_libraries(schemagen PRIVATE taocpp::pegtl)
1616
target_include_directories(schemagen SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
1717
target_include_directories(schemagen PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
18+
set_property(TARGET schemagen PROPERTY CXX_STANDARD 11)
1819

1920
add_custom_command(
2021
OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
@@ -34,11 +35,7 @@ target_link_libraries(graphqlservice PRIVATE taocpp::pegtl)
3435
target_include_directories(graphqlservice SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
3536
target_include_directories(graphqlservice SYSTEM INTERFACE $<INSTALL_INTERFACE:include>)
3637
target_include_directories(graphqlservice PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
37-
38-
if(UNIX)
39-
target_compile_options(graphqlservice PRIVATE -std=c++11)
40-
target_compile_options(schemagen PRIVATE -std=c++11)
41-
endif()
38+
set_property(TARGET graphqlservice PROPERTY CXX_STANDARD 11)
4239

4340
option(BUILD_TESTS "Build the tests and sample schema library." ON)
4441
option(UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON)
@@ -59,6 +56,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
5956
graphqlservice)
6057
target_include_directories(todaygraphql SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
6158
target_include_directories(todaygraphql PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
59+
set_property(TARGET todaygraphql PROPERTY CXX_STANDARD 11)
6260

6361
add_executable(test_today
6462
test_today.cpp)
@@ -67,6 +65,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
6765
todaygraphql)
6866
target_include_directories(test_today SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
6967
target_include_directories(test_today PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
68+
set_property(TARGET test_today PROPERTY CXX_STANDARD 11)
7069

7170
find_package(GTest REQUIRED)
7271

@@ -79,6 +78,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
7978
GTest::Main)
8079
target_include_directories(tests SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
8180
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
81+
set_property(TARGET tests PROPERTY CXX_STANDARD 11)
8282

8383
enable_testing()
8484
add_test(NAME TodayServiceCase
@@ -90,12 +90,6 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
9090
add_test(NAME PegtlCase
9191
COMMAND tests --gtest_filter=PegtlCase.*
9292
WORKING_DIRECTORY $<TARGET_FILE_DIR:tests>)
93-
94-
if(UNIX)
95-
target_compile_options(todaygraphql PRIVATE -std=c++11)
96-
target_compile_options(test_today PRIVATE -std=c++11)
97-
target_compile_options(tests PRIVATE -std=c++11)
98-
endif()
9993
endif()
10094

10195
if(UPDATE_SAMPLES)

0 commit comments

Comments
 (0)