{cmake} Add option to expose includes as SYSTEM headers

This can allow projects including pugixml to avoid reporting warnings in pugixml code (depending on compiler) by marking them as SYSTEM headers.

https://cmake.org/cmake/help/latest/command/target_include_directories.html
This commit is contained in:
Andy Maloney 2023-02-27 13:50:59 -05:00
parent c2c61a5905
commit 5ea159d15e

View File

@ -27,7 +27,7 @@ set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options")
separate_arguments(PUGIXML_BUILD_DEFINES) separate_arguments(PUGIXML_BUILD_DEFINES)
# Technically not needed for this file. This is builtin CMAKE global variable. # Technically not needed for this file. This is builtin CMAKE global variable.
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF) option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
# Expose option to build PUGIXML as static as well when the global BUILD_SHARED_LIBS variable is set # Expose option to build PUGIXML as static as well when the global BUILD_SHARED_LIBS variable is set
cmake_dependent_option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS cmake_dependent_option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS
@ -44,6 +44,9 @@ option(PUGIXML_NO_STL "Disable STL" OFF)
option(PUGIXML_NO_EXCEPTIONS "Disable Exceptions" OFF) option(PUGIXML_NO_EXCEPTIONS "Disable Exceptions" OFF)
mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS) mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS)
# Other options
option(PUGIXML_HEADER_DIRS_AS_SYSTEM "Expose headers as system includes." ON)
# Policy configuration # Policy configuration
if(POLICY CMP0091) if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW) # Enables use of MSVC_RUNTIME_LIBRARY cmake_policy(SET CMP0091 NEW) # Enables use of MSVC_RUNTIME_LIBRARY
@ -95,6 +98,12 @@ set(versioned-dir $<$<BOOL:${PUGIXML_USE_VERSIONED_LIBDIR}>:/pugixml-${PROJECT_V
set(libs) set(libs)
# Optionally mark header include idrectoriess as SYSTEM
set(PUGIXML_SYSTEM_HEADERS_ATTRIBUTE "")
if (PUGIXML_EXPOSE_HEADERS_AS_SYSTEM)
set(PUGIXML_SYSTEM_HEADERS_ATTRIBUTE SYSTEM)
endif ()
if (BUILD_SHARED_LIBS) if (BUILD_SHARED_LIBS)
add_library(pugixml-shared SHARED add_library(pugixml-shared SHARED
${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc ${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc
@ -108,6 +117,7 @@ if (BUILD_SHARED_LIBS)
set_property(TARGET pugixml-shared PROPERTY EXPORT_NAME shared) set_property(TARGET pugixml-shared PROPERTY EXPORT_NAME shared)
target_include_directories(pugixml-shared target_include_directories(pugixml-shared
${PUGIXML_SYSTEM_HEADERS_ATTRIBUTE}
PUBLIC PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
target_compile_definitions(pugixml-shared target_compile_definitions(pugixml-shared
@ -133,6 +143,7 @@ if (NOT BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS)
set_property(TARGET pugixml-static PROPERTY EXPORT_NAME static) set_property(TARGET pugixml-static PROPERTY EXPORT_NAME static)
target_include_directories(pugixml-static target_include_directories(pugixml-static
${PUGIXML_SYSTEM_HEADERS_ATTRIBUTE}
PUBLIC PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
target_compile_definitions(pugixml-static target_compile_definitions(pugixml-static