@@ -11,19 +11,39 @@ endif()
11
11
12
12
find_package (Threads MODULE REQUIRED )
13
13
14
+ include (CMakePackageConfigHelpers )
15
+
14
16
find_package (pegtl CONFIG REQUIRED )
15
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
+
16
33
add_executable (schemagen
17
34
GraphQLTree.cpp
18
35
GraphQLResponse.cpp
19
36
SchemaGenerator.cpp )
20
37
target_link_libraries (schemagen PRIVATE taocpp::pegtl )
21
- target_include_directories (schemagen PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
22
- set_property ( TARGET schemagen PROPERTY CXX_STANDARD 11 )
38
+ target_include_directories (schemagen PRIVATE ${CMAKE_SOURCE_DIR} /include ${CMAKE_BINARY_DIR} )
39
+ cppgraphqlgen_target_set_cxx_standard ( schemagen )
23
40
24
41
add_custom_command (
25
- OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
42
+ OUTPUT
43
+ IntrospectionSchema.cpp
44
+ include /graphqlservice/IntrospectionSchema.h
26
45
COMMAND schemagen
46
+ COMMAND ${CMAKE_COMMAND} -E rename IntrospectionSchema.h include /graphqlservice/IntrospectionSchema.h
27
47
DEPENDS schemagen
28
48
COMMENT "Generating IntrospectionSchema files"
29
49
)
@@ -35,18 +55,28 @@ add_library(graphqlservice
35
55
Introspection.cpp
36
56
IntrospectionSchema.cpp )
37
57
target_link_libraries (graphqlservice PRIVATE taocpp::pegtl )
38
- target_link_libraries (graphqlservice PUBLIC ${CMAKE_THREAD_LIBS_INIT} )
39
- target_include_directories (graphqlservice SYSTEM INTERFACE $< INSTALL_INTERFACE:include> )
40
- target_include_directories (graphqlservice PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
41
- set_property (TARGET graphqlservice PROPERTY CXX_STANDARD 11 )
58
+ target_link_libraries (graphqlservice PUBLIC Threads::Threads )
59
+ # Make system includes (e.g. <graphqlservice/public.h>) work relative to the build/install generator expressions
60
+ target_include_directories (graphqlservice SYSTEM PUBLIC
61
+ $< BUILD_INTERFACE:${CMAKE_SOURCE_DIR} /include>
62
+ $< BUILD_INTERFACE:${CMAKE_BINARY_DIR} /include>
63
+ $< INSTALL_INTERFACE:include> )
64
+ # Make local includes (e.g. "private.h") work while building graphqlservice, but don't export them
65
+ target_include_directories (graphqlservice PRIVATE
66
+ ${CMAKE_SOURCE_DIR} /include
67
+ ${CMAKE_BINARY_DIR} /include )
68
+ cppgraphqlgen_target_set_cxx_standard (graphqlservice )
42
69
43
70
option (BUILD_TESTS "Build the tests and sample schema library." ON )
44
71
option (UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON )
45
72
46
73
if (BUILD_TESTS OR UPDATE_SAMPLES )
47
74
add_custom_command (
48
- OUTPUT TodaySchema.cpp TodaySchema.h
75
+ OUTPUT
76
+ TodaySchema.cpp
77
+ include /TodaySchema.h
49
78
COMMAND schemagen ${CMAKE_SOURCE_DIR} /schema.today.graphql Today today
79
+ COMMAND ${CMAKE_COMMAND} -E rename TodaySchema.h include /TodaySchema.h
50
80
DEPENDS schemagen schema.today.graphql
51
81
COMMENT "Generating mock TodaySchema files"
52
82
)
@@ -60,21 +90,23 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
60
90
find_package (RapidJSON CONFIG REQUIRED )
61
91
62
92
add_library (todaygraphql
63
- ${CMAKE_BINARY_DIR} /TodaySchema .cpp
64
- Today .cpp
65
- JSONResponse.cpp )
93
+ Today .cpp
94
+ TodaySchema .cpp
95
+ JSONResponse.cpp )
66
96
target_link_libraries (todaygraphql PUBLIC
67
97
graphqlservice )
68
98
target_include_directories (todaygraphql SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} )
69
- target_include_directories (todaygraphql PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
70
- set_property (TARGET todaygraphql PROPERTY CXX_STANDARD 11 )
99
+ target_include_directories (todaygraphql
100
+ PUBLIC
101
+ ${CMAKE_SOURCE_DIR} /include
102
+ ${CMAKE_BINARY_DIR} /include )
103
+ cppgraphqlgen_target_set_cxx_standard (todaygraphql )
71
104
72
105
add_executable (test_today
73
106
test_today.cpp )
74
107
target_link_libraries (test_today PRIVATE
75
108
todaygraphql )
76
- target_include_directories (test_today PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
77
- set_property (TARGET test_today PROPERTY CXX_STANDARD 11 )
109
+ cppgraphqlgen_target_set_cxx_standard (test_today )
78
110
79
111
enable_testing ()
80
112
find_package (GTest MODULE REQUIRED )
@@ -85,8 +117,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
85
117
todaygraphql
86
118
GTest::GTest
87
119
GTest::Main )
88
- target_include_directories (tests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
89
- set_property (TARGET tests PROPERTY CXX_STANDARD 11 )
120
+ cppgraphqlgen_target_set_cxx_standard (tests )
90
121
91
122
add_test (NAME TodayServiceCase
92
123
COMMAND tests --gtest_filter=TodayServiceCase.*
@@ -101,34 +132,41 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
101
132
102
133
if (UPDATE_SAMPLES )
103
134
install (FILES
104
- ${CMAKE_BINARY_DIR} /IntrospectionSchema.h
135
+ ${CMAKE_BINARY_DIR} /include/graphqlservice/ IntrospectionSchema.h
105
136
${CMAKE_BINARY_DIR} /IntrospectionSchema.cpp
106
- ${CMAKE_BINARY_DIR} /TodaySchema.h
137
+ ${CMAKE_BINARY_DIR} /include/ TodaySchema.h
107
138
${CMAKE_BINARY_DIR} /TodaySchema.cpp
108
139
DESTINATION ${CMAKE_SOURCE_DIR} /samples )
109
140
endif ()
110
141
endif ()
111
142
112
143
install (TARGETS graphqlservice
113
- EXPORT cppgraphqlgen-config
144
+ EXPORT cppgraphqlgen-targets
114
145
RUNTIME DESTINATION bin
115
146
ARCHIVE DESTINATION lib
116
147
LIBRARY DESTINATION lib )
117
148
118
149
install (TARGETS schemagen
150
+ EXPORT cppgraphqlgen-targets
119
151
RUNTIME DESTINATION tools/cppgraphqlgen
120
152
CONFIGURATIONS Release )
121
153
122
154
install (FILES
123
- GraphQLTree.h
124
- GraphQLResponse.h
125
- GraphQLService.h
126
- Introspection .h
127
- ${CMAKE_BINARY_DIR} /IntrospectionSchema .h
128
- JSONResponse .h
155
+ include /graphqlservice/ GraphQLTree.h
156
+ include /graphqlservice/ GraphQLResponse.h
157
+ include /graphqlservice/ GraphQLService.h
158
+ include /graphqlservice/JSONResponse .h
159
+ include /graphqlservice/Introspection .h
160
+ ${CMAKE_BINARY_DIR} /include/graphqlservice/IntrospectionSchema .h
129
161
DESTINATION include /graphqlservice
130
162
CONFIGURATIONS Release )
131
163
132
- install (EXPORT cppgraphqlgen-config
164
+ set (CMAKE_INSTALL_CONFIGDIR lib/cmake/${PROJECT_NAME} )
165
+ install (FILES cmake/${PROJECT_NAME}-config.cmake
166
+ DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
167
+ )
168
+
169
+ install (EXPORT cppgraphqlgen-targets
133
170
NAMESPACE cppgraphqlgen::
134
- DESTINATION share/cppgraphqlgen )
171
+ DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
172
+ )
0 commit comments