Skip to content

Commit a50660c

Browse files
authored
Merge pull request #42 from mbodmer/fix/cmake-opt-use-rjson-install-split
Conditional install of graphqljson
2 parents b996095 + 955925b commit a50660c

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ schemagen
3030
settings.json
3131
test_today
3232
tests
33+
build

CMakeLists.txt

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,38 @@ cppgraphqlgen_target_set_cxx_standard(graphqlservice)
6767
# RapidJSON is the only option for JSON serialization used in this project, but if you want
6868
# to use another JSON library you can implement an alternate version of the functions in
6969
# JSONResponse.cpp to serialize to and from GraphQLResponse and build graphqljson from that.
70+
# You will also need to define how to build the graphqljson library target with your
71+
# implementation, and you should set BUILD_GRAPHQLJSON so that the test dependencies know
72+
# about your version of graphqljson.
7073
option(USE_RAPIDJSON "Use RapidJSON for JSON serialization." ON)
7174

7275
if(USE_RAPIDJSON)
7376
find_package(RapidJSON CONFIG REQUIRED)
7477

78+
set(BUILD_GRAPHQLJSON ON)
7579
add_library(graphqljson
7680
JSONResponse.cpp)
77-
target_link_libraries(graphqljson PUBLIC
78-
graphqlservice)
7981
target_include_directories(graphqljson SYSTEM PRIVATE
8082
${RAPIDJSON_INCLUDE_DIRS})
83+
endif()
84+
85+
if(BUILD_GRAPHQLJSON)
86+
option(BUILD_TESTS "Build the tests and sample schema library." ON)
87+
88+
target_link_libraries(graphqljson PUBLIC
89+
graphqlservice)
8190
cppgraphqlgen_target_set_cxx_standard(graphqljson)
91+
92+
install(TARGETS
93+
graphqljson
94+
EXPORT cppgraphqlgen-targets
95+
RUNTIME DESTINATION bin
96+
ARCHIVE DESTINATION lib
97+
LIBRARY DESTINATION lib)
98+
else()
99+
set(BUILD_TESTS OFF)
82100
endif()
83101

84-
option(BUILD_TESTS "Build the tests and sample schema library." ON)
85102
option(UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON)
86103

87104
if(BUILD_TESTS OR UPDATE_SAMPLES)
@@ -100,22 +117,22 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
100117
DEPENDS TodaySchema.cpp
101118
)
102119

103-
if(BUILD_TESTS)
104-
add_library(todaygraphql
105-
Today.cpp
106-
TodaySchema.cpp)
107-
target_link_libraries(todaygraphql PUBLIC
108-
graphqlservice
109-
graphqljson)
110-
target_include_directories(todaygraphql PUBLIC
111-
${CMAKE_CURRENT_SOURCE_DIR}/include
112-
${CMAKE_CURRENT_BINARY_DIR}/include)
113-
cppgraphqlgen_target_set_cxx_standard(todaygraphql)
120+
add_library(todaygraphql
121+
Today.cpp
122+
TodaySchema.cpp)
123+
target_link_libraries(todaygraphql PUBLIC
124+
graphqlservice)
125+
target_include_directories(todaygraphql PUBLIC
126+
${CMAKE_CURRENT_SOURCE_DIR}/include
127+
${CMAKE_CURRENT_BINARY_DIR}/include)
128+
cppgraphqlgen_target_set_cxx_standard(todaygraphql)
114129

130+
if(BUILD_TESTS)
115131
add_executable(test_today
116132
test_today.cpp)
117133
target_link_libraries(test_today PRIVATE
118-
todaygraphql)
134+
todaygraphql
135+
graphqljson)
119136
cppgraphqlgen_target_set_cxx_standard(test_today)
120137

121138
enable_testing()
@@ -125,6 +142,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
125142
tests.cpp)
126143
target_link_libraries(tests PRIVATE
127144
todaygraphql
145+
graphqljson
128146
GTest::GTest
129147
GTest::Main)
130148
cppgraphqlgen_target_set_cxx_standard(tests)
@@ -155,7 +173,6 @@ endif()
155173

156174
install(TARGETS
157175
graphqlservice
158-
graphqljson
159176
EXPORT cppgraphqlgen-targets
160177
RUNTIME DESTINATION bin
161178
ARCHIVE DESTINATION lib

0 commit comments

Comments
 (0)