1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306 |
- /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- file Copyright.txt or https://cmake.org/licensing for details. */
- #include "cmExportFileGenerator.h"
- #include <array>
- #include <cassert>
- #include <cstring>
- #include <sstream>
- #include <utility>
- #include <cm/memory>
- #include "cmsys/FStream.hxx"
- #include "cmComputeLinkInformation.h"
- #include "cmFileSet.h"
- #include "cmGeneratedFileStream.h"
- #include "cmGeneratorTarget.h"
- #include "cmLinkItem.h"
- #include "cmLocalGenerator.h"
- #include "cmMakefile.h"
- #include "cmMessageType.h"
- #include "cmOutputConverter.h"
- #include "cmPolicies.h"
- #include "cmPropertyMap.h"
- #include "cmStateTypes.h"
- #include "cmStringAlgorithms.h"
- #include "cmSystemTools.h"
- #include "cmTarget.h"
- #include "cmValue.h"
- static std::string cmExportFileGeneratorEscape(std::string const& str)
- {
- // Escape a property value for writing into a .cmake file.
- std::string result = cmOutputConverter::EscapeForCMake(str);
- // Un-escape variable references generated by our own export code.
- cmSystemTools::ReplaceString(result, "\\${_IMPORT_PREFIX}",
- "${_IMPORT_PREFIX}");
- cmSystemTools::ReplaceString(result, "\\${CMAKE_IMPORT_LIBRARY_SUFFIX}",
- "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
- return result;
- }
- cmExportFileGenerator::cmExportFileGenerator()
- {
- this->AppendMode = false;
- this->ExportOld = false;
- }
- void cmExportFileGenerator::AddConfiguration(const std::string& config)
- {
- this->Configurations.push_back(config);
- }
- void cmExportFileGenerator::SetExportFile(const char* mainFile)
- {
- this->MainImportFile = mainFile;
- this->FileDir = cmSystemTools::GetFilenamePath(this->MainImportFile);
- this->FileBase =
- cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile);
- this->FileExt =
- cmSystemTools::GetFilenameLastExtension(this->MainImportFile);
- }
- const std::string& cmExportFileGenerator::GetMainExportFileName() const
- {
- return this->MainImportFile;
- }
- bool cmExportFileGenerator::GenerateImportFile()
- {
- // Open the output file to generate it.
- std::unique_ptr<cmsys::ofstream> foutPtr;
- if (this->AppendMode) {
- // Open for append.
- auto openmodeApp = std::ios::app;
- foutPtr = cm::make_unique<cmsys::ofstream>(this->MainImportFile.c_str(),
- openmodeApp);
- } else {
- // Generate atomically and with copy-if-different.
- std::unique_ptr<cmGeneratedFileStream> ap(
- new cmGeneratedFileStream(this->MainImportFile, true));
- ap->SetCopyIfDifferent(true);
- foutPtr = std::move(ap);
- }
- if (!foutPtr || !*foutPtr) {
- std::string se = cmSystemTools::GetLastSystemError();
- std::ostringstream e;
- e << "cannot write to file \"" << this->MainImportFile << "\": " << se;
- cmSystemTools::Error(e.str());
- return false;
- }
- std::ostream& os = *foutPtr;
- // Start with the import file header.
- this->GeneratePolicyHeaderCode(os);
- this->GenerateImportHeaderCode(os);
- // Create all the imported targets.
- bool result = this->GenerateMainFile(os);
- // End with the import file footer.
- this->GenerateImportFooterCode(os);
- this->GeneratePolicyFooterCode(os);
- return result;
- }
- void cmExportFileGenerator::GenerateImportConfig(
- std::ostream& os, const std::string& config,
- std::vector<std::string>& missingTargets)
- {
- // Construct the property configuration suffix.
- std::string suffix = "_";
- if (!config.empty()) {
- suffix += cmSystemTools::UpperCase(config);
- } else {
- suffix += "NOCONFIG";
- }
- // Generate the per-config target information.
- this->GenerateImportTargetsConfig(os, config, suffix, missingTargets);
- }
- void cmExportFileGenerator::PopulateInterfaceProperty(
- const std::string& propName, cmGeneratorTarget const* target,
- ImportPropertyMap& properties)
- {
- cmValue input = target->GetProperty(propName);
- if (input) {
- properties[propName] = *input;
- }
- }
- void cmExportFileGenerator::PopulateInterfaceProperty(
- const std::string& propName, const std::string& outputName,
- cmGeneratorTarget const* target,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
- {
- cmValue input = target->GetProperty(propName);
- if (input) {
- if (input->empty()) {
- // Set to empty
- properties[outputName].clear();
- return;
- }
- std::string prepro =
- cmGeneratorExpression::Preprocess(*input, preprocessRule);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(prepro, target,
- missingTargets);
- properties[outputName] = prepro;
- }
- }
- }
- void cmExportFileGenerator::GenerateRequiredCMakeVersion(
- std::ostream& os, const char* versionString)
- {
- /* clang-format off */
- os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
- " message(FATAL_ERROR \"This file relies on consumers using "
- "CMake " << versionString << " or greater.\")\n"
- "endif()\n\n";
- /* clang-format on */
- }
- bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
- cmGeneratorTarget const* target,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
- {
- if (!target->IsLinkable()) {
- return false;
- }
- static const std::array<std::string, 3> linkIfaceProps = {
- { "INTERFACE_LINK_LIBRARIES", "INTERFACE_LINK_LIBRARIES_DIRECT",
- "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE" }
- };
- bool hadINTERFACE_LINK_LIBRARIES = false;
- for (std::string const& linkIfaceProp : linkIfaceProps) {
- if (cmValue input = target->GetProperty(linkIfaceProp)) {
- std::string prepro =
- cmGeneratorExpression::Preprocess(*input, preprocessRule);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(
- prepro, target, missingTargets, ReplaceFreeTargets);
- properties[linkIfaceProp] = prepro;
- hadINTERFACE_LINK_LIBRARIES = true;
- }
- }
- }
- return hadINTERFACE_LINK_LIBRARIES;
- }
- static bool isSubDirectory(std::string const& a, std::string const& b)
- {
- return (cmSystemTools::ComparePath(a, b) ||
- cmSystemTools::IsSubDirectory(a, b));
- }
- static bool checkInterfaceDirs(const std::string& prepro,
- cmGeneratorTarget const* target,
- const std::string& prop)
- {
- std::string const& installDir =
- target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
- std::string const& topSourceDir =
- target->GetLocalGenerator()->GetSourceDirectory();
- std::string const& topBinaryDir =
- target->GetLocalGenerator()->GetBinaryDirectory();
- std::vector<std::string> parts;
- cmGeneratorExpression::Split(prepro, parts);
- const bool inSourceBuild = topSourceDir == topBinaryDir;
- bool hadFatalError = false;
- for (std::string const& li : parts) {
- size_t genexPos = cmGeneratorExpression::Find(li);
- if (genexPos == 0) {
- continue;
- }
- if (cmHasLiteralPrefix(li, "${_IMPORT_PREFIX}")) {
- continue;
- }
- MessageType messageType = MessageType::FATAL_ERROR;
- std::ostringstream e;
- if (genexPos != std::string::npos) {
- if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
- switch (target->GetPolicyStatusCMP0041()) {
- case cmPolicies::WARN:
- messageType = MessageType::WARNING;
- e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n";
- break;
- case cmPolicies::OLD:
- continue;
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::REQUIRED_ALWAYS:
- case cmPolicies::NEW:
- hadFatalError = true;
- break; // Issue fatal message.
- }
- } else {
- hadFatalError = true;
- }
- }
- if (!cmSystemTools::FileIsFullPath(li)) {
- /* clang-format off */
- e << "Target \"" << target->GetName() << "\" " << prop <<
- " property contains relative path:\n"
- " \"" << li << "\"";
- /* clang-format on */
- target->GetLocalGenerator()->IssueMessage(messageType, e.str());
- }
- bool inBinary = isSubDirectory(li, topBinaryDir);
- bool inSource = isSubDirectory(li, topSourceDir);
- if (isSubDirectory(li, installDir)) {
- // The include directory is inside the install tree. If the
- // install tree is not inside the source tree or build tree then
- // fall through to the checks below that the include directory is not
- // also inside the source tree or build tree.
- bool shouldContinue =
- (!inBinary || isSubDirectory(installDir, topBinaryDir)) &&
- (!inSource || isSubDirectory(installDir, topSourceDir));
- if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
- if (!shouldContinue) {
- switch (target->GetPolicyStatusCMP0052()) {
- case cmPolicies::WARN: {
- std::ostringstream s;
- s << cmPolicies::GetPolicyWarning(cmPolicies::CMP0052) << "\n";
- s << "Directory:\n \"" << li
- << "\"\nin "
- "INTERFACE_INCLUDE_DIRECTORIES of target \""
- << target->GetName()
- << "\" is a subdirectory of the install "
- "directory:\n \""
- << installDir
- << "\"\nhowever it is also "
- "a subdirectory of the "
- << (inBinary ? "build" : "source") << " tree:\n \""
- << (inBinary ? topBinaryDir : topSourceDir) << "\"\n";
- target->GetLocalGenerator()->IssueMessage(
- MessageType::AUTHOR_WARNING, s.str());
- CM_FALLTHROUGH;
- }
- case cmPolicies::OLD:
- shouldContinue = true;
- break;
- case cmPolicies::REQUIRED_ALWAYS:
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::NEW:
- break;
- }
- }
- }
- if (shouldContinue) {
- continue;
- }
- }
- if (inBinary) {
- /* clang-format off */
- e << "Target \"" << target->GetName() << "\" " << prop <<
- " property contains path:\n"
- " \"" << li << "\"\nwhich is prefixed in the build directory.";
- /* clang-format on */
- target->GetLocalGenerator()->IssueMessage(messageType, e.str());
- }
- if (!inSourceBuild) {
- if (inSource) {
- e << "Target \"" << target->GetName() << "\" " << prop
- << " property contains path:\n"
- " \""
- << li << "\"\nwhich is prefixed in the source directory.";
- target->GetLocalGenerator()->IssueMessage(messageType, e.str());
- }
- }
- }
- return !hadFatalError;
- }
- static void prefixItems(std::string& exportDirs)
- {
- std::vector<std::string> entries;
- cmGeneratorExpression::Split(exportDirs, entries);
- exportDirs.clear();
- const char* sep = "";
- for (std::string const& e : entries) {
- exportDirs += sep;
- sep = ";";
- if (!cmSystemTools::FileIsFullPath(e) &&
- e.find("${_IMPORT_PREFIX}") == std::string::npos) {
- exportDirs += "${_IMPORT_PREFIX}/";
- }
- exportDirs += e;
- }
- }
- void cmExportFileGenerator::PopulateSourcesInterface(
- cmGeneratorTarget const* gt,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
- {
- assert(preprocessRule == cmGeneratorExpression::InstallInterface);
- const char* propName = "INTERFACE_SOURCES";
- cmValue input = gt->GetProperty(propName);
- if (!input) {
- return;
- }
- if (input->empty()) {
- properties[propName].clear();
- return;
- }
- std::string prepro =
- cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
- if (!checkInterfaceDirs(prepro, gt, propName)) {
- return;
- }
- properties[propName] = prepro;
- }
- }
- void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
- cmGeneratorTarget const* target,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets,
- cmTargetExport const& te)
- {
- assert(preprocessRule == cmGeneratorExpression::InstallInterface);
- const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
- cmValue input = target->GetProperty(propName);
- cmGeneratorExpression ge;
- std::string dirs = cmGeneratorExpression::Preprocess(
- cmJoin(target->Target->GetInstallIncludeDirectoriesEntries(te), ";"),
- preprocessRule, true);
- this->ReplaceInstallPrefix(dirs);
- std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
- std::string exportDirs =
- cge->Evaluate(target->GetLocalGenerator(), "", target);
- if (cge->GetHadContextSensitiveCondition()) {
- cmLocalGenerator* lg = target->GetLocalGenerator();
- std::ostringstream e;
- e << "Target \"" << target->GetName()
- << "\" is installed with "
- "INCLUDES DESTINATION set to a context sensitive path. Paths which "
- "depend on the configuration, policy values or the link interface "
- "are "
- "not supported. Consider using target_include_directories instead.";
- lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
- return;
- }
- if (!input && exportDirs.empty()) {
- return;
- }
- if ((input && input->empty()) && exportDirs.empty()) {
- // Set to empty
- properties[propName].clear();
- return;
- }
- prefixItems(exportDirs);
- std::string includes = (input ? *input : "");
- const char* sep = input ? ";" : "";
- includes += sep + exportDirs;
- std::string prepro =
- cmGeneratorExpression::Preprocess(includes, preprocessRule, true);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets);
- if (!checkInterfaceDirs(prepro, target, propName)) {
- return;
- }
- properties[propName] = prepro;
- }
- }
- void cmExportFileGenerator::PopulateLinkDependsInterface(
- cmGeneratorTarget const* gt,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
- {
- assert(preprocessRule == cmGeneratorExpression::InstallInterface);
- const char* propName = "INTERFACE_LINK_DEPENDS";
- cmValue input = gt->GetProperty(propName);
- if (!input) {
- return;
- }
- if (input->empty()) {
- properties[propName].clear();
- return;
- }
- std::string prepro =
- cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
- if (!checkInterfaceDirs(prepro, gt, propName)) {
- return;
- }
- properties[propName] = prepro;
- }
- }
- void cmExportFileGenerator::PopulateLinkDirectoriesInterface(
- cmGeneratorTarget const* gt,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
- {
- assert(preprocessRule == cmGeneratorExpression::InstallInterface);
- const char* propName = "INTERFACE_LINK_DIRECTORIES";
- cmValue input = gt->GetProperty(propName);
- if (!input) {
- return;
- }
- if (input->empty()) {
- properties[propName].clear();
- return;
- }
- std::string prepro =
- cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
- if (!checkInterfaceDirs(prepro, gt, propName)) {
- return;
- }
- properties[propName] = prepro;
- }
- }
- void cmExportFileGenerator::PopulateInterfaceProperty(
- const std::string& propName, cmGeneratorTarget const* target,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
- {
- this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
- properties, missingTargets);
- }
- static void getPropertyContents(cmGeneratorTarget const* tgt,
- const std::string& prop,
- std::set<std::string>& ifaceProperties)
- {
- cmValue p = tgt->GetProperty(prop);
- if (!p) {
- return;
- }
- std::vector<std::string> content = cmExpandedList(*p);
- ifaceProperties.insert(content.begin(), content.end());
- }
- static void getCompatibleInterfaceProperties(
- cmGeneratorTarget const* target, std::set<std::string>& ifaceProperties,
- const std::string& config)
- {
- if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- // object libraries have no link information, so nothing to compute
- return;
- }
- cmComputeLinkInformation* info = target->GetLinkInformation(config);
- if (!info) {
- cmLocalGenerator* lg = target->GetLocalGenerator();
- std::ostringstream e;
- e << "Exporting the target \"" << target->GetName()
- << "\" is not "
- "allowed since its linker language cannot be determined";
- lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
- return;
- }
- const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
- for (auto const& dep : deps) {
- if (!dep.Target) {
- continue;
- }
- getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_BOOL",
- ifaceProperties);
- getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_STRING",
- ifaceProperties);
- getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
- ifaceProperties);
- getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
- ifaceProperties);
- }
- }
- void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
- cmGeneratorTarget const* gtarget, ImportPropertyMap& properties)
- {
- this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL", gtarget,
- properties);
- this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING", gtarget,
- properties);
- this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN", gtarget,
- properties);
- this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX", gtarget,
- properties);
- std::set<std::string> ifaceProperties;
- getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
- getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
- getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MIN",
- ifaceProperties);
- getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MAX",
- ifaceProperties);
- if (gtarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
- std::vector<std::string> configNames =
- gtarget->Target->GetMakefile()->GetGeneratorConfigs(
- cmMakefile::IncludeEmptyConfig);
- for (std::string const& cn : configNames) {
- getCompatibleInterfaceProperties(gtarget, ifaceProperties, cn);
- }
- }
- for (std::string const& ip : ifaceProperties) {
- this->PopulateInterfaceProperty("INTERFACE_" + ip, gtarget, properties);
- }
- }
- void cmExportFileGenerator::GenerateInterfaceProperties(
- const cmGeneratorTarget* target, std::ostream& os,
- const ImportPropertyMap& properties)
- {
- if (!properties.empty()) {
- std::string targetName =
- cmStrCat(this->Namespace, target->GetExportName());
- os << "set_target_properties(" << targetName << " PROPERTIES\n";
- for (auto const& property : properties) {
- os << " " << property.first << " "
- << cmExportFileGeneratorEscape(property.second) << "\n";
- }
- os << ")\n\n";
- }
- }
- bool cmExportFileGenerator::AddTargetNamespace(
- std::string& input, cmGeneratorTarget const* target,
- cmLocalGenerator const* lg, std::vector<std::string>& missingTargets)
- {
- cmGeneratorTarget::TargetOrString resolved =
- target->ResolveTargetReference(input, lg);
- cmGeneratorTarget* tgt = resolved.Target;
- if (!tgt) {
- input = resolved.String;
- return false;
- }
- if (tgt->IsImported()) {
- input = tgt->GetName();
- return true;
- }
- if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) {
- input = this->Namespace + tgt->GetExportName();
- } else {
- std::string namespacedTarget;
- this->HandleMissingTarget(namespacedTarget, missingTargets, target, tgt);
- if (!namespacedTarget.empty()) {
- input = namespacedTarget;
- } else {
- input = tgt->GetName();
- }
- }
- return true;
- }
- void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
- std::string& input, cmGeneratorTarget const* target,
- std::vector<std::string>& missingTargets, FreeTargetsReplace replace)
- {
- cmLocalGenerator const* lg = target->GetLocalGenerator();
- if (replace == NoReplaceFreeTargets) {
- this->ResolveTargetsInGeneratorExpression(input, target, lg,
- missingTargets);
- return;
- }
- std::vector<std::string> parts;
- cmGeneratorExpression::Split(input, parts);
- std::string sep;
- input.clear();
- for (std::string& li : parts) {
- if (target->IsLinkLookupScope(li, lg)) {
- continue;
- }
- if (cmGeneratorExpression::Find(li) == std::string::npos) {
- this->AddTargetNamespace(li, target, lg, missingTargets);
- } else {
- this->ResolveTargetsInGeneratorExpression(li, target, lg,
- missingTargets);
- }
- input += sep + li;
- sep = ";";
- }
- }
- void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
- std::string& input, cmGeneratorTarget const* target,
- cmLocalGenerator const* lg, std::vector<std::string>& missingTargets)
- {
- std::string::size_type pos = 0;
- std::string::size_type lastPos = pos;
- while ((pos = input.find("$<TARGET_PROPERTY:", lastPos)) !=
- std::string::npos) {
- std::string::size_type nameStartPos =
- pos + sizeof("$<TARGET_PROPERTY:") - 1;
- std::string::size_type closePos = input.find('>', nameStartPos);
- std::string::size_type commaPos = input.find(',', nameStartPos);
- std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
- if (commaPos == std::string::npos // Implied 'this' target
- || closePos == std::string::npos // Incomplete expression.
- || closePos < commaPos // Implied 'this' target
- || nextOpenPos < commaPos) // Non-literal
- {
- lastPos = nameStartPos;
- continue;
- }
- std::string targetName =
- input.substr(nameStartPos, commaPos - nameStartPos);
- if (this->AddTargetNamespace(targetName, target, lg, missingTargets)) {
- input.replace(nameStartPos, commaPos - nameStartPos, targetName);
- }
- lastPos = nameStartPos + targetName.size() + 1;
- }
- std::string errorString;
- pos = 0;
- lastPos = pos;
- while ((pos = input.find("$<TARGET_NAME:", lastPos)) != std::string::npos) {
- std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
- std::string::size_type endPos = input.find('>', nameStartPos);
- if (endPos == std::string::npos) {
- errorString = "$<TARGET_NAME:...> expression incomplete";
- break;
- }
- std::string targetName = input.substr(nameStartPos, endPos - nameStartPos);
- if (targetName.find("$<") != std::string::npos) {
- errorString = "$<TARGET_NAME:...> requires its parameter to be a "
- "literal.";
- break;
- }
- if (!this->AddTargetNamespace(targetName, target, lg, missingTargets)) {
- errorString = "$<TARGET_NAME:...> requires its parameter to be a "
- "reachable target.";
- break;
- }
- input.replace(pos, endPos - pos + 1, targetName);
- lastPos = pos + targetName.size();
- }
- pos = 0;
- lastPos = pos;
- while (errorString.empty() &&
- (pos = input.find("$<LINK_ONLY:", lastPos)) != std::string::npos) {
- std::string::size_type nameStartPos = pos + sizeof("$<LINK_ONLY:") - 1;
- std::string::size_type endPos = input.find('>', nameStartPos);
- if (endPos == std::string::npos) {
- errorString = "$<LINK_ONLY:...> expression incomplete";
- break;
- }
- std::string libName = input.substr(nameStartPos, endPos - nameStartPos);
- if (cmGeneratorExpression::IsValidTargetName(libName) &&
- this->AddTargetNamespace(libName, target, lg, missingTargets)) {
- input.replace(nameStartPos, endPos - nameStartPos, libName);
- }
- lastPos = nameStartPos + libName.size() + 1;
- }
- this->ReplaceInstallPrefix(input);
- if (!errorString.empty()) {
- target->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
- errorString);
- }
- }
- void cmExportFileGenerator::ReplaceInstallPrefix(std::string& /*unused*/)
- {
- // Do nothing
- }
- void cmExportFileGenerator::SetImportLinkInterface(
- const std::string& config, std::string const& suffix,
- cmGeneratorExpression::PreprocessContext preprocessRule,
- cmGeneratorTarget const* target, ImportPropertyMap& properties,
- std::vector<std::string>& missingTargets)
- {
- // Add the transitive link dependencies for this configuration.
- cmLinkInterface const* iface = target->GetLinkInterface(config, target);
- if (!iface) {
- return;
- }
- if (iface->ImplementationIsInterface) {
- // Policy CMP0022 must not be NEW.
- this->SetImportLinkProperty(
- suffix, target, "IMPORTED_LINK_INTERFACE_LIBRARIES", iface->Libraries,
- properties, missingTargets, ImportLinkPropertyTargetNames::Yes);
- return;
- }
- cmValue propContent;
- if (cmValue prop_suffixed =
- target->GetProperty("LINK_INTERFACE_LIBRARIES" + suffix)) {
- propContent = prop_suffixed;
- } else if (cmValue prop = target->GetProperty("LINK_INTERFACE_LIBRARIES")) {
- propContent = prop;
- } else {
- return;
- }
- const bool newCMP0022Behavior =
- target->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
- target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
- if (newCMP0022Behavior && !this->ExportOld) {
- cmLocalGenerator* lg = target->GetLocalGenerator();
- std::ostringstream e;
- e << "Target \"" << target->GetName()
- << "\" has policy CMP0022 enabled, "
- "but also has old-style LINK_INTERFACE_LIBRARIES properties "
- "populated, but it was exported without the "
- "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
- lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
- return;
- }
- if (propContent->empty()) {
- properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix].clear();
- return;
- }
- std::string prepro =
- cmGeneratorExpression::Preprocess(*propContent, preprocessRule);
- if (!prepro.empty()) {
- this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets,
- ReplaceFreeTargets);
- properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
- }
- }
- void cmExportFileGenerator::SetImportDetailProperties(
- const std::string& config, std::string const& suffix,
- cmGeneratorTarget* target, ImportPropertyMap& properties,
- std::vector<std::string>& missingTargets)
- {
- // Get the makefile in which to lookup target information.
- cmMakefile* mf = target->Makefile;
- // Add the soname for unix shared libraries.
- if (target->GetType() == cmStateEnums::SHARED_LIBRARY ||
- target->GetType() == cmStateEnums::MODULE_LIBRARY) {
- if (!target->IsDLLPlatform()) {
- std::string prop;
- std::string value;
- if (target->HasSOName(config)) {
- if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
- value = this->InstallNameDir(target, config);
- }
- prop = "IMPORTED_SONAME";
- value += target->GetSOName(config);
- } else {
- prop = "IMPORTED_NO_SONAME";
- value = "TRUE";
- }
- prop += suffix;
- properties[prop] = value;
- }
- }
- // Add the transitive link dependencies for this configuration.
- if (cmLinkInterface const* iface =
- target->GetLinkInterface(config, target)) {
- this->SetImportLinkProperty(
- suffix, target, "IMPORTED_LINK_INTERFACE_LANGUAGES", iface->Languages,
- properties, missingTargets, ImportLinkPropertyTargetNames::No);
- std::vector<std::string> dummy;
- this->SetImportLinkProperty(
- suffix, target, "IMPORTED_LINK_DEPENDENT_LIBRARIES", iface->SharedDeps,
- properties, dummy, ImportLinkPropertyTargetNames::Yes);
- if (iface->Multiplicity > 0) {
- std::string prop =
- cmStrCat("IMPORTED_LINK_INTERFACE_MULTIPLICITY", suffix);
- properties[prop] = std::to_string(iface->Multiplicity);
- }
- }
- // Add information if this target is a managed target
- if (target->GetManagedType(config) !=
- cmGeneratorTarget::ManagedType::Native) {
- std::string prop = cmStrCat("IMPORTED_COMMON_LANGUAGE_RUNTIME", suffix);
- std::string propval;
- if (cmValue p = target->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
- propval = *p;
- } else if (target->IsCSharpOnly()) {
- // C# projects do not have the /clr flag, so we set the property
- // here to mark the target as (only) managed (i.e. no .lib file
- // to link to). Otherwise the COMMON_LANGUAGE_RUNTIME target
- // property would have to be set manually for C# targets to make
- // exporting/importing work.
- propval = "CSharp";
- }
- properties[prop] = propval;
- }
- }
- static std::string const& asString(std::string const& l)
- {
- return l;
- }
- static std::string const& asString(cmLinkItem const& l)
- {
- return l.AsStr();
- }
- template <typename T>
- void cmExportFileGenerator::SetImportLinkProperty(
- std::string const& suffix, cmGeneratorTarget const* target,
- const std::string& propName, std::vector<T> const& entries,
- ImportPropertyMap& properties, std::vector<std::string>& missingTargets,
- ImportLinkPropertyTargetNames targetNames)
- {
- // Skip the property if there are no entries.
- if (entries.empty()) {
- return;
- }
- cmLocalGenerator const* lg = target->GetLocalGenerator();
- // Construct the property value.
- std::string link_entries;
- const char* sep = "";
- for (T const& l : entries) {
- // Separate this from the previous entry.
- link_entries += sep;
- sep = ";";
- if (targetNames == ImportLinkPropertyTargetNames::Yes) {
- std::string temp = asString(l);
- this->AddTargetNamespace(temp, target, lg, missingTargets);
- link_entries += temp;
- } else {
- link_entries += asString(l);
- }
- }
- // Store the property.
- std::string prop = cmStrCat(propName, suffix);
- properties[prop] = link_entries;
- }
- void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
- {
- // Protect that file against use with older CMake versions.
- /* clang-format off */
- os << "# Generated by CMake\n\n";
- os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.6)\n"
- << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
- << "endif()\n";
- /* clang-format on */
- // Isolate the file policy level.
- // Support CMake versions as far back as 2.6 but also support using NEW
- // policy settings for up to CMake 3.22 (this upper limit may be reviewed
- // and increased from time to time). This reduces the opportunity for CMake
- // warnings when an older export file is later used with newer CMake
- // versions.
- /* clang-format off */
- os << "cmake_policy(PUSH)\n"
- << "cmake_policy(VERSION 2.6...3.22)\n";
- /* clang-format on */
- }
- void cmExportFileGenerator::GeneratePolicyFooterCode(std::ostream& os)
- {
- os << "cmake_policy(POP)\n";
- }
- void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
- const std::string& config)
- {
- os << "#----------------------------------------------------------------\n"
- << "# Generated CMake target import file";
- if (!config.empty()) {
- os << " for configuration \"" << config << "\".\n";
- } else {
- os << ".\n";
- }
- os << "#----------------------------------------------------------------\n"
- << "\n";
- this->GenerateImportVersionCode(os);
- }
- void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
- {
- os << "# Commands beyond this point should not need to know the version.\n"
- << "set(CMAKE_IMPORT_FILE_VERSION)\n";
- }
- void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
- {
- // Store an import file format version. This will let us change the
- // format later while still allowing old import files to work.
- /* clang-format off */
- os << "# Commands may need to know the format version.\n"
- << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
- << "\n";
- /* clang-format on */
- }
- void cmExportFileGenerator::GenerateExpectedTargetsCode(
- std::ostream& os, const std::string& expectedTargets)
- {
- /* clang-format off */
- os << "# Protect against multiple inclusion, which would fail when already "
- "imported targets are added once more.\n"
- "set(_targetsDefined)\n"
- "set(_targetsNotDefined)\n"
- "set(_expectedTargets)\n"
- "foreach(_expectedTarget " << expectedTargets << ")\n"
- " list(APPEND _expectedTargets ${_expectedTarget})\n"
- " if(NOT TARGET ${_expectedTarget})\n"
- " list(APPEND _targetsNotDefined ${_expectedTarget})\n"
- " endif()\n"
- " if(TARGET ${_expectedTarget})\n"
- " list(APPEND _targetsDefined ${_expectedTarget})\n"
- " endif()\n"
- "endforeach()\n"
- "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
- " unset(_targetsDefined)\n"
- " unset(_targetsNotDefined)\n"
- " unset(_expectedTargets)\n"
- " set(CMAKE_IMPORT_FILE_VERSION)\n"
- " cmake_policy(POP)\n"
- " return()\n"
- "endif()\n"
- "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
- " message(FATAL_ERROR \"Some (but not all) targets in this export "
- "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
- "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
- "endif()\n"
- "unset(_targetsDefined)\n"
- "unset(_targetsNotDefined)\n"
- "unset(_expectedTargets)\n"
- "\n\n";
- /* clang-format on */
- }
- void cmExportFileGenerator::GenerateImportTargetCode(
- std::ostream& os, cmGeneratorTarget const* target,
- cmStateEnums::TargetType targetType)
- {
- // Construct the imported target name.
- std::string targetName = this->Namespace;
- targetName += target->GetExportName();
- // Create the imported target.
- os << "# Create imported target " << targetName << "\n";
- switch (targetType) {
- case cmStateEnums::EXECUTABLE:
- os << "add_executable(" << targetName << " IMPORTED)\n";
- break;
- case cmStateEnums::STATIC_LIBRARY:
- os << "add_library(" << targetName << " STATIC IMPORTED)\n";
- break;
- case cmStateEnums::SHARED_LIBRARY:
- os << "add_library(" << targetName << " SHARED IMPORTED)\n";
- break;
- case cmStateEnums::MODULE_LIBRARY:
- os << "add_library(" << targetName << " MODULE IMPORTED)\n";
- break;
- case cmStateEnums::UNKNOWN_LIBRARY:
- os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
- break;
- case cmStateEnums::OBJECT_LIBRARY:
- os << "add_library(" << targetName << " OBJECT IMPORTED)\n";
- break;
- case cmStateEnums::INTERFACE_LIBRARY:
- os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
- break;
- default: // should never happen
- break;
- }
- // Mark the imported executable if it has exports.
- if (target->IsExecutableWithExports()) {
- os << "set_property(TARGET " << targetName
- << " PROPERTY ENABLE_EXPORTS 1)\n";
- }
- // Mark the imported library if it is a framework.
- if (target->IsFrameworkOnApple()) {
- os << "set_property(TARGET " << targetName << " PROPERTY FRAMEWORK 1)\n";
- }
- // Mark the imported executable if it is an application bundle.
- if (target->IsAppBundleOnApple()) {
- os << "set_property(TARGET " << targetName
- << " PROPERTY MACOSX_BUNDLE 1)\n";
- }
- if (target->IsCFBundleOnApple()) {
- os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n";
- }
- // generate DEPRECATION
- if (target->IsDeprecated()) {
- os << "set_property(TARGET " << targetName << " PROPERTY DEPRECATION "
- << cmExportFileGeneratorEscape(target->GetDeprecation()) << ")\n";
- }
- if (target->GetPropertyAsBool("IMPORTED_NO_SYSTEM")) {
- os << "set_property(TARGET " << targetName
- << " PROPERTY IMPORTED_NO_SYSTEM 1)\n";
- }
- os << "\n";
- }
- void cmExportFileGenerator::GenerateImportPropertyCode(
- std::ostream& os, const std::string& config, cmGeneratorTarget const* target,
- ImportPropertyMap const& properties)
- {
- // Construct the imported target name.
- std::string targetName = this->Namespace;
- targetName += target->GetExportName();
- // Set the import properties.
- os << "# Import target \"" << targetName << "\" for configuration \""
- << config << "\"\n";
- os << "set_property(TARGET " << targetName
- << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
- if (!config.empty()) {
- os << cmSystemTools::UpperCase(config);
- } else {
- os << "NOCONFIG";
- }
- os << ")\n";
- os << "set_target_properties(" << targetName << " PROPERTIES\n";
- for (auto const& property : properties) {
- os << " " << property.first << " "
- << cmExportFileGeneratorEscape(property.second) << "\n";
- }
- os << " )\n"
- << "\n";
- }
- void cmExportFileGenerator::GenerateMissingTargetsCheckCode(
- std::ostream& os, const std::vector<std::string>& missingTargets)
- {
- if (missingTargets.empty()) {
- /* clang-format off */
- os << "# This file does not depend on other imported targets which have\n"
- "# been exported from the same project but in a separate "
- "export set.\n\n";
- /* clang-format on */
- return;
- }
- /* clang-format off */
- os << "# Make sure the targets which have been exported in some other\n"
- "# export set exist.\n"
- "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
- "foreach(_target ";
- /* clang-format on */
- std::set<std::string> emitted;
- for (std::string const& missingTarget : missingTargets) {
- if (emitted.insert(missingTarget).second) {
- os << "\"" << missingTarget << "\" ";
- }
- }
- /* clang-format off */
- os << ")\n"
- " if(NOT TARGET \"${_target}\" )\n"
- " set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
- "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
- "\n"
- " endif()\n"
- "endforeach()\n"
- "\n"
- "if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
- " if(CMAKE_FIND_PACKAGE_NAME)\n"
- " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
- " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
- "\"The following imported targets are "
- "referenced, but are missing: "
- "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
- " else()\n"
- " message(FATAL_ERROR \"The following imported targets are "
- "referenced, but are missing: "
- "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
- " endif()\n"
- "endif()\n"
- "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
- "\n";
- /* clang-format on */
- }
- void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
- {
- // Add code which verifies at cmake time that the file which is being
- // imported actually exists on disk. This should in theory always be theory
- // case, but still when packages are split into normal and development
- // packages this might get broken (e.g. the Config.cmake could be part of
- // the non-development package, something similar happened to me without
- // on SUSE with a mysql pkg-config file, which claimed everything is fine,
- // but the development package was not installed.).
- /* clang-format off */
- os << "# Loop over all imported files and verify that they actually exist\n"
- "foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
- " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
- " if(NOT EXISTS \"${file}\" )\n"
- " message(FATAL_ERROR \"The imported target \\\"${target}\\\""
- " references the file\n"
- " \\\"${file}\\\"\n"
- "but this file does not exist. Possible reasons include:\n"
- "* The file was deleted, renamed, or moved to another location.\n"
- "* An install or uninstall procedure did not complete successfully.\n"
- "* The installation package was faulty and contained\n"
- " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
- "but not all the files it references.\n"
- "\")\n"
- " endif()\n"
- " endforeach()\n"
- " unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
- "endforeach()\n"
- "unset(_IMPORT_CHECK_TARGETS)\n"
- "\n";
- /* clang-format on */
- }
- void cmExportFileGenerator::GenerateImportedFileChecksCode(
- std::ostream& os, cmGeneratorTarget* target,
- ImportPropertyMap const& properties,
- const std::set<std::string>& importedLocations)
- {
- // Construct the imported target name.
- std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
- os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName
- << " )\n"
- "list(APPEND _IMPORT_CHECK_FILES_FOR_"
- << targetName << " ";
- for (std::string const& li : importedLocations) {
- auto pi = properties.find(li);
- if (pi != properties.end()) {
- os << cmExportFileGeneratorEscape(pi->second) << " ";
- }
- }
- os << ")\n\n";
- }
- bool cmExportFileGenerator::PopulateExportProperties(
- cmGeneratorTarget const* gte, ImportPropertyMap& properties,
- std::string& errorMessage)
- {
- const auto& targetProperties = gte->Target->GetProperties();
- if (cmValue exportProperties =
- targetProperties.GetPropertyValue("EXPORT_PROPERTIES")) {
- for (auto& prop : cmExpandedList(*exportProperties)) {
- /* Black list reserved properties */
- if (cmHasLiteralPrefix(prop, "IMPORTED_") ||
- cmHasLiteralPrefix(prop, "INTERFACE_")) {
- std::ostringstream e;
- e << "Target \"" << gte->Target->GetName() << "\" contains property \""
- << prop << "\" in EXPORT_PROPERTIES but IMPORTED_* and INTERFACE_* "
- << "properties are reserved.";
- errorMessage = e.str();
- return false;
- }
- cmValue propertyValue = targetProperties.GetPropertyValue(prop);
- if (!propertyValue) {
- // Asked to export a property that isn't defined on the target. Do not
- // consider this an error, there's just nothing to export.
- continue;
- }
- std::string evaluatedValue = cmGeneratorExpression::Preprocess(
- *propertyValue, cmGeneratorExpression::StripAllGeneratorExpressions);
- if (evaluatedValue != *propertyValue) {
- std::ostringstream e;
- e << "Target \"" << gte->Target->GetName() << "\" contains property \""
- << prop << "\" in EXPORT_PROPERTIES but this property contains a "
- << "generator expression. This is not allowed.";
- errorMessage = e.str();
- return false;
- }
- properties[prop] = *propertyValue;
- }
- }
- return true;
- }
- void cmExportFileGenerator::GenerateTargetFileSets(cmGeneratorTarget* gte,
- std::ostream& os,
- cmTargetExport* te)
- {
- auto interfaceFileSets = gte->Target->GetAllInterfaceFileSets();
- if (!interfaceFileSets.empty()) {
- std::string targetName = cmStrCat(this->Namespace, gte->GetExportName());
- os << "if(NOT CMAKE_VERSION VERSION_LESS \"3.23.0\")\n"
- " target_sources("
- << targetName << "\n";
- for (auto const& name : interfaceFileSets) {
- auto* fileSet = gte->Target->GetFileSet(name);
- if (!fileSet) {
- gte->Makefile->IssueMessage(
- MessageType::FATAL_ERROR,
- cmStrCat("File set \"", name,
- "\" is listed in interface file sets of ", gte->GetName(),
- " but has not been created"));
- return;
- }
- os << " INTERFACE"
- << "\n FILE_SET " << cmOutputConverter::EscapeForCMake(name)
- << "\n TYPE "
- << cmOutputConverter::EscapeForCMake(fileSet->GetType())
- << "\n BASE_DIRS "
- << this->GetFileSetDirectories(gte, fileSet, te) << "\n FILES "
- << this->GetFileSetFiles(gte, fileSet, te) << "\n";
- }
- os << " )\nendif()\n\n";
- }
- }
|