@@ -11,19 +11,39 @@ endif()
1111
1212find_package (Threads MODULE REQUIRED)
1313
14+ include (CMakePackageConfigHelpers)
15+
1416find_package (pegtl CONFIG REQUIRED)
1517
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+
1633add_executable (schemagen
1734 GraphQLTree.cpp
1835 GraphQLResponse.cpp
1936 SchemaGenerator.cpp)
2037target_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)
2340
2441add_custom_command (
25- OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
42+ OUTPUT
43+ IntrospectionSchema.cpp
44+ include /graphqlservice/IntrospectionSchema.h
2645 COMMAND schemagen
46+ COMMAND ${CMAKE_COMMAND} -E rename IntrospectionSchema.h include /graphqlservice/IntrospectionSchema.h
2747 DEPENDS schemagen
2848 COMMENT "Generating IntrospectionSchema files"
2949)
@@ -35,18 +55,28 @@ add_library(graphqlservice
3555 Introspection.cpp
3656 IntrospectionSchema.cpp)
3757target_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)
4269
4370option (BUILD_TESTS "Build the tests and sample schema library." ON )
4471option (UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON )
4572
4673if (BUILD_TESTS OR UPDATE_SAMPLES)
4774 add_custom_command (
48- OUTPUT TodaySchema.cpp TodaySchema.h
75+ OUTPUT
76+ TodaySchema.cpp
77+ include /TodaySchema.h
4978 COMMAND schemagen ${CMAKE_SOURCE_DIR} /schema.today.graphql Today today
79+ COMMAND ${CMAKE_COMMAND} -E rename TodaySchema.h include /TodaySchema.h
5080 DEPENDS schemagen schema.today.graphql
5181 COMMENT "Generating mock TodaySchema files"
5282 )
@@ -60,21 +90,23 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
6090 find_package (RapidJSON CONFIG REQUIRED)
6191
6292 add_library (todaygraphql
63- ${CMAKE_BINARY_DIR} /TodaySchema .cpp
64- Today .cpp
65- JSONResponse.cpp)
93+ Today .cpp
94+ TodaySchema .cpp
95+ JSONResponse.cpp)
6696 target_link_libraries (todaygraphql PUBLIC
6797 graphqlservice)
6898 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)
71104
72105 add_executable (test_today
73106 test_today.cpp)
74107 target_link_libraries (test_today PRIVATE
75108 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)
78110
79111 enable_testing ()
80112 find_package (GTest MODULE REQUIRED)
@@ -85,8 +117,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
85117 todaygraphql
86118 GTest::GTest
87119 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)
90121
91122 add_test (NAME TodayServiceCase
92123 COMMAND tests --gtest_filter=TodayServiceCase.*
@@ -101,34 +132,41 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
101132
102133 if (UPDATE_SAMPLES)
103134 install (FILES
104- ${CMAKE_BINARY_DIR} /IntrospectionSchema.h
135+ ${CMAKE_BINARY_DIR} /include /graphqlservice/ IntrospectionSchema.h
105136 ${CMAKE_BINARY_DIR} /IntrospectionSchema.cpp
106- ${CMAKE_BINARY_DIR} /TodaySchema.h
137+ ${CMAKE_BINARY_DIR} /include / TodaySchema.h
107138 ${CMAKE_BINARY_DIR} /TodaySchema.cpp
108139 DESTINATION ${CMAKE_SOURCE_DIR} /samples)
109140 endif ()
110141endif ()
111142
112143install (TARGETS graphqlservice
113- EXPORT cppgraphqlgen-config
144+ EXPORT cppgraphqlgen-targets
114145 RUNTIME DESTINATION bin
115146 ARCHIVE DESTINATION lib
116147 LIBRARY DESTINATION lib)
117148
118149install (TARGETS schemagen
150+ EXPORT cppgraphqlgen-targets
119151 RUNTIME DESTINATION tools/cppgraphqlgen
120152 CONFIGURATIONS Release)
121153
122154install (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
129161 DESTINATION include /graphqlservice
130162 CONFIGURATIONS Release)
131163
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
133170 NAMESPACE cppgraphqlgen::
134- DESTINATION share/cppgraphqlgen)
171+ DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
172+ )
0 commit comments