Skip to content

Commit 5d05a2b

Browse files
build: mark all protobuf headers as system headers (#132)
This PR makes sure that all protobuf headers, either from the library or the generated ones, are marked as `SYSTEM` headers. This causes most compilers to include them via `-isystem` instead of `-I`, which, in turn, suppresses warnings from those headers and, thus, enables compiling the main project with `-Werror`. This is achieved with the combination of several changes: * Several unnecessary `include_directories` statements have been removed. These are unnecessary because we already depend on the `protobuf::libprotobuf` target, which includes header dependencies. * We don't unnecessarily set the `target_include_directories` for the protobuf library headers for the same reason. * We mark the Protobuf library downloaded by `FetchContent` as `SYSTEM`, which marks all targets in that library as `SYSTEM`. * We manually mark our `substrait::proto` target as `SYSTEM`. I am not 100% sure if the first point doesn't break some legacy versions of Protobuf. My best guess is that those would be so old that they do not work anymore anyways. I am leaving this message in case somebody runs into problems, though. In that case, the `include_directories` commands should only be set for the legacy case. Signed-off-by: Ingo Müller <ingomueller@google.com> Co-authored-by: David Sisson <EpsilonPrime@users.noreply.github.com>
1 parent 2f5524d commit 5d05a2b

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/substrait/proto/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
22
find_package(Protobuf REQUIRED)
3-
include_directories(${Protobuf_INCLUDE_DIRS})
4-
include_directories(${CMAKE_CURRENT_BINARY_DIR})
53

64
find_package(Perl REQUIRED)
75
set(UPDATE_PROTO_PACKAGE_TOOL
@@ -94,10 +92,8 @@ target_link_libraries(substrait_proto protobuf::libprotobuf)
9492

9593
# Make sure we can see our own generated include files.
9694
target_include_directories(
97-
substrait_proto
95+
substrait_proto SYSTEM
9896
PUBLIC $<BUILD_INTERFACE:${PROTO_OUTPUT_TOPLEVEL_DIR}/src>
99-
$<INSTALL_INTERFACE:include>
100-
PUBLIC $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src>
10197
$<INSTALL_INTERFACE:include>)
10298

10399
install(

third_party/protobuf.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ FetchContent_Declare(GTest
1313
FetchContent_Declare(Protobuf
1414
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
1515
GIT_TAG v28.2
16+
SYSTEM
1617
OVERRIDE_FIND_PACKAGE
1718
)
1819

0 commit comments

Comments
 (0)