diff options
Diffstat (limited to 'Source/cmExportFileGenerator.cxx')
-rw-r--r-- | Source/cmExportFileGenerator.cxx | 907 |
1 files changed, 370 insertions, 537 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 5aa466d..2d645da 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -33,11 +33,9 @@ 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}", + cmSystemTools::ReplaceString(result, "\\${_IMPORT_PREFIX}", "${_IMPORT_PREFIX}"); - cmSystemTools::ReplaceString(result, - "\\${CMAKE_IMPORT_LIBRARY_SUFFIX}", + cmSystemTools::ReplaceString(result, "\\${CMAKE_IMPORT_LIBRARY_SUFFIX}", "${CMAKE_IMPORT_LIBRARY_SUFFIX}"); return result; } @@ -56,8 +54,7 @@ void cmExportFileGenerator::AddConfiguration(const std::string& config) void cmExportFileGenerator::SetExportFile(const char* mainFile) { this->MainImportFile = mainFile; - this->FileDir = - cmSystemTools::GetFilenamePath(this->MainImportFile); + this->FileDir = cmSystemTools::GetFilenamePath(this->MainImportFile); this->FileBase = cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile); this->FileExt = @@ -73,30 +70,25 @@ bool cmExportFileGenerator::GenerateImportFile() { // Open the output file to generate it. cmsys::auto_ptr<cmsys::ofstream> foutPtr; - if(this->AppendMode) - { + if (this->AppendMode) { // Open for append. - cmsys::auto_ptr<cmsys::ofstream> - ap(new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app)); + cmsys::auto_ptr<cmsys::ofstream> ap( + new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app)); foutPtr = ap; - } - else - { + } else { // Generate atomically and with copy-if-different. - cmsys::auto_ptr<cmGeneratedFileStream> - ap(new cmGeneratedFileStream(this->MainImportFile.c_str(), true)); + cmsys::auto_ptr<cmGeneratedFileStream> ap( + new cmGeneratedFileStream(this->MainImportFile.c_str(), true)); ap->SetCopyIfDifferent(true); foutPtr = ap; - } - if(!foutPtr.get() || !*foutPtr) - { + } + if (!foutPtr.get() || !*foutPtr) { std::string se = cmSystemTools::GetLastSystemError(); std::ostringstream e; - e << "cannot write to file \"" << this->MainImportFile - << "\": " << se; + e << "cannot write to file \"" << this->MainImportFile << "\": " << se; cmSystemTools::Error(e.str().c_str()); return false; - } + } std::ostream& os = *foutPtr; // Protect that file against use with older CMake versions. @@ -129,68 +121,58 @@ bool cmExportFileGenerator::GenerateImportFile() return result; } -void cmExportFileGenerator::GenerateImportConfig(std::ostream& os, - const std::string& config, - std::vector<std::string> &missingTargets) +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()) - { + if (!config.empty()) { suffix += cmSystemTools::UpperCase(config); - } - else - { + } else { suffix += "NOCONFIG"; - } + } // Generate the per-config target information. this->GenerateImportTargetsConfig(os, config, suffix, missingTargets); } void cmExportFileGenerator::PopulateInterfaceProperty( - const std::string& propName, - cmGeneratorTarget *target, - ImportPropertyMap &properties) + const std::string& propName, cmGeneratorTarget* target, + ImportPropertyMap& properties) { - const char *input = target->GetProperty(propName); - if (input) - { + const char* input = target->GetProperty(propName); + if (input) { properties[propName] = input; - } + } } void cmExportFileGenerator::PopulateInterfaceProperty( - const std::string& propName, - const std::string& outputName, - cmGeneratorTarget *target, - cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap &properties, - std::vector<std::string> &missingTargets) + const std::string& propName, const std::string& outputName, + cmGeneratorTarget* target, + cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector<std::string>& missingTargets) { - const char *input = target->GetProperty(propName); - if (input) - { - if (!*input) - { + const char* input = target->GetProperty(propName); + if (input) { + if (!*input) { // Set to empty properties[outputName] = ""; return; - } + } - std::string prepro = cmGeneratorExpression::Preprocess(input, - preprocessRule); - if (!prepro.empty()) - { + 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) +void cmExportFileGenerator::GenerateRequiredCMakeVersion( + std::ostream& os, const char* versionString) { /* clang-format off */ os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n" @@ -201,29 +183,24 @@ void cmExportFileGenerator::GenerateRequiredCMakeVersion(std::ostream& os, } bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty( - cmGeneratorTarget *target, - cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap &properties, - std::vector<std::string> &missingTargets) + cmGeneratorTarget* target, + cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector<std::string>& missingTargets) { - if(!target->IsLinkable()) - { + if (!target->IsLinkable()) { return false; - } - const char *input = target->GetProperty("INTERFACE_LINK_LIBRARIES"); - if (input) - { - std::string prepro = cmGeneratorExpression::Preprocess(input, - preprocessRule); - if (!prepro.empty()) - { - this->ResolveTargetsInGeneratorExpressions(prepro, target, - missingTargets, - ReplaceFreeTargets); + } + const char* input = target->GetProperty("INTERFACE_LINK_LIBRARIES"); + if (input) { + std::string prepro = + cmGeneratorExpression::Preprocess(input, preprocessRule); + if (!prepro.empty()) { + this->ResolveTargetsInGeneratorExpressions( + prepro, target, missingTargets, ReplaceFreeTargets); properties["INTERFACE_LINK_LIBRARIES"] = prepro; return true; - } } + } return false; } @@ -233,15 +210,14 @@ static bool isSubDirectory(const char* a, const char* b) cmSystemTools::IsSubDirectory(a, b)); } -static bool checkInterfaceDirs(const std::string &prepro, - cmGeneratorTarget *target, const std::string& prop) +static bool checkInterfaceDirs(const std::string& prepro, + cmGeneratorTarget* target, + const std::string& prop) { const char* installDir = - target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); - const char* topSourceDir = - target->GetLocalGenerator()->GetSourceDirectory(); - const char* topBinaryDir = - target->GetLocalGenerator()->GetBinaryDirectory(); + target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); + const char* topSourceDir = target->GetLocalGenerator()->GetSourceDirectory(); + const char* topBinaryDir = target->GetLocalGenerator()->GetBinaryDirectory(); std::vector<std::string> parts; cmGeneratorExpression::Split(prepro, parts); @@ -250,22 +226,17 @@ static bool checkInterfaceDirs(const std::string &prepro, bool hadFatalError = false; - for(std::vector<std::string>::iterator li = parts.begin(); - li != parts.end(); ++li) - { + for (std::vector<std::string>::iterator li = parts.begin(); + li != parts.end(); ++li) { size_t genexPos = cmGeneratorExpression::Find(*li); - if (genexPos == 0) - { + if (genexPos == 0) { continue; - } + } cmake::MessageType messageType = cmake::FATAL_ERROR; std::ostringstream e; - if (genexPos != std::string::npos) - { - if (prop == "INTERFACE_INCLUDE_DIRECTORIES") - { - switch (target->GetPolicyStatusCMP0041()) - { + if (genexPos != std::string::npos) { + if (prop == "INTERFACE_INCLUDE_DIRECTORIES") { + switch (target->GetPolicyStatusCMP0041()) { case cmPolicies::WARN: messageType = cmake::WARNING; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n"; @@ -277,30 +248,25 @@ static bool checkInterfaceDirs(const std::string &prepro, case cmPolicies::NEW: hadFatalError = true; break; // Issue fatal message. - } } - else - { + } else { hadFatalError = true; - } } - if (cmHasLiteralPrefix(li->c_str(), "${_IMPORT_PREFIX}")) - { + } + if (cmHasLiteralPrefix(li->c_str(), "${_IMPORT_PREFIX}")) { continue; - } - if (!cmSystemTools::FileIsFullPath(li->c_str())) - { + } + if (!cmSystemTools::FileIsFullPath(li->c_str())) { /* 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->c_str(), topBinaryDir); bool inSource = isSubDirectory(li->c_str(), topSourceDir); - if (isSubDirectory(li->c_str(), installDir)) - { + if (isSubDirectory(li->c_str(), 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 @@ -309,26 +275,25 @@ static bool checkInterfaceDirs(const std::string &prepro, (!inBinary || isSubDirectory(installDir, topBinaryDir)) && (!inSource || isSubDirectory(installDir, topSourceDir)); - if (prop == "INTERFACE_INCLUDE_DIRECTORIES") - { - if (!shouldContinue) - { - switch(target->GetPolicyStatusCMP0052()) - { - case cmPolicies::WARN: - { + 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 \"" + 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) - << "\"" << std::endl; + "directory:\n \"" + << installDir << "\"\nhowever it is also " + "a subdirectory of the " + << (inBinary ? "build" : "source") << " tree:\n \"" + << (inBinary ? topBinaryDir : topSourceDir) << "\"" + << std::endl; target->GetLocalGenerator()->IssueMessage(cmake::AUTHOR_WARNING, - s.str()); - } + s.str()); + } case cmPolicies::OLD: shouldContinue = true; break; @@ -336,242 +301,207 @@ static bool checkInterfaceDirs(const std::string &prepro, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: break; - } } } - if (shouldContinue) - { + } + if (shouldContinue) { continue; - } } - if (inBinary) - { + } + 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."; + } + 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) +static void prefixItems(std::string& exportDirs) { std::vector<std::string> entries; cmGeneratorExpression::Split(exportDirs, entries); exportDirs = ""; - const char *sep = ""; - for(std::vector<std::string>::const_iterator ei = entries.begin(); - ei != entries.end(); ++ei) - { + const char* sep = ""; + for (std::vector<std::string>::const_iterator ei = entries.begin(); + ei != entries.end(); ++ei) { exportDirs += sep; sep = ";"; - if (!cmSystemTools::FileIsFullPath(ei->c_str()) - && ei->find("${_IMPORT_PREFIX}") == std::string::npos) - { + if (!cmSystemTools::FileIsFullPath(ei->c_str()) && + ei->find("${_IMPORT_PREFIX}") == std::string::npos) { exportDirs += "${_IMPORT_PREFIX}/"; - } - exportDirs += *ei; } + exportDirs += *ei; + } } void cmExportFileGenerator::PopulateSourcesInterface( - cmTargetExport *tei, - cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap &properties, - std::vector<std::string> &missingTargets) + cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector<std::string>& missingTargets) { cmGeneratorTarget* gt = tei->Target; assert(preprocessRule == cmGeneratorExpression::InstallInterface); - const char *propName = "INTERFACE_SOURCES"; - const char *input = gt->GetProperty(propName); + const char* propName = "INTERFACE_SOURCES"; + const char* input = gt->GetProperty(propName); - if (!input) - { + if (!input) { return; - } + } - if (!*input) - { + if (!*input) { properties[propName] = ""; return; - } + } - std::string prepro = cmGeneratorExpression::Preprocess(input, - preprocessRule, - true); - if (!prepro.empty()) - { - this->ResolveTargetsInGeneratorExpressions(prepro, gt, - missingTargets); + std::string prepro = + cmGeneratorExpression::Preprocess(input, preprocessRule, true); + if (!prepro.empty()) { + this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets); - if (!checkInterfaceDirs(prepro, gt, propName)) - { + if (!checkInterfaceDirs(prepro, gt, propName)) { return; - } - properties[propName] = prepro; } + properties[propName] = prepro; + } } void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( - cmTargetExport *tei, - cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap &properties, - std::vector<std::string> &missingTargets) + cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector<std::string>& missingTargets) { - cmGeneratorTarget *target = tei->Target; + cmGeneratorTarget* target = tei->Target; assert(preprocessRule == cmGeneratorExpression::InstallInterface); - const char *propName = "INTERFACE_INCLUDE_DIRECTORIES"; - const char *input = target->GetProperty(propName); + const char* propName = "INTERFACE_INCLUDE_DIRECTORIES"; + const char* input = target->GetProperty(propName); cmGeneratorExpression ge; std::string dirs = cmGeneratorExpression::Preprocess( - tei->InterfaceIncludeDirectories, - preprocessRule, - true); + tei->InterfaceIncludeDirectories, preprocessRule, true); this->ReplaceInstallPrefix(dirs); cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs); - std::string exportDirs = cge->Evaluate(target->GetLocalGenerator(), "", - false, target); + std::string exportDirs = + cge->Evaluate(target->GetLocalGenerator(), "", false, target); - if (cge->GetHadContextSensitiveCondition()) - { + 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."; + 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(cmake::FATAL_ERROR, e.str()); return; - } + } - if (!input && exportDirs.empty()) - { + if (!input && exportDirs.empty()) { return; - } - if ((input && !*input) && exportDirs.empty()) - { + } + if ((input && !*input) && exportDirs.empty()) { // Set to empty properties[propName] = ""; return; - } + } prefixItems(exportDirs); - std::string includes = (input?input:""); + 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); + std::string prepro = + cmGeneratorExpression::Preprocess(includes, preprocessRule, true); + if (!prepro.empty()) { + this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets); - if (!checkInterfaceDirs(prepro, target, propName)) - { + if (!checkInterfaceDirs(prepro, target, propName)) { return; - } - properties[propName] = prepro; } + properties[propName] = prepro; + } } void cmExportFileGenerator::PopulateInterfaceProperty( - const std::string& propName, - cmGeneratorTarget* target, - cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap &properties, - std::vector<std::string> &missingTargets) + const std::string& propName, cmGeneratorTarget* target, + cmGeneratorExpression::PreprocessContext preprocessRule, + ImportPropertyMap& properties, std::vector<std::string>& missingTargets) { this->PopulateInterfaceProperty(propName, propName, target, preprocessRule, - properties, missingTargets); + properties, missingTargets); } - -void getPropertyContents(cmGeneratorTarget const* tgt, - const std::string& prop, - std::set<std::string> &ifaceProperties) +void getPropertyContents(cmGeneratorTarget const* tgt, const std::string& prop, + std::set<std::string>& ifaceProperties) { - const char *p = tgt->GetProperty(prop); - if (!p) - { + const char* p = tgt->GetProperty(prop); + if (!p) { return; - } + } std::vector<std::string> content; cmSystemTools::ExpandListArgument(p, content); ifaceProperties.insert(content.begin(), content.end()); } -void getCompatibleInterfaceProperties(cmGeneratorTarget *target, - std::set<std::string> &ifaceProperties, +void getCompatibleInterfaceProperties(cmGeneratorTarget* target, + std::set<std::string>& ifaceProperties, const std::string& config) { - cmComputeLinkInformation *info = target->GetLinkInformation(config); + cmComputeLinkInformation* info = target->GetLinkInformation(config); - if (!info) - { + 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"; + e << "Exporting the target \"" << target->GetName() + << "\" is not " + "allowed since its linker language cannot be determined"; lg->IssueMessage(cmake::FATAL_ERROR, e.str()); return; - } + } - const cmComputeLinkInformation::ItemVector &deps = info->GetItems(); + const cmComputeLinkInformation::ItemVector& deps = info->GetItems(); - for(cmComputeLinkInformation::ItemVector::const_iterator li = - deps.begin(); - li != deps.end(); ++li) - { - if (!li->Target) - { + for (cmComputeLinkInformation::ItemVector::const_iterator li = deps.begin(); + li != deps.end(); ++li) { + if (!li->Target) { continue; - } - getPropertyContents(li->Target, - "COMPATIBLE_INTERFACE_BOOL", + } + getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties); - getPropertyContents(li->Target, - "COMPATIBLE_INTERFACE_STRING", + getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_STRING", ifaceProperties); - getPropertyContents(li->Target, - "COMPATIBLE_INTERFACE_NUMBER_MIN", + getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_NUMBER_MIN", ifaceProperties); - getPropertyContents(li->Target, - "COMPATIBLE_INTERFACE_NUMBER_MAX", + getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_NUMBER_MAX", ifaceProperties); - } + } } void cmExportFileGenerator::PopulateCompatibleInterfaceProperties( - cmGeneratorTarget *gtarget, - ImportPropertyMap &properties) + cmGeneratorTarget* 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); + 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; @@ -582,335 +512,272 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties( getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MAX", ifaceProperties); - if (gtarget->GetType() != cmState::INTERFACE_LIBRARY) - { + if (gtarget->GetType() != cmState::INTERFACE_LIBRARY) { getCompatibleInterfaceProperties(gtarget, ifaceProperties, ""); std::vector<std::string> configNames; gtarget->Target->GetMakefile()->GetConfigurations(configNames); for (std::vector<std::string>::const_iterator ci = configNames.begin(); - ci != configNames.end(); ++ci) - { + ci != configNames.end(); ++ci) { getCompatibleInterfaceProperties(gtarget, ifaceProperties, *ci); - } } + } for (std::set<std::string>::const_iterator it = ifaceProperties.begin(); - it != ifaceProperties.end(); ++it) - { - this->PopulateInterfaceProperty("INTERFACE_" + *it, - gtarget, properties); - } + it != ifaceProperties.end(); ++it) { + this->PopulateInterfaceProperty("INTERFACE_" + *it, gtarget, properties); + } } void cmExportFileGenerator::GenerateInterfaceProperties( - const cmGeneratorTarget* target, - std::ostream& os, - const ImportPropertyMap &properties) + const cmGeneratorTarget* target, std::ostream& os, + const ImportPropertyMap& properties) { - if (!properties.empty()) - { + if (!properties.empty()) { std::string targetName = this->Namespace; targetName += target->GetExportName(); os << "set_target_properties(" << targetName << " PROPERTIES\n"; - for(ImportPropertyMap::const_iterator pi = properties.begin(); - pi != properties.end(); ++pi) - { - os << " " << pi->first << " " - << cmExportFileGeneratorEscape(pi->second) << "\n"; - } - os << ")\n\n"; + for (ImportPropertyMap::const_iterator pi = properties.begin(); + pi != properties.end(); ++pi) { + os << " " << pi->first << " " << cmExportFileGeneratorEscape(pi->second) + << "\n"; } + os << ")\n\n"; + } } -bool -cmExportFileGenerator::AddTargetNamespace(std::string &input, - cmGeneratorTarget* target, - std::vector<std::string> &missingTargets) +bool cmExportFileGenerator::AddTargetNamespace( + std::string& input, cmGeneratorTarget* target, + std::vector<std::string>& missingTargets) { - cmLocalGenerator *lg = target->GetLocalGenerator(); + cmLocalGenerator* lg = target->GetLocalGenerator(); - cmGeneratorTarget *tgt = lg->FindGeneratorTargetToUse(input); - if (!tgt) - { + cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(input); + if (!tgt) { return false; - } + } - if(tgt->IsImported()) - { + if (tgt->IsImported()) { return true; - } - if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) - { + } + if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) { input = this->Namespace + tgt->GetExportName(); - } - else - { + } else { std::string namespacedTarget; - this->HandleMissingTarget(namespacedTarget, missingTargets, - target, tgt); - if (!namespacedTarget.empty()) - { + this->HandleMissingTarget(namespacedTarget, missingTargets, target, tgt); + if (!namespacedTarget.empty()) { input = namespacedTarget; - } } + } return true; } -void -cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( - std::string &input, - cmGeneratorTarget* target, - std::vector<std::string> &missingTargets, - FreeTargetsReplace replace) +void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( + std::string& input, cmGeneratorTarget* target, + std::vector<std::string>& missingTargets, FreeTargetsReplace replace) { - if (replace == NoReplaceFreeTargets) - { + if (replace == NoReplaceFreeTargets) { this->ResolveTargetsInGeneratorExpression(input, target, missingTargets); return; - } + } std::vector<std::string> parts; cmGeneratorExpression::Split(input, parts); std::string sep; input = ""; - for(std::vector<std::string>::iterator li = parts.begin(); - li != parts.end(); ++li) - { - if (cmGeneratorExpression::Find(*li) == std::string::npos) - { + for (std::vector<std::string>::iterator li = parts.begin(); + li != parts.end(); ++li) { + if (cmGeneratorExpression::Find(*li) == std::string::npos) { this->AddTargetNamespace(*li, target, missingTargets); - } - else - { - this->ResolveTargetsInGeneratorExpression( - *li, - target, - missingTargets); - } + } else { + this->ResolveTargetsInGeneratorExpression(*li, target, missingTargets); + } input += sep + *li; sep = ";"; - } + } } -void -cmExportFileGenerator::ResolveTargetsInGeneratorExpression( - std::string &input, - cmGeneratorTarget* target, - std::vector<std::string> &missingTargets) +void cmExportFileGenerator::ResolveTargetsInGeneratorExpression( + std::string& input, cmGeneratorTarget* target, + std::vector<std::string>& missingTargets) { std::string::size_type pos = 0; std::string::size_type lastPos = pos; - while((pos = input.find("$<TARGET_PROPERTY:", lastPos)) != input.npos) - { - std::string::size_type nameStartPos = pos + - sizeof("$<TARGET_PROPERTY:") - 1; + while ((pos = input.find("$<TARGET_PROPERTY:", lastPos)) != input.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 == input.npos // Implied 'this' target - || closePos == input.npos // Imcomplete expression. - || closePos < commaPos // Implied 'this' target + if (commaPos == input.npos // Implied 'this' target + || closePos == input.npos // Imcomplete expression. + || closePos < commaPos // Implied 'this' target || nextOpenPos < commaPos) // Non-literal - { + { lastPos = nameStartPos; continue; - } + } - std::string targetName = input.substr(nameStartPos, - commaPos - nameStartPos); + std::string targetName = + input.substr(nameStartPos, commaPos - nameStartPos); - if (this->AddTargetNamespace(targetName, target, missingTargets)) - { + if (this->AddTargetNamespace(targetName, target, missingTargets)) { input.replace(nameStartPos, commaPos - nameStartPos, targetName); - } - lastPos = nameStartPos + targetName.size() + 1; } + lastPos = nameStartPos + targetName.size() + 1; + } std::string errorString; pos = 0; lastPos = pos; - while((pos = input.find("$<TARGET_NAME:", lastPos)) != input.npos) - { + while ((pos = input.find("$<TARGET_NAME:", lastPos)) != input.npos) { std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1; std::string::size_type endPos = input.find(">", nameStartPos); - if (endPos == input.npos) - { + if (endPos == input.npos) { errorString = "$<TARGET_NAME:...> expression incomplete"; break; - } - std::string targetName = input.substr(nameStartPos, - endPos - nameStartPos); - if(targetName.find("$<") != input.npos) - { + } + std::string targetName = input.substr(nameStartPos, endPos - nameStartPos); + if (targetName.find("$<") != input.npos) { errorString = "$<TARGET_NAME:...> requires its parameter to be a " "literal."; break; - } - if (!this->AddTargetNamespace(targetName, target, missingTargets)) - { + } + if (!this->AddTargetNamespace(targetName, target, missingTargets)) { errorString = "$<TARGET_NAME:...> requires its parameter to be a " "reachable target."; break; - } + } input.replace(pos, endPos - pos + 1, targetName); lastPos = endPos; - } + } pos = 0; lastPos = pos; while (errorString.empty() && - (pos = input.find("$<LINK_ONLY:", lastPos)) != input.npos) - { + (pos = input.find("$<LINK_ONLY:", lastPos)) != input.npos) { std::string::size_type nameStartPos = pos + sizeof("$<LINK_ONLY:") - 1; std::string::size_type endPos = input.find(">", nameStartPos); - if (endPos == input.npos) - { + if (endPos == input.npos) { errorString = "$<LINK_ONLY:...> expression incomplete"; break; - } + } std::string libName = input.substr(nameStartPos, endPos - nameStartPos); if (cmGeneratorExpression::IsValidTargetName(libName) && - this->AddTargetNamespace(libName, target, missingTargets)) - { + this->AddTargetNamespace(libName, target, missingTargets)) { input.replace(nameStartPos, endPos - nameStartPos, libName); - } - lastPos = nameStartPos + libName.size() + 1; } + lastPos = nameStartPos + libName.size() + 1; + } this->ReplaceInstallPrefix(input); - if (!errorString.empty()) - { + if (!errorString.empty()) { target->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, errorString); - } + } } -void -cmExportFileGenerator::ReplaceInstallPrefix(std::string &) +void cmExportFileGenerator::ReplaceInstallPrefix(std::string&) { // Do nothing } -void -cmExportFileGenerator -::SetImportLinkInterface(const std::string& config, std::string const& suffix, - cmGeneratorExpression::PreprocessContext preprocessRule, - cmGeneratorTarget* target, ImportPropertyMap& properties, - std::vector<std::string>& missingTargets) +void cmExportFileGenerator::SetImportLinkInterface( + const std::string& config, std::string const& suffix, + cmGeneratorExpression::PreprocessContext preprocessRule, + cmGeneratorTarget* 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) - { + cmLinkInterface const* iface = target->GetLinkInterface(config, target); + if (!iface) { return; - } + } - if (iface->ImplementationIsInterface) - { + if (iface->ImplementationIsInterface) { // Policy CMP0022 must not be NEW. this->SetImportLinkProperty(suffix, target, "IMPORTED_LINK_INTERFACE_LIBRARIES", iface->Libraries, properties, missingTargets); return; - } + } - const char *propContent; + const char* propContent; - if (const char *prop_suffixed = target->GetProperty( - "LINK_INTERFACE_LIBRARIES" + suffix)) - { + if (const char* prop_suffixed = + target->GetProperty("LINK_INTERFACE_LIBRARIES" + suffix)) { propContent = prop_suffixed; - } - else if (const char *prop = target->GetProperty( - "LINK_INTERFACE_LIBRARIES")) - { + } else if (const char* prop = + target->GetProperty("LINK_INTERFACE_LIBRARIES")) { propContent = prop; - } - else - { + } else { return; - } + } const bool newCMP0022Behavior = - target->GetPolicyStatusCMP0022() != cmPolicies::WARN - && target->GetPolicyStatusCMP0022() != cmPolicies::OLD; + target->GetPolicyStatusCMP0022() != cmPolicies::WARN && + target->GetPolicyStatusCMP0022() != cmPolicies::OLD; - if(newCMP0022Behavior && !this->ExportOld) - { - cmLocalGenerator *lg = target->GetLocalGenerator(); + if (newCMP0022Behavior && !this->ExportOld) { + cmLocalGenerator* lg = target->GetLocalGenerator(); std::ostringstream e; - e << "Target \"" << target->GetName() << "\" has policy CMP0022 enabled, " + 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(cmake::FATAL_ERROR, e.str()); return; - } + } - if (!*propContent) - { + if (!*propContent) { properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = ""; return; - } + } - std::string prepro = cmGeneratorExpression::Preprocess(propContent, - preprocessRule); - if (!prepro.empty()) - { - this->ResolveTargetsInGeneratorExpressions(prepro, target, - missingTargets, + 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 - ) +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() == cmState::SHARED_LIBRARY || - target->GetType() == cmState::MODULE_LIBRARY) - { - if(!target->IsDLLPlatform()) - { + if (target->GetType() == cmState::SHARED_LIBRARY || + target->GetType() == cmState::MODULE_LIBRARY) { + if (!target->IsDLLPlatform()) { std::string prop; std::string value; - if(target->HasSOName(config)) - { - if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) - { + if (target->HasSOName(config)) { + if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { value = this->InstallNameDir(target, config); - } + } prop = "IMPORTED_SONAME"; value += target->GetSOName(config); - } - else - { + } 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)) - { + if (cmLinkInterface const* iface = + target->GetLinkInterface(config, target)) { this->SetImportLinkProperty(suffix, target, "IMPORTED_LINK_INTERFACE_LANGUAGES", iface->Languages, properties, missingTargets); @@ -919,40 +786,32 @@ cmExportFileGenerator this->SetImportLinkProperty(suffix, target, "IMPORTED_LINK_DEPENDENT_LIBRARIES", iface->SharedDeps, properties, dummy); - if(iface->Multiplicity > 0) - { + if (iface->Multiplicity > 0) { std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY"; prop += suffix; std::ostringstream m; m << iface->Multiplicity; properties[prop] = m.str(); - } } + } } template <typename T> -void -cmExportFileGenerator -::SetImportLinkProperty(std::string const& suffix, - cmGeneratorTarget* target, - const std::string& propName, - std::vector<T> const& entries, - ImportPropertyMap& properties, - std::vector<std::string>& missingTargets - ) +void cmExportFileGenerator::SetImportLinkProperty( + std::string const& suffix, cmGeneratorTarget* target, + const std::string& propName, std::vector<T> const& entries, + ImportPropertyMap& properties, std::vector<std::string>& missingTargets) { // Skip the property if there are no entries. - if(entries.empty()) - { + if (entries.empty()) { return; - } + } // Construct the property value. std::string link_entries; const char* sep = ""; - for(typename std::vector<T>::const_iterator li = entries.begin(); - li != entries.end(); ++li) - { + for (typename std::vector<T>::const_iterator li = entries.begin(); + li != entries.end(); ++li) { // Separate this from the previous entry. link_entries += sep; sep = ";"; @@ -960,7 +819,7 @@ cmExportFileGenerator std::string temp = *li; this->AddTargetNamespace(temp, target, missingTargets); link_entries += temp; - } + } // Store the property. std::string prop = propName; @@ -969,18 +828,15 @@ cmExportFileGenerator } void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os, - const std::string& config) + const std::string& config) { os << "#----------------------------------------------------------------\n" << "# Generated CMake target import file"; - if(!config.empty()) - { + if (!config.empty()) { os << " for configuration \"" << config << "\".\n"; - } - else - { + } else { os << ".\n"; - } + } os << "#----------------------------------------------------------------\n" << "\n"; this->GenerateImportVersionCode(os); @@ -1003,8 +859,8 @@ void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os) /* clang-format on */ } -void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os, - const std::string &expectedTargets) +void cmExportFileGenerator::GenerateExpectedTargetsCode( + std::ostream& os, const std::string& expectedTargets) { /* clang-format off */ os << "# Protect against multiple inclusion, which would fail when already " @@ -1040,9 +896,8 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os, "\n\n"; /* clang-format on */ } -void -cmExportFileGenerator -::GenerateImportTargetCode(std::ostream& os, const cmGeneratorTarget* target) +void cmExportFileGenerator::GenerateImportTargetCode( + std::ostream& os, const cmGeneratorTarget* target) { // Construct the imported target name. std::string targetName = this->Namespace; @@ -1051,8 +906,7 @@ cmExportFileGenerator // Create the imported target. os << "# Create imported target " << targetName << "\n"; - switch(target->GetType()) - { + switch (target->GetType()) { case cmState::EXECUTABLE: os << "add_executable(" << targetName << " IMPORTED)\n"; break; @@ -1071,44 +925,36 @@ cmExportFileGenerator case cmState::INTERFACE_LIBRARY: os << "add_library(" << targetName << " INTERFACE IMPORTED)\n"; break; - default: // should never happen + default: // should never happen break; - } + } // Mark the imported executable if it has exports. - if(target->IsExecutableWithExports()) - { + 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"; - } + 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()) - { + 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"; - } + if (target->IsCFBundleOnApple()) { + os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n"; + } os << "\n"; } -void -cmExportFileGenerator -::GenerateImportPropertyCode(std::ostream& os, const std::string& config, - cmGeneratorTarget const* target, - ImportPropertyMap const& properties) +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; @@ -1120,39 +966,33 @@ cmExportFileGenerator << config << "\"\n"; os << "set_property(TARGET " << targetName << " APPEND PROPERTY IMPORTED_CONFIGURATIONS "; - if(!config.empty()) - { + if (!config.empty()) { os << cmSystemTools::UpperCase(config); - } - else - { + } else { os << "NOCONFIG"; - } + } os << ")\n"; os << "set_target_properties(" << targetName << " PROPERTIES\n"; - for(ImportPropertyMap::const_iterator pi = properties.begin(); - pi != properties.end(); ++pi) - { - os << " " << pi->first << " " - << cmExportFileGeneratorEscape(pi->second) << "\n"; - } + for (ImportPropertyMap::const_iterator pi = properties.begin(); + pi != properties.end(); ++pi) { + os << " " << pi->first << " " << cmExportFileGeneratorEscape(pi->second) + << "\n"; + } os << " )\n" << "\n"; } - -void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, - const std::vector<std::string>& missingTargets) +void cmExportFileGenerator::GenerateMissingTargetsCheckCode( + std::ostream& os, const std::vector<std::string>& missingTargets) { - if (missingTargets.empty()) - { + 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" @@ -1160,13 +1000,11 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, "foreach(_target "; /* clang-format on */ std::set<std::string> emitted; - for(unsigned int i=0; i<missingTargets.size(); ++i) - { - if (emitted.insert(missingTargets[i]).second) - { - os << "\"" << missingTargets[i] << "\" "; - } + for (unsigned int i = 0; i < missingTargets.size(); ++i) { + if (emitted.insert(missingTargets[i]).second) { + os << "\"" << missingTargets[i] << "\" "; } + } /* clang-format off */ os << ")\n" " if(NOT TARGET \"${_target}\" )\n" @@ -1194,9 +1032,7 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, /* clang-format on */ } - -void -cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os) +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 @@ -1229,30 +1065,27 @@ cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os) /* clang-format on */ } - -void -cmExportFileGenerator -::GenerateImportedFileChecksCode(std::ostream& os, cmGeneratorTarget* target, - ImportPropertyMap const& properties, - const std::set<std::string>& importedLocations) +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 = this->Namespace; targetName += target->GetExportName(); - os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n" - "list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " "; + os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName + << " )\n" + "list(APPEND _IMPORT_CHECK_FILES_FOR_" + << targetName << " "; - for(std::set<std::string>::const_iterator li = importedLocations.begin(); - li != importedLocations.end(); - ++li) - { + for (std::set<std::string>::const_iterator li = importedLocations.begin(); + li != importedLocations.end(); ++li) { ImportPropertyMap::const_iterator pi = properties.find(*li); - if (pi != properties.end()) - { + if (pi != properties.end()) { os << cmExportFileGeneratorEscape(pi->second) << " "; - } } + } os << ")\n\n"; } |