2
2
# Licensed under the MIT License.
3
3
4
4
cmake_minimum_required (VERSION 3.5.1 )
5
- project (cppgraphql )
5
+ project (cppgraphqlgen )
6
6
7
7
if (WIN32 )
8
8
# Let CMake figure out the exports for the SHARED library (DLL) on Windows.
9
9
SET (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE )
10
10
endif ()
11
11
12
- add_library (graphqlservice SHARED GraphQLService.cpp Introspection.cpp IntrospectionSchema.cpp )
12
+ add_library (graphqlservice GraphQLService.cpp Introspection.cpp IntrospectionSchema.cpp )
13
13
add_executable (schemagen SchemaGenerator.cpp )
14
14
15
15
find_library (GRAPHQLPARSER graphqlparser )
16
16
17
+ find_package (cpprestsdk REQUIRED )
18
+ set (CPPRESTSDK cpprestsdk::cpprest )
19
+
17
20
if (UNIX )
18
- find_library (CPPRESTSDK_LIB cpprest )
19
- elseif (WIN32 )
20
- find_package (cpprestsdk REQUIRED )
21
- set (CPPRESTSDK_LIB cpprestsdk::cpprest )
21
+ find_library (BOOST_SYSTEM boost_system )
22
+ list (APPEND CPPRESTSDK ${BOOST_SYSTEM} )
22
23
endif ()
23
24
24
25
find_package (pegtl CONFIG REQUIRED )
25
26
26
27
add_library (graphqlpeg SHARED GraphQLGrammar.cpp )
27
- target_include_directories (graphqlpeg SYSTEM PUBLIC ${CMAKE_PREFIX_PATH} /include ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
28
+ target_include_directories (graphqlpeg INTERFACE $< BUILD_INTERFACE: ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} > $< INSTALL_INTERFACE:include > )
28
29
target_link_libraries (graphqlpeg taocpp::pegtl ${GRAPHQLPARSER} )
29
30
30
- target_include_directories (graphqlservice SYSTEM PUBLIC ${CMAKE_PREFIX_PATH} /include ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
31
+ target_include_directories (graphqlservice INTERFACE $< BUILD_INTERFACE: ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} > $< INSTALL_INTERFACE:include > )
31
32
target_link_libraries (graphqlservice ${CPPRESTSDK_LIB} ${GRAPHQLPARSER} graphqlpeg )
32
33
target_link_libraries (schemagen ${CPPRESTSDK_LIB} ${GRAPHQLPARSER} graphqlpeg )
33
34
@@ -38,74 +39,85 @@ add_custom_command(
38
39
COMMENT "Generating IntrospectionSchema files"
39
40
)
40
41
41
- add_custom_command (
42
- OUTPUT TodaySchema.cpp TodaySchema.h
43
- COMMAND schemagen ${CMAKE_SOURCE_DIR} /schema.today.graphql Today today
44
- DEPENDS schemagen schema.today.graphql
45
- COMMENT "Generating mock TodaySchema files"
46
- )
47
-
48
- add_library (todaygraphql SHARED
49
- TodaySchema.cpp
50
- Today.cpp )
51
-
52
- target_link_libraries (todaygraphql
53
- ${CPPRESTSDK_LIB}
54
- ${GRAPHQLPARSER}
55
- graphqlservice )
56
- target_include_directories (todaygraphql SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
57
-
58
- add_executable (test_today test_today.cpp )
59
-
60
- target_link_libraries (test_today
61
- ${CPPRESTSDK_LIB}
62
- ${GRAPHQLPARSER}
63
- graphqlservice
64
- todaygraphql )
65
- target_include_directories (test_today SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
66
-
67
- enable_testing ()
68
- add_executable (tests tests.cpp )
69
- find_package (GTest REQUIRED )
70
- target_link_libraries (tests
71
- ${CPPRESTSDK_LIB}
72
- ${GRAPHQLPARSER}
73
- graphqlservice
74
- graphqlpeg
75
- todaygraphql
76
- GTest::GTest
77
- GTest::Main )
78
- target_include_directories (tests SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
79
- add_test (TodayServiceCase tests )
80
- add_test (ArgumentsCase tests )
81
-
82
42
if (UNIX )
83
43
target_compile_options (graphqlservice PRIVATE -std=c++11 )
84
- target_compile_options (todaygraphql PRIVATE -std=c++11 )
85
44
target_compile_options (schemagen PRIVATE -std=c++11 )
86
- target_compile_options (test_today PRIVATE -std=c++11 )
87
- target_compile_options (tests PRIVATE -std=c++11 )
45
+ endif ()
46
+
47
+ option (BUILD_TESTS "Build the tests and sample schema library." ON )
48
+ option (UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON )
49
+
50
+ if (BUILD_TESTS OR UPDATE_SAMPLES )
51
+ add_custom_command (
52
+ OUTPUT TodaySchema.cpp TodaySchema.h
53
+ COMMAND schemagen ${CMAKE_SOURCE_DIR} /schema.today.graphql Today today
54
+ DEPENDS schemagen schema.today.graphql
55
+ COMMENT "Generating mock TodaySchema files"
56
+ )
57
+
58
+ if (BUILD_TESTS )
59
+ add_library (todaygraphql
60
+ TodaySchema.cpp
61
+ Today.cpp )
62
+
63
+ target_link_libraries (todaygraphql
64
+ ${CPPRESTSDK}
65
+ ${GRAPHQLPARSER}
66
+ graphqlservice )
67
+ target_include_directories (todaygraphql SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
68
+
69
+ add_executable (test_today test_today.cpp )
70
+
71
+ target_link_libraries (test_today
72
+ ${CPPRESTSDK}
73
+ ${GRAPHQLPARSER}
74
+ graphqlservice
75
+ todaygraphql )
76
+ target_include_directories (test_today SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
77
+
78
+ enable_testing ()
79
+ add_executable (tests tests.cpp )
80
+ find_package (GTest REQUIRED )
81
+ target_link_libraries (tests
82
+ ${CPPRESTSDK}
83
+ ${GRAPHQLPARSER}
84
+ graphqlpeg
85
+ graphqlservice
86
+ todaygraphql
87
+ GTest::GTest
88
+ GTest::Main )
89
+ target_include_directories (tests SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} )
90
+ add_test (TodayServiceCase tests )
91
+ add_test (ArgumentsCase tests )
92
+
93
+ if (UNIX )
94
+ target_compile_options (todaygraphql PRIVATE -std=c++11 )
95
+ target_compile_options (test_today PRIVATE -std=c++11 )
96
+ target_compile_options (tests PRIVATE -std=c++11 )
97
+ endif ()
98
+ endif ()
99
+
100
+ if (UPDATE_SAMPLES )
101
+ install (FILES IntrospectionSchema.h IntrospectionSchema.cpp TodaySchema.h TodaySchema.cpp
102
+ DESTINATION ${CMAKE_SOURCE_DIR} /samples )
103
+ endif ()
88
104
endif ()
89
105
90
106
install (TARGETS graphqlservice schemagen
107
+ EXPORT cppgraphqlgen-config
91
108
RUNTIME DESTINATION bin
109
+ ARCHIVE DESTINATION lib
92
110
LIBRARY DESTINATION lib )
93
111
94
112
install (FILES GraphQLService.h Introspection.h IntrospectionSchema.h
95
113
DESTINATION include /graphqlservice )
96
114
97
- install (FILES IntrospectionSchema.h IntrospectionSchema.cpp TodaySchema.h TodaySchema.cpp
98
- DESTINATION ${CMAKE_SOURCE_DIR} /samples )
99
-
100
115
if (WIN32 )
101
116
set (GRAPHQLSERVICE_DIR $< TARGET_FILE_DIR:graphqlservice> )
102
117
install (FILES ${GRAPHQLSERVICE_DIR} /graphqlservice.lib
103
118
DESTINATION lib )
104
-
105
- option (INSTALL_WINDOWS_DLLS "Copy all Windows DLLs as part of the install to get dependencies." OFF )
106
-
107
- if (INSTALL_WINDOWS_DLLS )
108
- install (CODE "include(${CMAKE_SOURCE_DIR} /copy-windows-dlls.cmake)"
109
- CODE "copy_windows_dlls(${CMAKE_BINARY_DIR} )" )
110
- endif ()
111
119
endif ()
120
+
121
+ install (EXPORT cppgraphqlgen-config
122
+ NAMESPACE cppgraphqlgen::
123
+ DESTINATION lib/cppgraphqlgen )
0 commit comments