Commit 6f688615 by Evan Cox

add new CMake option `ABSL_USE_SYSTEM_INCLUDES`

When using Abseil as a dependency with CMake, files that include Abseil headers and have incompatible warning settings can emit compiler warnings. CMake allows you to mark include directories as `SYSTEM` includes, which causes compilers to ignore warnings from those headers. 

This adds the new option `ABSL_USE_SYSTEM_INCLUDES`, which makes Abseil's include directories be marked with `SYSTEM`. 
parent 697acabc
...@@ -26,6 +26,12 @@ if(NOT DEFINED ABSL_IDE_FOLDER) ...@@ -26,6 +26,12 @@ if(NOT DEFINED ABSL_IDE_FOLDER)
set(ABSL_IDE_FOLDER Abseil) set(ABSL_IDE_FOLDER Abseil)
endif() endif()
if(ABSL_USE_SYSTEM_INCLUDES)
set(ABSL_INTERNAL_INCLUDE_WARNING_GUARD SYSTEM)
else()
set(ABSL_INTERNAL_INCLUDE_WARNING_GUARD "")
endif()
# absl_cc_library() # absl_cc_library()
# #
# CMake function to imitate Bazel's cc_library rule. # CMake function to imitate Bazel's cc_library rule.
...@@ -242,7 +248,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") ...@@ -242,7 +248,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
# unconditionally. # unconditionally.
set_property(TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX") set_property(TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX")
target_include_directories(${_NAME} target_include_directories(${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
PUBLIC PUBLIC
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>" "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
...@@ -290,7 +296,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") ...@@ -290,7 +296,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
else() else()
# Generating header-only library # Generating header-only library
add_library(${_NAME} INTERFACE) add_library(${_NAME} INTERFACE)
target_include_directories(${_NAME} target_include_directories(${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
INTERFACE INTERFACE
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>" "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>"
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
......
...@@ -70,6 +70,10 @@ if((${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.8) AND (NOT ABSL_PROPAGATE_CXX_STD) ...@@ -70,6 +70,10 @@ if((${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.8) AND (NOT ABSL_PROPAGATE_CXX_STD)
message(WARNING "A future Abseil release will default ABSL_PROPAGATE_CXX_STD to ON for CMake 3.8 and up. We recommend enabling this option to ensure your project still builds correctly.") message(WARNING "A future Abseil release will default ABSL_PROPAGATE_CXX_STD to ON for CMake 3.8 and up. We recommend enabling this option to ensure your project still builds correctly.")
endif() endif()
option(ABSL_USE_SYSTEM_INCLUDES
"Mark C++ include directories with `SYSTEM` to prevent warnings from headers when using Abseil with incompatible warning flags"
OFF)
list(APPEND CMAKE_MODULE_PATH list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}/CMake ${CMAKE_CURRENT_LIST_DIR}/CMake
${CMAKE_CURRENT_LIST_DIR}/absl/copts ${CMAKE_CURRENT_LIST_DIR}/absl/copts
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment