From ee38062be8ccdb7f4c53156ef00db0d42a41a6a7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 22 Jan 2015 23:40:27 +0100 Subject: [PATCH 1/2] IncludeDirectories: Respect SYSTEM flag when using CONFIG genex. Update the Makefile and Ninja generators to use the config when requesting the include flags. --- Source/cmMakefileTargetGenerator.cxx | 3 ++- Source/cmNinjaTargetGenerator.cxx | 4 +++- .../SystemIncludeDirectories/CMakeLists.txt | 8 +++++++- .../config_specific/config_iface.h | 14 ++++++++++++++ .../SystemIncludeDirectories/consumer.cpp | 2 ++ 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 Tests/IncludeDirectories/SystemIncludeDirectories/config_specific/config_iface.h diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index f8471fdb2..7ed0c106a 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1870,7 +1870,8 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags, std::string includeFlags = this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget, - lang, false, useResponseFile); + lang, false, useResponseFile, + config); if(includeFlags.empty()) { return; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index c019ceb48..67824c616 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -170,8 +170,10 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source, std::string includeFlags = this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget, language, - language == "RC" ? true : false); // full include paths for RC + language == "RC" ? true : false, // full include paths for RC // needed by cmcldeps + false, + this->GetConfigName()); if(cmGlobalNinjaGenerator::IsMinGW()) cmSystemTools::ReplaceString(includeFlags, "\\", "/"); diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt index abe9f74d9..0215e9322 100644 --- a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt @@ -14,8 +14,14 @@ target_include_directories(upstream SYSTEM PUBLIC $ ) +add_library(config_specific INTERFACE) +set(testConfig ${CMAKE_BUILD_TYPE}) +target_include_directories(config_specific SYSTEM INTERFACE + "$<$:${CMAKE_CURRENT_SOURCE_DIR}/config_specific>" +) + add_library(consumer consumer.cpp) -target_link_libraries(consumer upstream) +target_link_libraries(consumer upstream config_specific) target_compile_options(consumer PRIVATE -Werror=unused-variable) add_library(iface IMPORTED INTERFACE) diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/config_specific/config_iface.h b/Tests/IncludeDirectories/SystemIncludeDirectories/config_specific/config_iface.h new file mode 100644 index 000000000..05d3604eb --- /dev/null +++ b/Tests/IncludeDirectories/SystemIncludeDirectories/config_specific/config_iface.h @@ -0,0 +1,14 @@ + +#ifndef CONFIG_IFACE_H +#define CONFIG_IFACE_H + +#ifdef _WIN32 +__declspec(dllexport) +#endif +int configUnusedFunc() +{ + int unused; + return 0; +} + +#endif diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp b/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp index 197dae86d..be18ebf52 100644 --- a/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp +++ b/Tests/IncludeDirectories/SystemIncludeDirectories/consumer.cpp @@ -1,6 +1,8 @@ #include "upstream.h" +#include "config_iface.h" + int consumer() { return upstream(); From 85857e6d1c1859bdc8ab4206e0329e846b6ef020 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 23 Jan 2015 00:14:32 +0100 Subject: [PATCH 2/2] Help: Clarify INTERFACE_SYSTEM_INCLUDE_DIRECTORIES documentation. --- .../prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst b/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst index b54b6c1d8..a0a97ada7 100644 --- a/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst +++ b/Help/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.rst @@ -7,8 +7,15 @@ Targets may populate this property to publish the include directories which contain system headers, and therefore should not result in compiler warnings. The :command:`target_include_directories(SYSTEM)` command signature populates this property with values given to the -``PUBLIC`` and ``INTERFACE`` keywords. Projects may also get and set the -property directly. +``PUBLIC`` and ``INTERFACE`` keywords. + +Projects may also get and set the property directly, but must be aware that +adding directories to this property does not make those directories used +during compilation. Adding directories to this property marks directories +as ``SYSTEM`` which otherwise would be used in a non-``SYSTEM`` manner. This +can appear similar to 'duplication', so prefer the +high-level :command:`target_include_directories(SYSTEM)` command and avoid +setting the property by low-level means. When target dependencies are specified using :command:`target_link_libraries`, CMake will read this property from all target dependencies to mark the