Skip to content

Commit d8aa069

Browse files
authored
Merge pull request #17 from Sarcasm/fix_cmake_install
move public headers to graphqlservice/ directory
2 parents faddbd0 + 188b4db commit d8aa069

22 files changed

+125
-60
lines changed

CMakeLists.txt

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,39 @@ endif()
1111

1212
find_package(Threads MODULE REQUIRED)
1313

14+
include(CMakePackageConfigHelpers)
15+
1416
find_package(pegtl CONFIG REQUIRED)
1517

18+
# Set the minimum C++ standard required for compiling,
19+
# but allow for user to override on the command line using:
20+
# cmake -DCMAKE_CXX_STANDARD=[11|14|17|...] -DCMAKE_CXX_EXTENSIONS=[ON|OFF]
21+
function(cppgraphqlgen_target_set_cxx_standard target)
22+
if (CMAKE_VERSION VERSION_LESS "3.8")
23+
# The cxx_std_11 abstract compile feature
24+
# is available only starting from CMake 3.8.
25+
# We assume the availability of lambdas
26+
# indicates a C++11-compatible compiler mode.
27+
target_compile_features(${target} PUBLIC cxx_lambdas)
28+
else()
29+
target_compile_features(${target} PUBLIC cxx_std_11)
30+
endif()
31+
endfunction()
32+
1633
add_executable(schemagen
1734
GraphQLTree.cpp
1835
GraphQLResponse.cpp
1936
SchemaGenerator.cpp)
2037
target_link_libraries(schemagen PRIVATE taocpp::pegtl)
21-
target_include_directories(schemagen PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
22-
set_property(TARGET schemagen PROPERTY CXX_STANDARD 11)
38+
target_include_directories(schemagen PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR})
39+
cppgraphqlgen_target_set_cxx_standard(schemagen)
2340

2441
add_custom_command(
25-
OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
42+
OUTPUT
43+
IntrospectionSchema.cpp
44+
include/graphqlservice/IntrospectionSchema.h
2645
COMMAND schemagen
46+
COMMAND ${CMAKE_COMMAND} -E rename IntrospectionSchema.h include/graphqlservice/IntrospectionSchema.h
2747
DEPENDS schemagen
2848
COMMENT "Generating IntrospectionSchema files"
2949
)
@@ -35,18 +55,28 @@ add_library(graphqlservice
3555
Introspection.cpp
3656
IntrospectionSchema.cpp)
3757
target_link_libraries(graphqlservice PRIVATE taocpp::pegtl)
38-
target_link_libraries(graphqlservice PUBLIC ${CMAKE_THREAD_LIBS_INIT})
39-
target_include_directories(graphqlservice SYSTEM INTERFACE $<INSTALL_INTERFACE:include>)
40-
target_include_directories(graphqlservice PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
41-
set_property(TARGET graphqlservice PROPERTY CXX_STANDARD 11)
58+
target_link_libraries(graphqlservice PUBLIC Threads::Threads)
59+
# Make system includes (e.g. <graphqlservice/public.h>) work relative to the build/install generator expressions
60+
target_include_directories(graphqlservice SYSTEM PUBLIC
61+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
62+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
63+
$<INSTALL_INTERFACE:include>)
64+
# Make local includes (e.g. "private.h") work while building graphqlservice, but don't export them
65+
target_include_directories(graphqlservice PRIVATE
66+
${CMAKE_SOURCE_DIR}/include
67+
${CMAKE_BINARY_DIR}/include)
68+
cppgraphqlgen_target_set_cxx_standard(graphqlservice)
4269

4370
option(BUILD_TESTS "Build the tests and sample schema library." ON)
4471
option(UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests and the sample library." ON)
4572

4673
if(BUILD_TESTS OR UPDATE_SAMPLES)
4774
add_custom_command(
48-
OUTPUT TodaySchema.cpp TodaySchema.h
75+
OUTPUT
76+
TodaySchema.cpp
77+
include/TodaySchema.h
4978
COMMAND schemagen ${CMAKE_SOURCE_DIR}/schema.today.graphql Today today
79+
COMMAND ${CMAKE_COMMAND} -E rename TodaySchema.h include/TodaySchema.h
5080
DEPENDS schemagen schema.today.graphql
5181
COMMENT "Generating mock TodaySchema files"
5282
)
@@ -60,21 +90,23 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
6090
find_package(RapidJSON CONFIG REQUIRED)
6191

6292
add_library(todaygraphql
63-
${CMAKE_BINARY_DIR}/TodaySchema.cpp
64-
Today.cpp
65-
JSONResponse.cpp)
93+
Today.cpp
94+
TodaySchema.cpp
95+
JSONResponse.cpp)
6696
target_link_libraries(todaygraphql PUBLIC
6797
graphqlservice)
6898
target_include_directories(todaygraphql SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
69-
target_include_directories(todaygraphql PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
70-
set_property(TARGET todaygraphql PROPERTY CXX_STANDARD 11)
99+
target_include_directories(todaygraphql
100+
PUBLIC
101+
${CMAKE_SOURCE_DIR}/include
102+
${CMAKE_BINARY_DIR}/include)
103+
cppgraphqlgen_target_set_cxx_standard(todaygraphql)
71104

72105
add_executable(test_today
73106
test_today.cpp)
74107
target_link_libraries(test_today PRIVATE
75108
todaygraphql)
76-
target_include_directories(test_today PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
77-
set_property(TARGET test_today PROPERTY CXX_STANDARD 11)
109+
cppgraphqlgen_target_set_cxx_standard(test_today)
78110

79111
enable_testing()
80112
find_package(GTest MODULE REQUIRED)
@@ -85,8 +117,7 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
85117
todaygraphql
86118
GTest::GTest
87119
GTest::Main)
88-
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
89-
set_property(TARGET tests PROPERTY CXX_STANDARD 11)
120+
cppgraphqlgen_target_set_cxx_standard(tests)
90121

91122
add_test(NAME TodayServiceCase
92123
COMMAND tests --gtest_filter=TodayServiceCase.*
@@ -101,34 +132,41 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
101132

102133
if(UPDATE_SAMPLES)
103134
install(FILES
104-
${CMAKE_BINARY_DIR}/IntrospectionSchema.h
135+
${CMAKE_BINARY_DIR}/include/graphqlservice/IntrospectionSchema.h
105136
${CMAKE_BINARY_DIR}/IntrospectionSchema.cpp
106-
${CMAKE_BINARY_DIR}/TodaySchema.h
137+
${CMAKE_BINARY_DIR}/include/TodaySchema.h
107138
${CMAKE_BINARY_DIR}/TodaySchema.cpp
108139
DESTINATION ${CMAKE_SOURCE_DIR}/samples)
109140
endif()
110141
endif()
111142

112143
install(TARGETS graphqlservice
113-
EXPORT cppgraphqlgen-config
144+
EXPORT cppgraphqlgen-targets
114145
RUNTIME DESTINATION bin
115146
ARCHIVE DESTINATION lib
116147
LIBRARY DESTINATION lib)
117148

118149
install(TARGETS schemagen
150+
EXPORT cppgraphqlgen-targets
119151
RUNTIME DESTINATION tools/cppgraphqlgen
120152
CONFIGURATIONS Release)
121153

122154
install(FILES
123-
GraphQLTree.h
124-
GraphQLResponse.h
125-
GraphQLService.h
126-
Introspection.h
127-
${CMAKE_BINARY_DIR}/IntrospectionSchema.h
128-
JSONResponse.h
155+
include/graphqlservice/GraphQLTree.h
156+
include/graphqlservice/GraphQLResponse.h
157+
include/graphqlservice/GraphQLService.h
158+
include/graphqlservice/JSONResponse.h
159+
include/graphqlservice/Introspection.h
160+
${CMAKE_BINARY_DIR}/include/graphqlservice/IntrospectionSchema.h
129161
DESTINATION include/graphqlservice
130162
CONFIGURATIONS Release)
131163

132-
install(EXPORT cppgraphqlgen-config
164+
set(CMAKE_INSTALL_CONFIGDIR lib/cmake/${PROJECT_NAME})
165+
install(FILES cmake/${PROJECT_NAME}-config.cmake
166+
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
167+
)
168+
169+
install(EXPORT cppgraphqlgen-targets
133170
NAMESPACE cppgraphqlgen::
134-
DESTINATION share/cppgraphqlgen)
171+
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
172+
)

GraphQLResponse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
#include "GraphQLResponse.h"
4+
#include <graphqlservice/GraphQLResponse.h>
55

66
#include <stdexcept>
77

@@ -466,4 +466,4 @@ ScalarType Value::release<ScalarType>()
466466

467467
} /* namespace response */
468468
} /* namespace graphql */
469-
} /* namespace facebook */
469+
} /* namespace facebook */

GraphQLService.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
#include "GraphQLService.h"
54
#include "GraphQLGrammar.h"
65

6+
#include <graphqlservice/GraphQLService.h>
7+
78
#include <iostream>
89
#include <algorithm>
910
#include <array>
@@ -1066,4 +1067,4 @@ void OperationDefinitionVisitor::visit(const peg::ast_node& operationDefinition)
10661067

10671068
} /* namespace service */
10681069
} /* namespace graphql */
1069-
} /* namespace facebook */
1070+
} /* namespace facebook */

GraphQLTree.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
#include "GraphQLTree.h"
54
#include "GraphQLGrammar.h"
65

76
#include <tao/pegtl/contrib/unescape.hpp>
@@ -597,4 +596,4 @@ std::unique_ptr<peg::ast<const char*>> operator "" _graphql(const char* text, si
597596
}
598597

599598
} /* namespace graphql */
600-
} /* namespace facebook */
599+
} /* namespace facebook */

Introspection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
#include "Introspection.h"
4+
#include <graphqlservice/Introspection.h>
55

66
namespace facebook {
77
namespace graphql {
@@ -652,4 +652,4 @@ std::future<std::unique_ptr<std::string>> EnumValue::getDeprecationReason(servic
652652

653653
} /* namespace facebook */
654654
} /* namespace graphql */
655-
} /* namespace introspection */
655+
} /* namespace introspection */

JSONResponse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
#include "JSONResponse.h"
4+
#include <graphqlservice/JSONResponse.h>
55

66
namespace facebook {
77
namespace graphql {

SchemaGenerator.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,12 @@ bool Generator::outputHeader() const noexcept
11641164
11651165
#pragma once
11661166
1167+
#include <graphqlservice/GraphQLService.h>
1168+
11671169
#include <memory>
11681170
#include <string>
11691171
#include <vector>
11701172
1171-
#include "GraphQLService.h"
1172-
11731173
namespace facebook {
11741174
namespace graphql {
11751175
namespace introspection {
@@ -1496,8 +1496,15 @@ bool Generator::outputSource() const noexcept
14961496
sourceFile << R"cpp(// Copyright (c) Microsoft Corporation. All rights reserved.
14971497
// Licensed under the MIT License.
14981498
1499-
#include ")cpp" << _filenamePrefix << R"cpp(Schema.h"
1500-
#include "Introspection.h"
1499+
)cpp";
1500+
if (!_isIntrospection)
1501+
{
1502+
sourceFile << R"cpp(#include ")cpp" << _filenamePrefix << R"cpp(Schema.h"
1503+
1504+
)cpp";
1505+
}
1506+
1507+
sourceFile << R"cpp(#include <graphqlservice/Introspection.h>
15011508
15021509
#include <algorithm>
15031510
#include <functional>

cmake/cppgraphqlgen-config.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
#[=======================================================================[.rst:
5+
cppgraphqlgen
6+
-------------
7+
8+
The following import targets are created
9+
10+
::
11+
12+
cppgraphqlgen::graphqlservice
13+
cppgraphqlgen::schemagen
14+
#]=======================================================================]
15+
16+
include(CMakeFindDependencyMacro)
17+
find_package(pegtl REQUIRED)
18+
find_package(Threads REQUIRED)
19+
include("${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-targets.cmake")

GraphQLGrammar.h renamed to include/GraphQLGrammar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include <tao/pegtl.hpp>
9+
#include <graphqlservice/GraphQLTree.h>
1010

1111
namespace facebook {
1212
namespace graphql {

SchemaGenerator.h renamed to include/SchemaGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <array>
77
#include <cstdio>
88

9-
#include "GraphQLService.h"
9+
#include <graphqlservice/GraphQLService.h>
1010

1111
namespace facebook {
1212
namespace graphql {
@@ -301,4 +301,4 @@ class Generator
301301

302302
} /* namespace schema */
303303
} /* namespace graphql */
304-
} /* namespace facebook */
304+
} /* namespace facebook */

0 commit comments

Comments
 (0)