mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
Compiler/MSVC: use the -external:I
flag for system includes
See: #17904
This commit is contained in:
7
Help/release/dev/msvc-isystem.rst
Normal file
7
Help/release/dev/msvc-isystem.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
msvc-isystem
|
||||||
|
------------
|
||||||
|
|
||||||
|
* The MSVC compilers learned to pass the ``-external:I`` flag for system
|
||||||
|
includes when using the :generator:`Ninja` and :generator:`NMake Makefiles`
|
||||||
|
generators. This became available as of Visual Studio 16.10 (toolchain
|
||||||
|
version 14.29.30037).
|
@@ -63,3 +63,9 @@ endmacro()
|
|||||||
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
|
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
|
||||||
set(CMAKE_C_COMPILE_OPTIONS_JMC "-JMC")
|
set(CMAKE_C_COMPILE_OPTIONS_JMC "-JMC")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# The `/external:I` flag was made non-experimental in 19.29.30036.3.
|
||||||
|
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30036.3)
|
||||||
|
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-external:I ")
|
||||||
|
set(_CMAKE_INCLUDE_SYSTEM_FLAG_C_WARNING "-external:W0 ")
|
||||||
|
endif ()
|
||||||
|
@@ -79,3 +79,9 @@ endif()
|
|||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
|
||||||
set(CMAKE_CXX_COMPILE_OPTIONS_JMC "-JMC")
|
set(CMAKE_CXX_COMPILE_OPTIONS_JMC "-JMC")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# The `/external:I` flag was made non-experimental in 19.29.30036.3.
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30036.3)
|
||||||
|
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-external:I ")
|
||||||
|
set(_CMAKE_INCLUDE_SYSTEM_FLAG_CXX_WARNING "-external:W0 ")
|
||||||
|
endif ()
|
||||||
|
@@ -878,9 +878,12 @@ std::string cmLocalGenerator::GetIncludeFlags(
|
|||||||
// Support special system include flag if it is available and the
|
// Support special system include flag if it is available and the
|
||||||
// normal flag is repeated for each directory.
|
// normal flag is repeated for each directory.
|
||||||
cmProp sysIncludeFlag = nullptr;
|
cmProp sysIncludeFlag = nullptr;
|
||||||
|
cmProp sysIncludeFlagWarning = nullptr;
|
||||||
if (repeatFlag) {
|
if (repeatFlag) {
|
||||||
sysIncludeFlag = this->Makefile->GetDefinition(
|
sysIncludeFlag = this->Makefile->GetDefinition(
|
||||||
cmStrCat("CMAKE_INCLUDE_SYSTEM_FLAG_", lang));
|
cmStrCat("CMAKE_INCLUDE_SYSTEM_FLAG_", lang));
|
||||||
|
sysIncludeFlagWarning = this->Makefile->GetDefinition(
|
||||||
|
cmStrCat("_CMAKE_INCLUDE_SYSTEM_FLAG_", lang, "_WARNING"));
|
||||||
}
|
}
|
||||||
|
|
||||||
cmProp fwSearchFlag = this->Makefile->GetDefinition(
|
cmProp fwSearchFlag = this->Makefile->GetDefinition(
|
||||||
@@ -889,6 +892,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
|
|||||||
cmStrCat("CMAKE_", lang, "_SYSTEM_FRAMEWORK_SEARCH_FLAG"));
|
cmStrCat("CMAKE_", lang, "_SYSTEM_FRAMEWORK_SEARCH_FLAG"));
|
||||||
|
|
||||||
bool flagUsed = false;
|
bool flagUsed = false;
|
||||||
|
bool sysIncludeFlagUsed = false;
|
||||||
std::set<std::string> emitted;
|
std::set<std::string> emitted;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
emitted.insert("/System/Library/Frameworks");
|
emitted.insert("/System/Library/Frameworks");
|
||||||
@@ -915,6 +919,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
|
|||||||
if (sysIncludeFlag && target &&
|
if (sysIncludeFlag && target &&
|
||||||
target->IsSystemIncludeDirectory(i, config, lang)) {
|
target->IsSystemIncludeDirectory(i, config, lang)) {
|
||||||
includeFlags << *sysIncludeFlag;
|
includeFlags << *sysIncludeFlag;
|
||||||
|
sysIncludeFlagUsed = true;
|
||||||
} else {
|
} else {
|
||||||
includeFlags << includeFlag;
|
includeFlags << includeFlag;
|
||||||
}
|
}
|
||||||
@@ -931,6 +936,9 @@ std::string cmLocalGenerator::GetIncludeFlags(
|
|||||||
}
|
}
|
||||||
includeFlags << sep;
|
includeFlags << sep;
|
||||||
}
|
}
|
||||||
|
if (sysIncludeFlagUsed && sysIncludeFlagWarning) {
|
||||||
|
includeFlags << *sysIncludeFlagWarning;
|
||||||
|
}
|
||||||
std::string flags = includeFlags.str();
|
std::string flags = includeFlags.str();
|
||||||
// remove trailing separators
|
// remove trailing separators
|
||||||
if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) {
|
if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) {
|
||||||
|
Reference in New Issue
Block a user