mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 12:16:40 +08:00
Genex: Fix COMPILE_LANGUAGE propagation through try_compile
When evaluating include directories during export to a `try_compile` test project, thread the compile language through to the generator expression evaluator so it can support `$<COMPILE_LANGUAGE:...>`. Issue: #17811
This commit is contained in:
@@ -580,7 +580,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
|
|
||||||
if (!targets.empty()) {
|
if (!targets.empty()) {
|
||||||
std::string fname = "/" + std::string(targetName) + "Targets.cmake";
|
std::string fname = "/" + std::string(targetName) + "Targets.cmake";
|
||||||
cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile);
|
cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile,
|
||||||
|
testLangs);
|
||||||
tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
|
tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
|
||||||
tcfg.SetConfig(tcConfig);
|
tcfg.SetConfig(tcConfig);
|
||||||
|
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
|
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
|
||||||
cmGlobalGenerator* gg, const std::vector<std::string>& targets,
|
cmGlobalGenerator* gg, const std::vector<std::string>& targets,
|
||||||
cmMakefile* mf)
|
cmMakefile* mf, std::set<std::string> const& langs)
|
||||||
|
: Languages(langs.begin(), langs.end())
|
||||||
{
|
{
|
||||||
gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
|
gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
|
||||||
}
|
}
|
||||||
@@ -36,12 +37,14 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
|
|||||||
|
|
||||||
ImportPropertyMap properties;
|
ImportPropertyMap properties;
|
||||||
|
|
||||||
|
for (std::string const& lang : this->Languages) {
|
||||||
#define FIND_TARGETS(PROPERTY) \
|
#define FIND_TARGETS(PROPERTY) \
|
||||||
this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
|
this->FindTargets("INTERFACE_" #PROPERTY, te, lang, emittedDeps);
|
||||||
|
|
||||||
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
|
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
|
||||||
|
|
||||||
#undef FIND_TARGETS
|
#undef FIND_TARGETS
|
||||||
|
}
|
||||||
|
|
||||||
this->PopulateProperties(te, properties, emittedDeps);
|
this->PopulateProperties(te, properties, emittedDeps);
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
|
|||||||
|
|
||||||
std::string cmExportTryCompileFileGenerator::FindTargets(
|
std::string cmExportTryCompileFileGenerator::FindTargets(
|
||||||
const std::string& propName, cmGeneratorTarget const* tgt,
|
const std::string& propName, cmGeneratorTarget const* tgt,
|
||||||
std::set<cmGeneratorTarget const*>& emitted)
|
std::string const& language, std::set<cmGeneratorTarget const*>& emitted)
|
||||||
{
|
{
|
||||||
const char* prop = tgt->GetProperty(propName);
|
const char* prop = tgt->GetProperty(propName);
|
||||||
if (!prop) {
|
if (!prop) {
|
||||||
@@ -72,8 +75,9 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
|
|||||||
|
|
||||||
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
|
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
|
||||||
|
|
||||||
std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
|
std::string result =
|
||||||
false, &gDummyHead, tgt, &dagChecker);
|
cge->Evaluate(tgt->GetLocalGenerator(), this->Config, false, &gDummyHead,
|
||||||
|
tgt, &dagChecker, language);
|
||||||
|
|
||||||
const std::set<cmGeneratorTarget const*>& allTargets =
|
const std::set<cmGeneratorTarget const*>& allTargets =
|
||||||
cge->GetAllTargetsSeen();
|
cge->GetAllTargetsSeen();
|
||||||
@@ -97,7 +101,8 @@ void cmExportTryCompileFileGenerator::PopulateProperties(
|
|||||||
if (p.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
|
if (p.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
|
||||||
p.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0 ||
|
p.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0 ||
|
||||||
p.find("INTERFACE_LINK_LIBRARIES") == 0) {
|
p.find("INTERFACE_LINK_LIBRARIES") == 0) {
|
||||||
std::string evalResult = this->FindTargets(p, target, emitted);
|
std::string evalResult =
|
||||||
|
this->FindTargets(p, target, std::string(), emitted);
|
||||||
|
|
||||||
std::vector<std::string> depends;
|
std::vector<std::string> depends;
|
||||||
cmSystemTools::ExpandListArgument(evalResult, depends);
|
cmSystemTools::ExpandListArgument(evalResult, depends);
|
||||||
|
@@ -21,7 +21,8 @@ class cmExportTryCompileFileGenerator : public cmExportFileGenerator
|
|||||||
public:
|
public:
|
||||||
cmExportTryCompileFileGenerator(cmGlobalGenerator* gg,
|
cmExportTryCompileFileGenerator(cmGlobalGenerator* gg,
|
||||||
std::vector<std::string> const& targets,
|
std::vector<std::string> const& targets,
|
||||||
cmMakefile* mf);
|
cmMakefile* mf,
|
||||||
|
std::set<std::string> const& langs);
|
||||||
|
|
||||||
/** Set the list of targets to export. */
|
/** Set the list of targets to export. */
|
||||||
void SetConfig(const std::string& config) { this->Config = config; }
|
void SetConfig(const std::string& config) { this->Config = config; }
|
||||||
@@ -49,10 +50,12 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::string FindTargets(const std::string& prop,
|
std::string FindTargets(const std::string& prop,
|
||||||
const cmGeneratorTarget* tgt,
|
const cmGeneratorTarget* tgt,
|
||||||
|
std::string const& language,
|
||||||
std::set<const cmGeneratorTarget*>& emitted);
|
std::set<const cmGeneratorTarget*>& emitted);
|
||||||
|
|
||||||
std::vector<cmGeneratorTarget const*> Exports;
|
std::vector<cmGeneratorTarget const*> Exports;
|
||||||
std::string Config;
|
std::string Config;
|
||||||
|
std::vector<std::string> Languages;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -32,7 +32,9 @@ target_link_libraries(consumer upstream config_specific)
|
|||||||
target_compile_options(consumer PRIVATE -Werror=unused-variable)
|
target_compile_options(consumer PRIVATE -Werror=unused-variable)
|
||||||
|
|
||||||
add_library(iface IMPORTED INTERFACE)
|
add_library(iface IMPORTED INTERFACE)
|
||||||
set_property(TARGET iface PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/systemlib_header_only")
|
set_property(TARGET iface PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
||||||
|
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/systemlib_header_only>"
|
||||||
|
)
|
||||||
|
|
||||||
add_library(imported_consumer imported_consumer.cpp)
|
add_library(imported_consumer imported_consumer.cpp)
|
||||||
target_link_libraries(imported_consumer iface)
|
target_link_libraries(imported_consumer iface)
|
||||||
@@ -52,13 +54,6 @@ 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