Skip to content

Commit fec456b

Browse files
committed
Get build working with vcpkg built cpprestsdk
1 parent 2f536bc commit fec456b

File tree

2 files changed

+72
-73
lines changed

2 files changed

+72
-73
lines changed

CMakeLists.txt

Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33

44
cmake_minimum_required(VERSION 3.5.1)
5-
project(cppgraphql)
5+
project(cppgraphqlgen)
66

77
if(WIN32)
88
# Let CMake figure out the exports for the SHARED library (DLL) on Windows.
@@ -14,16 +14,17 @@ add_executable(schemagen SchemaGenerator.cpp)
1414

1515
find_library(GRAPHQLPARSER graphqlparser)
1616

17+
find_package(cpprestsdk REQUIRED)
18+
set(CPPRESTSDK cpprestsdk::cpprest)
19+
1720
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})
2223
endif()
2324

24-
target_include_directories(graphqlservice SYSTEM PUBLIC ${CMAKE_PREFIX_PATH}/include ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
25-
target_link_libraries(graphqlservice ${CPPRESTSDK_LIB} ${GRAPHQLPARSER})
26-
target_link_libraries(schemagen ${CPPRESTSDK_LIB} ${GRAPHQLPARSER})
25+
target_include_directories(graphqlservice INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
26+
target_link_libraries(graphqlservice ${CPPRESTSDK} ${GRAPHQLPARSER})
27+
target_link_libraries(schemagen ${CPPRESTSDK} ${GRAPHQLPARSER})
2728

2829
add_custom_command(
2930
OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
@@ -32,73 +33,83 @@ add_custom_command(
3233
COMMENT "Generating IntrospectionSchema files"
3334
)
3435

35-
add_custom_command(
36-
OUTPUT TodaySchema.cpp TodaySchema.h
37-
COMMAND schemagen ${CMAKE_SOURCE_DIR}/schema.today.graphql Today today
38-
DEPENDS schemagen schema.today.graphql
39-
COMMENT "Generating mock TodaySchema files"
40-
)
41-
42-
add_library(todaygraphql SHARED
43-
TodaySchema.cpp
44-
Today.cpp)
45-
46-
target_link_libraries(todaygraphql
47-
${CPPRESTSDK_LIB}
48-
${GRAPHQLPARSER}
49-
graphqlservice)
50-
target_include_directories(todaygraphql SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
51-
52-
add_executable(test_today test_today.cpp)
53-
54-
target_link_libraries(test_today
55-
${CPPRESTSDK_LIB}
56-
${GRAPHQLPARSER}
57-
graphqlservice
58-
todaygraphql)
59-
target_include_directories(test_today SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
60-
61-
enable_testing()
62-
add_executable(tests tests.cpp)
63-
find_package(GTest REQUIRED)
64-
target_link_libraries(tests
65-
${CPPRESTSDK_LIB}
66-
${GRAPHQLPARSER}
67-
graphqlservice
68-
todaygraphql
69-
GTest::GTest
70-
GTest::Main)
71-
target_include_directories(tests SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
72-
add_test(TodayServiceCase tests)
73-
add_test(ArgumentsCase tests)
74-
7536
if(UNIX)
7637
target_compile_options(graphqlservice PRIVATE -std=c++11)
77-
target_compile_options(todaygraphql PRIVATE -std=c++11)
7838
target_compile_options(schemagen PRIVATE -std=c++11)
79-
target_compile_options(test_today PRIVATE -std=c++11)
80-
target_compile_options(tests PRIVATE -std=c++11)
39+
endif()
40+
41+
option(BUILD_TESTS "Build the tests and sample schema library." ON)
42+
option(UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON)
43+
44+
if(BUILD_TESTS OR UPDATE_SAMPLES)
45+
add_custom_command(
46+
OUTPUT TodaySchema.cpp TodaySchema.h
47+
COMMAND schemagen ${CMAKE_SOURCE_DIR}/schema.today.graphql Today today
48+
DEPENDS schemagen schema.today.graphql
49+
COMMENT "Generating mock TodaySchema files"
50+
)
51+
52+
if(BUILD_TESTS)
53+
add_library(todaygraphql SHARED
54+
TodaySchema.cpp
55+
Today.cpp)
56+
57+
target_link_libraries(todaygraphql
58+
${CPPRESTSDK}
59+
${GRAPHQLPARSER}
60+
graphqlservice)
61+
target_include_directories(todaygraphql SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
62+
63+
add_executable(test_today test_today.cpp)
64+
65+
target_link_libraries(test_today
66+
${CPPRESTSDK}
67+
${GRAPHQLPARSER}
68+
graphqlservice
69+
todaygraphql)
70+
target_include_directories(test_today SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
71+
72+
enable_testing()
73+
add_executable(tests tests.cpp)
74+
find_package(GTest REQUIRED)
75+
target_link_libraries(tests
76+
${CPPRESTSDK}
77+
${GRAPHQLPARSER}
78+
graphqlservice
79+
todaygraphql
80+
GTest::GTest
81+
GTest::Main)
82+
target_include_directories(tests SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
83+
add_test(TodayServiceCase tests)
84+
add_test(ArgumentsCase tests)
85+
86+
if(UNIX)
87+
target_compile_options(todaygraphql PRIVATE -std=c++11)
88+
target_compile_options(test_today PRIVATE -std=c++11)
89+
target_compile_options(tests PRIVATE -std=c++11)
90+
endif()
91+
endif()
92+
93+
if(UPDATE_SAMPLES)
94+
install(FILES IntrospectionSchema.h IntrospectionSchema.cpp TodaySchema.h TodaySchema.cpp
95+
DESTINATION ${CMAKE_SOURCE_DIR}/samples)
96+
endif()
8197
endif()
8298

8399
install(TARGETS graphqlservice schemagen
100+
EXPORT cppgraphqlgen-config
84101
RUNTIME DESTINATION bin
85102
LIBRARY DESTINATION lib)
86103

87104
install(FILES GraphQLService.h Introspection.h IntrospectionSchema.h
88105
DESTINATION include/graphqlservice)
89106

90-
install(FILES IntrospectionSchema.h IntrospectionSchema.cpp TodaySchema.h TodaySchema.cpp
91-
DESTINATION ${CMAKE_SOURCE_DIR}/samples)
92-
93107
if(WIN32)
94108
set(GRAPHQLSERVICE_DIR $<TARGET_FILE_DIR:graphqlservice>)
95109
install(FILES ${GRAPHQLSERVICE_DIR}/graphqlservice.lib
96110
DESTINATION lib)
97-
98-
option(INSTALL_WINDOWS_DLLS "Copy all Windows DLLs as part of the install to get dependencies." OFF)
99-
100-
if(INSTALL_WINDOWS_DLLS)
101-
install(CODE "include(${CMAKE_SOURCE_DIR}/copy-windows-dlls.cmake)"
102-
CODE "copy_windows_dlls(${CMAKE_BINARY_DIR})")
103-
endif()
104111
endif()
112+
113+
install(EXPORT cppgraphqlgen-config
114+
NAMESPACE cppgraphqlgen::
115+
DESTINATION lib/cppgraphqlgen)

copy-windows-dlls.cmake

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)