Skip to content

Commit 188b4db

Browse files
committed
Make a distinction between system and local includes
1 parent 72fdd58 commit 188b4db

17 files changed

+56
-43
lines changed

CMakeLists.txt

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ cppgraphqlgen_target_set_cxx_standard(schemagen)
4040

4141
add_custom_command(
4242
OUTPUT
43-
graphqlservice/IntrospectionSchema.cpp
44-
graphqlservice/IntrospectionSchema.h
43+
IntrospectionSchema.cpp
44+
include/graphqlservice/IntrospectionSchema.h
4545
COMMAND schemagen
46-
COMMAND ${CMAKE_COMMAND} -E rename IntrospectionSchema.cpp graphqlservice/IntrospectionSchema.cpp
47-
COMMAND ${CMAKE_COMMAND} -E rename IntrospectionSchema.h graphqlservice/IntrospectionSchema.h
46+
COMMAND ${CMAKE_COMMAND} -E rename IntrospectionSchema.h include/graphqlservice/IntrospectionSchema.h
4847
DEPENDS schemagen
4948
COMMENT "Generating IntrospectionSchema files"
5049
)
@@ -54,24 +53,30 @@ add_library(graphqlservice
5453
GraphQLResponse.cpp
5554
GraphQLService.cpp
5655
Introspection.cpp
57-
${CMAKE_BINARY_DIR}/graphqlservice/IntrospectionSchema.cpp)
56+
IntrospectionSchema.cpp)
5857
target_link_libraries(graphqlservice PRIVATE taocpp::pegtl)
5958
target_link_libraries(graphqlservice PUBLIC Threads::Threads)
60-
target_include_directories(graphqlservice
61-
PUBLIC
62-
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
63-
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
64-
$<INSTALL_INTERFACE:include>
65-
)
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)
6668
cppgraphqlgen_target_set_cxx_standard(graphqlservice)
6769

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

7173
if(BUILD_TESTS OR UPDATE_SAMPLES)
7274
add_custom_command(
73-
OUTPUT TodaySchema.cpp TodaySchema.h
75+
OUTPUT
76+
TodaySchema.cpp
77+
include/TodaySchema.h
7478
COMMAND schemagen ${CMAKE_SOURCE_DIR}/schema.today.graphql Today today
79+
COMMAND ${CMAKE_COMMAND} -E rename TodaySchema.h include/TodaySchema.h
7580
DEPENDS schemagen schema.today.graphql
7681
COMMENT "Generating mock TodaySchema files"
7782
)
@@ -85,20 +90,22 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
8590
find_package(RapidJSON CONFIG REQUIRED)
8691

8792
add_library(todaygraphql
88-
${CMAKE_BINARY_DIR}/TodaySchema.cpp
8993
Today.cpp
94+
TodaySchema.cpp
9095
JSONResponse.cpp)
9196
target_link_libraries(todaygraphql PUBLIC
9297
graphqlservice)
9398
target_include_directories(todaygraphql SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
94-
target_include_directories(todaygraphql PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
99+
target_include_directories(todaygraphql
100+
PUBLIC
101+
${CMAKE_SOURCE_DIR}/include
102+
${CMAKE_BINARY_DIR}/include)
95103
cppgraphqlgen_target_set_cxx_standard(todaygraphql)
96104

97105
add_executable(test_today
98106
test_today.cpp)
99107
target_link_libraries(test_today PRIVATE
100108
todaygraphql)
101-
target_include_directories(test_today PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
102109
cppgraphqlgen_target_set_cxx_standard(test_today)
103110

104111
enable_testing()
@@ -110,7 +117,6 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
110117
todaygraphql
111118
GTest::GTest
112119
GTest::Main)
113-
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
114120
cppgraphqlgen_target_set_cxx_standard(tests)
115121

116122
add_test(NAME TodayServiceCase
@@ -126,9 +132,9 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
126132

127133
if(UPDATE_SAMPLES)
128134
install(FILES
129-
${CMAKE_BINARY_DIR}/graphqlservice/IntrospectionSchema.h
130-
${CMAKE_BINARY_DIR}/graphqlservice/IntrospectionSchema.cpp
131-
${CMAKE_BINARY_DIR}/TodaySchema.h
135+
${CMAKE_BINARY_DIR}/include/graphqlservice/IntrospectionSchema.h
136+
${CMAKE_BINARY_DIR}/IntrospectionSchema.cpp
137+
${CMAKE_BINARY_DIR}/include/TodaySchema.h
132138
${CMAKE_BINARY_DIR}/TodaySchema.cpp
133139
DESTINATION ${CMAKE_SOURCE_DIR}/samples)
134140
endif()
@@ -149,9 +155,9 @@ install(FILES
149155
include/graphqlservice/GraphQLTree.h
150156
include/graphqlservice/GraphQLResponse.h
151157
include/graphqlservice/GraphQLService.h
152-
include/graphqlservice/Introspection.h
153-
${CMAKE_BINARY_DIR}/graphqlservice/IntrospectionSchema.h
154158
include/graphqlservice/JSONResponse.h
159+
include/graphqlservice/Introspection.h
160+
${CMAKE_BINARY_DIR}/include/graphqlservice/IntrospectionSchema.h
155161
DESTINATION include/graphqlservice
156162
CONFIGURATIONS Release)
157163

GraphQLResponse.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 "graphqlservice/GraphQLResponse.h"
4+
#include <graphqlservice/GraphQLResponse.h>
55

66
#include <stdexcept>
77

GraphQLService.cpp

Lines changed: 2 additions & 1 deletion
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/GraphQLService.h"
54
#include "GraphQLGrammar.h"
65

6+
#include <graphqlservice/GraphQLService.h>
7+
78
#include <iostream>
89
#include <algorithm>
910
#include <array>

GraphQLTree.cpp

Lines changed: 0 additions & 1 deletion
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 "graphqlservice/GraphQLTree.h"
54
#include "GraphQLGrammar.h"
65

76
#include <tao/pegtl/contrib/unescape.hpp>

Introspection.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 "graphqlservice/Introspection.h"
4+
#include <graphqlservice/Introspection.h>
55

66
namespace facebook {
77
namespace graphql {

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 "graphqlservice/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/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 <graphqlservice/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>

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 {

include/SchemaGenerator.h

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

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

1111
namespace facebook {
1212
namespace graphql {

include/graphqlservice/GraphQLService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#pragma once
55

6-
#include "graphqlservice/GraphQLTree.h"
7-
#include "graphqlservice/GraphQLResponse.h"
6+
#include <graphqlservice/GraphQLTree.h>
7+
#include <graphqlservice/GraphQLResponse.h>
88

99
#include <memory>
1010
#include <string>

0 commit comments

Comments
 (0)