@@ -15,13 +15,28 @@ include(CMakePackageConfigHelpers)
15
15
16
16
find_package (pegtl CONFIG REQUIRED )
17
17
18
+ # Set the minimum C++ standard required for compiling,
19
+ # but allow for user to override on the command line using:
20
+ # cmake -DCMAKE_CXX_STANDARD=[11|14|17|...] -DCMAKE_CXX_EXTENSIONS=[ON|OFF]
21
+ function (cppgraphqlgen_target_set_cxx_standard target )
22
+ if (CMAKE_VERSION VERSION_LESS "3.8" )
23
+ # The cxx_std_11 abstract compile feature
24
+ # is available only starting from CMake 3.8.
25
+ # We assume the availability of lambdas
26
+ # indicates a C++11-compatible compiler mode.
27
+ target_compile_features (${target} PUBLIC cxx_lambdas )
28
+ else ()
29
+ target_compile_features (${target} PUBLIC cxx_std_11 )
30
+ endif ()
31
+ endfunction ()
32
+
18
33
add_executable (schemagen
19
34
GraphQLTree.cpp
20
35
GraphQLResponse.cpp
21
36
SchemaGenerator.cpp )
22
37
target_link_libraries (schemagen PRIVATE taocpp::pegtl )
23
38
target_include_directories (schemagen PRIVATE ${CMAKE_SOURCE_DIR} /include ${CMAKE_BINARY_DIR} )
24
- set_property ( TARGET schemagen PROPERTY CXX_STANDARD 11 )
39
+ cppgraphqlgen_target_set_cxx_standard ( schemagen )
25
40
26
41
add_custom_command (
27
42
OUTPUT
@@ -48,7 +63,7 @@ target_include_directories(graphqlservice
48
63
$< BUILD_INTERFACE:${CMAKE_BINARY_DIR} >
49
64
$< INSTALL_INTERFACE:include>
50
65
)
51
- set_property ( TARGET graphqlservice PROPERTY CXX_STANDARD 11 )
66
+ cppgraphqlgen_target_set_cxx_standard ( graphqlservice )
52
67
53
68
option (BUILD_TESTS "Build the tests and sample schema library." ON )
54
69
option (UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON )
@@ -77,14 +92,14 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
77
92
graphqlservice )
78
93
target_include_directories (todaygraphql SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} )
79
94
target_include_directories (todaygraphql PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
80
- set_property ( TARGET todaygraphql PROPERTY CXX_STANDARD 11 )
95
+ cppgraphqlgen_target_set_cxx_standard ( todaygraphql )
81
96
82
97
add_executable (test_today
83
98
test_today.cpp )
84
99
target_link_libraries (test_today PRIVATE
85
100
todaygraphql )
86
101
target_include_directories (test_today PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
87
- set_property ( TARGET test_today PROPERTY CXX_STANDARD 11 )
102
+ cppgraphqlgen_target_set_cxx_standard ( test_today )
88
103
89
104
enable_testing ()
90
105
find_package (GTest MODULE REQUIRED )
@@ -96,7 +111,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
96
111
GTest::GTest
97
112
GTest::Main )
98
113
target_include_directories (tests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
99
- set_property ( TARGET tests PROPERTY CXX_STANDARD 11 )
114
+ cppgraphqlgen_target_set_cxx_standard ( tests )
100
115
101
116
add_test (NAME TodayServiceCase
102
117
COMMAND tests --gtest_filter=TodayServiceCase.*
0 commit comments