Commit 2deb9b7f authored by Brad King's avatar Brad King
Browse files

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
parent c5541cf0
......@@ -384,14 +384,15 @@ static void handleSystemIncludesDep(
cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
const std::string& config, cmGeneratorTarget const* headTarget,
cmGeneratorExpressionDAGChecker* dagChecker,
std::vector<std::string>& result, bool excludeImported)
std::vector<std::string>& result, bool excludeImported,
std::string const& language)
{
if (const char* dirs =
depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
dagChecker),
dagChecker, language),
result);
}
if (!depTgt->IsImported() || excludeImported) {
......@@ -403,7 +404,7 @@ static void handleSystemIncludesDep(
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
dagChecker),
dagChecker, language),
result);
}
}
......@@ -735,7 +736,8 @@ const char* cmGeneratorTarget::GetLocationForBuild() const
}
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);
std::string config_upper;
......@@ -758,7 +760,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(it)->Evaluate(this->LocalGenerator, config, false, this,
&dagChecker),
&dagChecker, language),
result);
}
......@@ -766,7 +768,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
this->GetLinkImplementationClosure(config);
for (cmGeneratorTarget const* dep : deps) {
handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
&dagChecker, result, excludeImported);
&dagChecker, result, excludeImported, language);
}
std::for_each(result.begin(), result.end(),
......
......@@ -413,7 +413,8 @@ public:
const std::string& language) const;
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. */
void ComputeTargetManifest(const std::string& config) const;
......
......@@ -2035,7 +2035,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
if (emitted.insert(frameworkDir).second) {
std::string incpath = this->XCodeEscapePath(frameworkDir);
if (emitSystemIncludes &&
gtgt->IsSystemIncludeDirectory(frameworkDir, configName)) {
gtgt->IsSystemIncludeDirectory(frameworkDir, configName,
langForPreprocessor)) {
sysfdirs.Add(incpath);
} else {
fdirs.Add(incpath);
......@@ -2044,7 +2045,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
} else {
std::string incpath = this->XCodeEscapePath(include);
if (emitSystemIncludes &&
gtgt->IsSystemIncludeDirectory(include, configName)) {
gtgt->IsSystemIncludeDirectory(include, configName,
langForPreprocessor)) {
sysdirs.Add(incpath);
} else {
dirs.Add(incpath);
......@@ -2057,7 +2059,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
if (emitted.insert(fwDir).second) {
std::string incpath = this->XCodeEscapePath(fwDir);
if (emitSystemIncludes &&
gtgt->IsSystemIncludeDirectory(fwDir, configName)) {
gtgt->IsSystemIncludeDirectory(fwDir, configName,
langForPreprocessor)) {
sysfdirs.Add(incpath);
} else {
fdirs.Add(incpath);
......
......@@ -718,7 +718,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
if (emitted.insert(frameworkDir).second) {
if (sysFwSearchFlag && target &&
target->IsSystemIncludeDirectory(i, config)) {
target->IsSystemIncludeDirectory(i, config, lang)) {
includeFlags << sysFwSearchFlag;
} else {
includeFlags << fwSearchFlag;
......@@ -731,7 +731,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
if (!flagUsed || repeatFlag) {
if (sysIncludeFlag && target &&
target->IsSystemIncludeDirectory(i, config)) {
target->IsSystemIncludeDirectory(i, config, lang)) {
includeFlags << sysIncludeFlag;
} else {
includeFlags << includeFlag;
......
......@@ -725,8 +725,9 @@ static Json::Value DumpSourceFilesList(
lg->AppendIncludeDirectories(includes, evaluatedIncludes, *file);
for (const auto& include : includes) {
fileData.IncludePathList.push_back(std::make_pair(
include, target->IsSystemIncludeDirectory(include, config)));
fileData.IncludePathList.push_back(
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);
for (std::string const& i : includePathList) {
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_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)
set(TC_ARGS
IFACE_TRY_COMPILE_${error_option}
......
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