forked from microsoft/cppgraphqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
186 lines (159 loc) · 6.79 KB
/
Copy pathCMakeLists.txt
File metadata and controls
186 lines (159 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.8.2)
function(add_bigobj_flag target)
if(MSVC)
# MSVC requires the /bigobj flag if the number of sections gets too big.
target_compile_options(${target} PRIVATE /bigobj)
endif()
endfunction()
# graphqlpeg
add_library(graphqlpeg GraphQLTree.cpp)
target_link_libraries(graphqlpeg PUBLIC taocpp::pegtl)
target_include_directories(graphqlpeg PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include>
$<INSTALL_INTERFACE:${GRAPHQL_INSTALL_INCLUDE_DIR}>)
add_bigobj_flag(graphqlpeg)
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(graphqlpeg
PUBLIC GRAPHQL_DLLEXPORTS
PRIVATE IMPL_GRAPHQLPEG_DLL)
endif()
# graphqlresponse
add_library(graphqlresponse GraphQLResponse.cpp)
target_include_directories(graphqlresponse PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:${GRAPHQL_INSTALL_INCLUDE_DIR}>)
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(graphqlresponse
PUBLIC GRAPHQL_DLLEXPORTS
PRIVATE IMPL_GRAPHQLRESPONSE_DLL)
endif()
# schemagen
if(GRAPHQL_BUILD_SCHEMAGEN)
add_executable(schemagen SchemaGenerator.cpp)
target_link_libraries(schemagen PRIVATE
graphqlpeg
graphqlresponse)
add_bigobj_flag(schemagen)
set(BOOST_COMPONENTS program_options)
set(BOOST_LIBRARIES Boost::program_options)
if(NOT MSVC)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} filesystem)
set(BOOST_LIBRARIES ${BOOST_LIBRARIES} Boost::filesystem)
target_compile_options(schemagen PRIVATE -DUSE_BOOST_FILESYSTEM)
endif()
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
target_link_libraries(schemagen PRIVATE ${BOOST_LIBRARIES})
install(TARGETS schemagen
EXPORT cppgraphqlgen-targets
RUNTIME DESTINATION ${GRAPHQL_INSTALL_TOOLS_DIR}/${PROJECT_NAME}
CONFIGURATIONS Release)
endif()
# introspection
if(GRAPHQL_UPDATE_SAMPLES)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/../IntrospectionSchema.cpp
${CMAKE_CURRENT_BINARY_DIR}/../include/graphqlservice/IntrospectionSchema.h
COMMAND ${CMAKE_COMMAND} -E make_directory include/graphqlservice
COMMAND schemagen --introspection
DEPENDS schemagen
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
COMMENT "Generating IntrospectionSchema files")
file(GLOB OLD_INTROSPECTION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../samples/introspection/*)
add_custom_command(
OUTPUT updated_introspection
COMMAND ${CMAKE_COMMAND} -E remove -f ${OLD_INTROSPECTION_FILES}
COMMAND ${CMAKE_COMMAND} -E copy ../IntrospectionSchema.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../samples/introspection/
COMMAND ${CMAKE_COMMAND} -E copy ../include/graphqlservice/IntrospectionSchema.h ${CMAKE_CURRENT_SOURCE_DIR}/../samples/introspection/
COMMAND ${CMAKE_COMMAND} -E touch updated_introspection
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/../IntrospectionSchema.cpp
${CMAKE_CURRENT_BINARY_DIR}/../include/graphqlservice/IntrospectionSchema.h
COMMENT "Updating introspection files")
add_custom_target(update_introspection ALL
DEPENDS updated_introspection)
else()
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/../IntrospectionSchema.cpp
${CMAKE_CURRENT_BINARY_DIR}/../include/graphqlservice/IntrospectionSchema.h
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../samples/introspection/IntrospectionSchema.cpp .
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../samples/introspection/IntrospectionSchema.h include/graphqlservice
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
COMMENT "Copying IntrospectionSchema files")
endif()
# graphqlservice
add_library(graphqlservice
GraphQLService.cpp
Introspection.cpp
Validation.cpp
${CMAKE_CURRENT_BINARY_DIR}/../IntrospectionSchema.cpp)
target_link_libraries(graphqlservice PUBLIC
graphqlpeg
Threads::Threads)
target_link_libraries(graphqlservice PUBLIC graphqlresponse)
target_include_directories(graphqlservice SYSTEM PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/../include)
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(graphqlservice
PUBLIC GRAPHQL_DLLEXPORTS
PRIVATE IMPL_GRAPHQLSERVICE_DLL)
endif()
# RapidJSON is the only option for JSON serialization used in this project, but if you want
# to use another JSON library you can implement an alternate version of the functions in
# JSONResponse.cpp to serialize to and from GraphQLResponse and build graphqljson from that.
# You will also need to define how to build the graphqljson library target with your
# implementation, and you should set BUILD_GRAPHQLJSON so that the test dependencies know
# about your version of graphqljson.
option(GRAPHQL_USE_RAPIDJSON "Use RapidJSON for JSON serialization." ON)
if(GRAPHQL_USE_RAPIDJSON)
find_package(RapidJSON CONFIG REQUIRED)
set(BUILD_GRAPHQLJSON ON)
add_library(graphqljson JSONResponse.cpp)
target_link_libraries(graphqljson PUBLIC graphqlresponse)
target_include_directories(graphqljson SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(graphqljson
PUBLIC GRAPHQL_DLLEXPORTS
PRIVATE IMPL_JSONRESPONSE_DLL)
endif()
endif()
# graphqljson
if(BUILD_GRAPHQLJSON)
option(GRAPHQL_BUILD_TESTS "Build the tests and sample schema library." ON)
target_link_libraries(graphqljson PUBLIC graphqlservice)
install(TARGETS graphqljson
EXPORT cppgraphqlgen-targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/JSONResponse.h
DESTINATION ${GRAPHQL_INSTALL_INCLUDE_DIR}/graphqlservice
CONFIGURATIONS Release)
else()
set(GRAPHQL_BUILD_TESTS OFF CACHE BOOL "GRAPHQL_BUILD_TESTS depends on BUILD_GRAPHQLJSON" FORCE)
endif()
install(TARGETS
graphqlpeg
graphqlresponse
graphqlservice
EXPORT cppgraphqlgen-targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/GraphQLParse.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/GraphQLResponse.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/GraphQLService.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/GraphQLGrammar.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/GraphQLTree.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/Introspection.h
${CMAKE_CURRENT_BINARY_DIR}/../include/graphqlservice/IntrospectionSchema.h
DESTINATION ${GRAPHQL_INSTALL_INCLUDE_DIR}/graphqlservice
CONFIGURATIONS Release)
install(EXPORT cppgraphqlgen-targets
NAMESPACE cppgraphqlgen::
DESTINATION ${GRAPHQL_INSTALL_CMAKE_DIR}/${PROJECT_NAME})