Skip to content

Commit e105335

Browse files
committed
Make CMakeLists.txt compatible with vcpkg
1 parent a9e690b commit e105335

File tree

1 file changed

+57
-35
lines changed

1 file changed

+57
-35
lines changed

CMakeLists.txt

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,12 @@ if(WIN32)
99
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
1010
endif()
1111

12-
add_library(graphqlpeg GraphQLTree.cpp)
13-
add_library(graphqlservice GraphQLService.cpp Introspection.cpp IntrospectionSchema.cpp)
14-
add_executable(schemagen SchemaGenerator.cpp)
15-
1612
find_package(pegtl CONFIG REQUIRED)
1713

18-
target_include_directories(graphqlpeg INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
19-
target_link_libraries(graphqlpeg taocpp::pegtl)
20-
21-
find_package(RapidJSON CONFIG REQUIRED)
22-
23-
target_include_directories(graphqlservice INTERFACE ${RAPIDJSON_INCLUDE_DIRS} $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
24-
target_link_libraries(graphqlservice graphqlpeg)
25-
target_link_libraries(schemagen graphqlpeg)
14+
add_executable(schemagen GraphQLTree.cpp SchemaGenerator.cpp)
15+
target_link_libraries(schemagen PRIVATE taocpp::pegtl)
16+
target_include_directories(schemagen SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
17+
target_include_directories(schemagen PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
2618

2719
add_custom_command(
2820
OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
@@ -31,6 +23,18 @@ add_custom_command(
3123
COMMENT "Generating IntrospectionSchema files"
3224
)
3325

26+
find_package(RapidJSON CONFIG REQUIRED)
27+
28+
add_library(graphqlservice
29+
GraphQLTree.cpp
30+
GraphQLService.cpp
31+
Introspection.cpp
32+
IntrospectionSchema.cpp)
33+
target_link_libraries(graphqlservice PRIVATE taocpp::pegtl)
34+
target_include_directories(graphqlservice SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
35+
target_include_directories(graphqlservice SYSTEM INTERFACE $<INSTALL_INTERFACE:include>)
36+
target_include_directories(graphqlservice PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
37+
3438
if(UNIX)
3539
target_compile_options(graphqlpeg PRIVATE -std=c++11)
3640
target_compile_options(graphqlservice PRIVATE -std=c++11)
@@ -52,30 +56,41 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
5256
add_library(todaygraphql
5357
TodaySchema.cpp
5458
Today.cpp)
59+
target_link_libraries(todaygraphql
60+
graphqlservice)
61+
target_include_directories(todaygraphql SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
62+
target_include_directories(todaygraphql PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
5563

56-
target_link_libraries(todaygraphql graphqlservice)
57-
target_include_directories(todaygraphql SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
58-
59-
add_executable(test_today test_today.cpp)
60-
64+
add_executable(test_today
65+
test_today.cpp)
6166
target_link_libraries(test_today
62-
graphqlpeg
6367
graphqlservice
6468
todaygraphql)
65-
target_include_directories(test_today SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
69+
target_include_directories(test_today SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
70+
target_include_directories(test_today PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
6671

67-
enable_testing()
68-
add_executable(tests tests.cpp)
6972
find_package(GTest REQUIRED)
73+
74+
add_executable(tests
75+
tests.cpp)
7076
target_link_libraries(tests
71-
graphqlpeg
7277
graphqlservice
7378
todaygraphql
7479
GTest::GTest
7580
GTest::Main)
76-
target_include_directories(tests SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
77-
add_test(TodayServiceCase tests)
78-
add_test(ArgumentsCase tests)
81+
target_include_directories(tests SYSTEM PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
82+
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
83+
84+
enable_testing()
85+
add_test(NAME TodayServiceCase
86+
COMMAND tests --gtest_filter=TodayServiceCase.*
87+
WORKING_DIRECTORY $<TARGET_FILE_DIR:tests>)
88+
add_test(NAME ArgumentsCase
89+
COMMAND tests --gtest_filter=ArgumentsCase.*
90+
WORKING_DIRECTORY $<TARGET_FILE_DIR:tests>)
91+
add_test(NAME PegtlCase
92+
COMMAND tests --gtest_filter=PegtlCase.*
93+
WORKING_DIRECTORY $<TARGET_FILE_DIR:tests>)
7994

8095
if(UNIX)
8196
target_compile_options(todaygraphql PRIVATE -std=c++11)
@@ -85,26 +100,33 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
85100
endif()
86101

87102
if(UPDATE_SAMPLES)
88-
install(FILES IntrospectionSchema.h IntrospectionSchema.cpp TodaySchema.h TodaySchema.cpp
103+
install(FILES
104+
${CMAKE_BINARY_DIR}/IntrospectionSchema.h
105+
${CMAKE_BINARY_DIR}/IntrospectionSchema.cpp
106+
${CMAKE_BINARY_DIR}/TodaySchema.h
107+
${CMAKE_BINARY_DIR}/TodaySchema.cpp
89108
DESTINATION ${CMAKE_SOURCE_DIR}/samples)
90109
endif()
91110
endif()
92111

93-
install(TARGETS graphqlpeg graphqlservice schemagen
112+
install(TARGETS graphqlservice
94113
EXPORT cppgraphqlgen-config
95114
RUNTIME DESTINATION bin
96115
ARCHIVE DESTINATION lib
97116
LIBRARY DESTINATION lib)
98117

99-
install(FILES GraphQLService.h GraphQLTree.h Introspection.h IntrospectionSchema.h
100-
DESTINATION include/graphqlservice)
118+
install(TARGETS schemagen
119+
RUNTIME DESTINATION tools/cppgraphqlgen
120+
CONFIGURATIONS Release)
101121

102-
if(WIN32)
103-
set(GRAPHQLSERVICE_DIR $<TARGET_FILE_DIR:graphqlservice>)
104-
install(FILES ${GRAPHQLSERVICE_DIR}/graphqlservice.lib ${GRAPHQLSERVICE_DIR}/graphqlpeg.lib
105-
DESTINATION lib)
106-
endif()
122+
install(FILES
123+
GraphQLTree.h
124+
GraphQLService.h
125+
Introspection.h
126+
${CMAKE_BINARY_DIR}/IntrospectionSchema.h
127+
DESTINATION include/graphqlservice
128+
CONFIGURATIONS Release)
107129

108130
install(EXPORT cppgraphqlgen-config
109131
NAMESPACE cppgraphqlgen::
110-
DESTINATION lib/cppgraphqlgen)
132+
DESTINATION share/cppgraphqlgen)

0 commit comments

Comments
 (0)