diff options
Diffstat (limited to 'Source/cmGetPropertyCommand.cxx')
| -rw-r--r-- | Source/cmGetPropertyCommand.cxx | 103 |
1 files changed, 79 insertions, 24 deletions
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 947d893..cba7704 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -11,6 +11,7 @@ #include "cmPolicies.h" #include "cmProperty.h" #include "cmPropertyDefinition.h" +#include "cmSetPropertyCommand.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStringAlgorithms.h" @@ -48,7 +49,9 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, const std::string& propertyName); bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, - const std::string& propertyName); + const std::string& propertyName, + cmMakefile& directory_makefile, + bool source_file_paths_should_be_absolute); bool HandleTestMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, const std::string& propertyName); @@ -78,6 +81,11 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, std::string name; std::string propertyName; + std::vector<std::string> source_file_directories; + std::vector<std::string> source_file_target_directories; + bool source_file_directory_option_enabled = false; + bool source_file_target_option_enabled = false; + // Get the scope from which to get the property. cmProperty::ScopeType scope; if (args[1] == "GLOBAL") { @@ -111,7 +119,9 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, DoingNone, DoingName, DoingProperty, - DoingType + DoingType, + DoingSourceDirectory, + DoingSourceTargetDirectory }; Doing doing = DoingName; for (unsigned int i = 2; i < args.size(); ++i) { @@ -132,6 +142,20 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, } else if (doing == DoingName) { doing = DoingNone; name = args[i]; + } else if (doing == DoingNone && scope == cmProperty::SOURCE_FILE && + args[i] == "DIRECTORY") { + doing = DoingSourceDirectory; + source_file_directory_option_enabled = true; + } else if (doing == DoingNone && scope == cmProperty::SOURCE_FILE && + args[i] == "TARGET_DIRECTORY") { + doing = DoingSourceTargetDirectory; + source_file_target_option_enabled = true; + } else if (doing == DoingSourceDirectory) { + source_file_directories.push_back(args[i]); + doing = DoingNone; + } else if (doing == DoingSourceTargetDirectory) { + source_file_target_directories.push_back(args[i]); + doing = DoingNone; } else if (doing == DoingProperty) { doing = DoingNone; propertyName = args[i]; @@ -147,6 +171,16 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, return false; } + std::vector<cmMakefile*> source_file_directory_makefiles; + bool file_scopes_handled = + SetPropertyCommand::HandleAndValidateSourceFileDirectortoryScopes( + status, source_file_directory_option_enabled, + source_file_target_option_enabled, source_file_directories, + source_file_target_directories, source_file_directory_makefiles); + if (!file_scopes_handled) { + return false; + } + // Compute requested output. if (infoType == OutBriefDoc) { // Lookup brief documentation. @@ -180,6 +214,11 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, } } else { // Dispatch property getting. + cmMakefile& directory_scope_mf = *(source_file_directory_makefiles[0]); + bool source_file_paths_should_be_absolute = + source_file_directory_option_enabled || + source_file_target_option_enabled; + switch (scope) { case cmProperty::GLOBAL: return HandleGlobalMode(status, name, infoType, variable, @@ -191,8 +230,9 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, return HandleTargetMode(status, name, infoType, variable, propertyName); case cmProperty::SOURCE_FILE: - return HandleSourceMode(status, name, infoType, variable, - propertyName); + return HandleSourceMode(status, name, infoType, variable, propertyName, + directory_scope_mf, + source_file_paths_should_be_absolute); case cmProperty::TEST: return HandleTestMode(status, name, infoType, variable, propertyName); case cmProperty::VARIABLE: @@ -241,8 +281,9 @@ bool HandleGlobalMode(cmExecutionStatus& status, const std::string& name, // Get the property. cmake* cm = status.GetMakefile().GetCMakeInstance(); + cmProp p = cm->GetState()->GetGlobalProperty(propertyName); return StoreResult(infoType, status.GetMakefile(), variable, - cm->GetState()->GetGlobalProperty(propertyName)); + p ? p->c_str() : nullptr); } bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name, @@ -256,14 +297,8 @@ bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name, if (!name.empty()) { // Construct the directory name. Interpret relative paths with // respect to the current directory. - std::string dir = name; - if (!cmSystemTools::FileIsFullPath(dir)) { - dir = - cmStrCat(status.GetMakefile().GetCurrentSourceDirectory(), '/', name); - } - - // The local generators are associated with collapsed paths. - dir = cmSystemTools::CollapseFullPath(dir); + std::string dir = cmSystemTools::CollapseFullPath( + name, status.GetMakefile().GetCurrentSourceDirectory()); // Lookup the generator. mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir); @@ -294,8 +329,9 @@ bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name, } // Get the property. + cmProp p = mf->GetProperty(propertyName); return StoreResult(infoType, status.GetMakefile(), variable, - mf->GetProperty(propertyName)); + p ? p->c_str() : nullptr); } bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, @@ -308,14 +344,24 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, } if (cmTarget* target = status.GetMakefile().FindTargetToUse(name)) { - if (propertyName == "ALIASED_TARGET") { + if (propertyName == "ALIASED_TARGET" || propertyName == "ALIAS_GLOBAL") { if (status.GetMakefile().IsAlias(name)) { - return StoreResult(infoType, status.GetMakefile(), variable, - target->GetName().c_str()); + if (propertyName == "ALIASED_TARGET") { + + return StoreResult(infoType, status.GetMakefile(), variable, + target->GetName().c_str()); + } + if (propertyName == "ALIAS_GLOBAL") { + return StoreResult( + infoType, status.GetMakefile(), variable, + status.GetMakefile().GetGlobalGenerator()->IsAlias(name) + ? "TRUE" + : "FALSE"); + } } return StoreResult(infoType, status.GetMakefile(), variable, nullptr); } - const char* prop_cstr = nullptr; + cmProp prop_cstr = nullptr; cmListFileBacktrace bt = status.GetMakefile().GetBacktrace(); cmMessenger* messenger = status.GetMakefile().GetMessenger(); if (cmTargetPropertyComputer::PassesWhitelist( @@ -325,7 +371,8 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, prop_cstr = target->GetProperty(propertyName); } } - return StoreResult(infoType, status.GetMakefile(), variable, prop_cstr); + return StoreResult(infoType, status.GetMakefile(), variable, + prop_cstr ? prop_cstr->c_str() : nullptr); } status.SetError(cmStrCat("could not find TARGET ", name, ". Perhaps it has not yet been created.")); @@ -334,7 +381,9 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, - const std::string& propertyName) + const std::string& propertyName, + cmMakefile& directory_makefile, + const bool source_file_paths_should_be_absolute) { if (name.empty()) { status.SetError("not given name for SOURCE scope."); @@ -342,12 +391,17 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, } // Get the source file. - if (cmSourceFile* sf = status.GetMakefile().GetOrCreateSource(name)) { + const std::string source_file_absolute_path = + SetPropertyCommand::MakeSourceFilePathAbsoluteIfNeeded( + status, name, source_file_paths_should_be_absolute); + if (cmSourceFile* sf = + directory_makefile.GetOrCreateSource(source_file_absolute_path)) { return StoreResult(infoType, status.GetMakefile(), variable, sf->GetPropertyForUser(propertyName)); } status.SetError( - cmStrCat("given SOURCE name that could not be found or created: ", name)); + cmStrCat("given SOURCE name that could not be found or created: ", + source_file_absolute_path)); return false; } @@ -393,12 +447,13 @@ bool HandleCacheMode(cmExecutionStatus& status, const std::string& name, return false; } - const char* value = nullptr; + cmProp value = nullptr; if (status.GetMakefile().GetState()->GetCacheEntryValue(name)) { value = status.GetMakefile().GetState()->GetCacheEntryProperty( name, propertyName); } - StoreResult(infoType, status.GetMakefile(), variable, value); + StoreResult(infoType, status.GetMakefile(), variable, + value ? value->c_str() : nullptr); return true; } |
