mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 19:08:07 +08:00
Genex: Fix COMPILE_LANGUAGE in SYSTEM include directories
When evaluating `INTERFACE_SYSTEM_INCLUDE_DIRECTORIES`, or evaluating `INTERFACE_INCLUDE_DIRECTORIES` on an imported target, thread the compile language through to the generator expression evaluator so that it can support `$<COMPILE_LANGUAGE:...>`. Fixes: #17811
This commit is contained in:
@@ -384,14 +384,15 @@ static void handleSystemIncludesDep(
|
|||||||
cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
|
cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
|
||||||
const std::string& config, cmGeneratorTarget const* headTarget,
|
const std::string& config, cmGeneratorTarget const* headTarget,
|
||||||
cmGeneratorExpressionDAGChecker* dagChecker,
|
cmGeneratorExpressionDAGChecker* dagChecker,
|
||||||
std::vector<std::string>& result, bool excludeImported)
|
std::vector<std::string>& result, bool excludeImported,
|
||||||
|
std::string const& language)
|
||||||
{
|
{
|
||||||
if (const char* dirs =
|
if (const char* dirs =
|
||||||
depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
|
depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
|
||||||
cmGeneratorExpression ge;
|
cmGeneratorExpression ge;
|
||||||
cmSystemTools::ExpandListArgument(
|
cmSystemTools::ExpandListArgument(
|
||||||
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
|
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
|
||||||
dagChecker),
|
dagChecker, language),
|
||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
if (!depTgt->IsImported() || excludeImported) {
|
if (!depTgt->IsImported() || excludeImported) {
|
||||||
@@ -403,7 +404,7 @@ static void handleSystemIncludesDep(
|
|||||||
cmGeneratorExpression ge;
|
cmGeneratorExpression ge;
|
||||||
cmSystemTools::ExpandListArgument(
|
cmSystemTools::ExpandListArgument(
|
||||||
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
|
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
|
||||||
dagChecker),
|
dagChecker, language),
|
||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -735,7 +736,8 @@ const char* cmGeneratorTarget::GetLocationForBuild() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool cmGeneratorTarget::IsSystemIncludeDirectory(
|
bool cmGeneratorTarget::IsSystemIncludeDirectory(
|
||||||
const std::string& dir, const std::string& config) const
|
const std::string& dir, const std::string& config,
|
||||||
|
const std::string& language) const
|
||||||
{
|
{
|
||||||
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
|
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
|
||||||
std::string config_upper;
|
std::string config_upper;
|
||||||
@@ -758,7 +760,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
|
|||||||
cmGeneratorExpression ge;
|
cmGeneratorExpression ge;
|
||||||
cmSystemTools::ExpandListArgument(
|
cmSystemTools::ExpandListArgument(
|
||||||
ge.Parse(it)->Evaluate(this->LocalGenerator, config, false, this,
|
ge.Parse(it)->Evaluate(this->LocalGenerator, config, false, this,
|
||||||
&dagChecker),
|
&dagChecker, language),
|
||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,7 +768,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
|
|||||||
this->GetLinkImplementationClosure(config);
|
this->GetLinkImplementationClosure(config);
|
||||||
for (cmGeneratorTarget const* dep : deps) {
|
for (cmGeneratorTarget const* dep : deps) {
|
||||||
handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
|
handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
|
||||||
&dagChecker, result, excludeImported);
|
&dagChecker, result, excludeImported, language);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::for_each(result.begin(), result.end(),
|
std::for_each(result.begin(), result.end(),
|
||||||
|
@@ -413,7 +413,8 @@ public:
|
|||||||
const std::string& language) const;
|
const std::string& language) const;
|
||||||
|
|
||||||
bool IsSystemIncludeDirectory(const std::string& dir,
|
bool IsSystemIncludeDirectory(const std::string& dir,
|
||||||
const std::string& config) const;
|
const std::string& config,
|
||||||
|
const std::string& language) const;
|
||||||
|
|
||||||
/** Add the target output files to the global generator manifest. */
|
/** Add the target output files to the global generator manifest. */
|
||||||
void ComputeTargetManifest(const std::string& config) const;
|
void ComputeTargetManifest(const std::string& config) const;
|
||||||
|
@@ -2035,7 +2035,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
|||||||
if (emitted.insert(frameworkDir).second) {
|
if (emitted.insert(frameworkDir).second) {
|
||||||
std::string incpath = this->XCodeEscapePath(frameworkDir);
|
std::string incpath = this->XCodeEscapePath(frameworkDir);
|
||||||
if (emitSystemIncludes &&
|
if (emitSystemIncludes &&
|
||||||
gtgt->IsSystemIncludeDirectory(frameworkDir, configName)) {
|
gtgt->IsSystemIncludeDirectory(frameworkDir, configName,
|
||||||
|
langForPreprocessor)) {
|
||||||
sysfdirs.Add(incpath);
|
sysfdirs.Add(incpath);
|
||||||
} else {
|
} else {
|
||||||
fdirs.Add(incpath);
|
fdirs.Add(incpath);
|
||||||
@@ -2044,7 +2045,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
|||||||
} else {
|
} else {
|
||||||
std::string incpath = this->XCodeEscapePath(include);
|
std::string incpath = this->XCodeEscapePath(include);
|
||||||
if (emitSystemIncludes &&
|
if (emitSystemIncludes &&
|
||||||
gtgt->IsSystemIncludeDirectory(include, configName)) {
|
gtgt->IsSystemIncludeDirectory(include, configName,
|
||||||
|
langForPreprocessor)) {
|
||||||
sysdirs.Add(incpath);
|
sysdirs.Add(incpath);
|
||||||
} else {
|
} else {
|
||||||
dirs.Add(incpath);
|
dirs.Add(incpath);
|
||||||
@@ -2057,7 +2059,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
|||||||
if (emitted.insert(fwDir).second) {
|
if (emitted.insert(fwDir).second) {
|
||||||
std::string incpath = this->XCodeEscapePath(fwDir);
|
std::string incpath = this->XCodeEscapePath(fwDir);
|
||||||
if (emitSystemIncludes &&
|
if (emitSystemIncludes &&
|
||||||
gtgt->IsSystemIncludeDirectory(fwDir, configName)) {
|
gtgt->IsSystemIncludeDirectory(fwDir, configName,
|
||||||
|
langForPreprocessor)) {
|
||||||
sysfdirs.Add(incpath);
|
sysfdirs.Add(incpath);
|
||||||
} else {
|
} else {
|
||||||
fdirs.Add(incpath);
|
fdirs.Add(incpath);
|
||||||
|
@@ -718,7 +718,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
|
|||||||
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
|
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
|
||||||
if (emitted.insert(frameworkDir).second) {
|
if (emitted.insert(frameworkDir).second) {
|
||||||
if (sysFwSearchFlag && target &&
|
if (sysFwSearchFlag && target &&
|
||||||
target->IsSystemIncludeDirectory(i, config)) {
|
target->IsSystemIncludeDirectory(i, config, lang)) {
|
||||||
includeFlags << sysFwSearchFlag;
|
includeFlags << sysFwSearchFlag;
|
||||||
} else {
|
} else {
|
||||||
includeFlags << fwSearchFlag;
|
includeFlags << fwSearchFlag;
|
||||||
@@ -731,7 +731,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
|
|||||||
|
|
||||||
if (!flagUsed || repeatFlag) {
|
if (!flagUsed || repeatFlag) {
|
||||||
if (sysIncludeFlag && target &&
|
if (sysIncludeFlag && target &&
|
||||||
target->IsSystemIncludeDirectory(i, config)) {
|
target->IsSystemIncludeDirectory(i, config, lang)) {
|
||||||
includeFlags << sysIncludeFlag;
|
includeFlags << sysIncludeFlag;
|
||||||
} else {
|
} else {
|
||||||
includeFlags << includeFlag;
|
includeFlags << includeFlag;
|
||||||
|
@@ -725,8 +725,9 @@ static Json::Value DumpSourceFilesList(
|
|||||||
lg->AppendIncludeDirectories(includes, evaluatedIncludes, *file);
|
lg->AppendIncludeDirectories(includes, evaluatedIncludes, *file);
|
||||||
|
|
||||||
for (const auto& include : includes) {
|
for (const auto& include : includes) {
|
||||||
fileData.IncludePathList.push_back(std::make_pair(
|
fileData.IncludePathList.push_back(
|
||||||
include, target->IsSystemIncludeDirectory(include, config)));
|
std::make_pair(include, target->IsSystemIncludeDirectory(
|
||||||
|
include, config, fileData.Language)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,7 +1006,7 @@ static Json::Value DumpTarget(cmGeneratorTarget* target,
|
|||||||
lg->GetIncludeDirectories(includePathList, target, lang, config, true);
|
lg->GetIncludeDirectories(includePathList, target, lang, config, true);
|
||||||
for (std::string const& i : includePathList) {
|
for (std::string const& i : includePathList) {
|
||||||
ld.IncludePathList.push_back(
|
ld.IncludePathList.push_back(
|
||||||
std::make_pair(i, target->IsSystemIncludeDirectory(i, config)));
|
std::make_pair(i, target->IsSystemIncludeDirectory(i, config, lang)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,6 +52,13 @@ add_library(otherlib upstream.cpp)
|
|||||||
target_link_libraries(otherlib PUBLIC somelib)
|
target_link_libraries(otherlib PUBLIC somelib)
|
||||||
target_compile_options(somelib PRIVATE -Werror=unused-variable)
|
target_compile_options(somelib PRIVATE -Werror=unused-variable)
|
||||||
|
|
||||||
|
add_library(iface_lang IMPORTED INTERFACE)
|
||||||
|
set_property(TARGET iface_lang PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
||||||
|
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/systemlib_header_only>"
|
||||||
|
)
|
||||||
|
add_library(imported_consumer_lang imported_consumer.cpp)
|
||||||
|
target_link_libraries(imported_consumer_lang iface_lang)
|
||||||
|
|
||||||
macro(do_try_compile error_option)
|
macro(do_try_compile error_option)
|
||||||
set(TC_ARGS
|
set(TC_ARGS
|
||||||
IFACE_TRY_COMPILE_${error_option}
|
IFACE_TRY_COMPILE_${error_option}
|
||||||
|
Reference in New Issue
Block a user