diff options
Diffstat (limited to 'Source/cmGetPropertyCommand.cxx')
-rw-r--r-- | Source/cmGetPropertyCommand.cxx | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index cb657f9..162860a 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGetPropertyCommand.h" +#include <cstddef> + #include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmInstalledFile.h" @@ -18,6 +20,7 @@ #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTest.h" +#include "cmValue.h" #include "cmake.h" class cmMessenger; @@ -32,10 +35,6 @@ enum OutType OutSet }; -// Implementation of result storage. -bool StoreResult(OutType infoType, cmMakefile& makefile, - const std::string& variable, const char* value); - // Implementation of each property type. bool HandleGlobalMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, @@ -253,8 +252,10 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args, namespace { +// Implementation of result storage. +template <typename ValueType> bool StoreResult(OutType infoType, cmMakefile& makefile, - const std::string& variable, const char* value) + const std::string& variable, ValueType value) { if (infoType == OutSet) { makefile.AddDefinition(variable, value ? "1" : "0"); @@ -268,6 +269,12 @@ bool StoreResult(OutType infoType, cmMakefile& makefile, } return true; } +template <> +bool StoreResult(OutType infoType, cmMakefile& makefile, + const std::string& variable, std::nullptr_t value) +{ + return StoreResult(infoType, makefile, variable, cmValue(value)); +} bool HandleGlobalMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, @@ -280,9 +287,8 @@ bool HandleGlobalMode(cmExecutionStatus& status, const std::string& name, // Get the property. cmake* cm = status.GetMakefile().GetCMakeInstance(); - return StoreResult( - infoType, status.GetMakefile(), variable, - cmToCStr(cm->GetState()->GetGlobalProperty(propertyName))); + return StoreResult(infoType, status.GetMakefile(), variable, + cm->GetState()->GetGlobalProperty(propertyName)); } bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name, @@ -329,7 +335,7 @@ bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name, // Get the property. return StoreResult(infoType, status.GetMakefile(), variable, - cmToCStr(mf->GetProperty(propertyName))); + mf->GetProperty(propertyName)); } bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, @@ -361,12 +367,11 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name, } cmListFileBacktrace bt = status.GetMakefile().GetBacktrace(); cmMessenger* messenger = status.GetMakefile().GetMessenger(); - cmProp prop = target->GetComputedProperty(propertyName, messenger, bt); + cmValue prop = target->GetComputedProperty(propertyName, messenger, bt); if (!prop) { prop = target->GetProperty(propertyName); } - return StoreResult(infoType, status.GetMakefile(), variable, - cmToCStr(prop)); + return StoreResult(infoType, status.GetMakefile(), variable, prop); } status.SetError(cmStrCat("could not find TARGET ", name, ". Perhaps it has not yet been created.")); @@ -391,7 +396,7 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, if (cmSourceFile* sf = directory_makefile.GetOrCreateSource(source_file_absolute_path)) { return StoreResult(infoType, status.GetMakefile(), variable, - cmToCStr(sf->GetPropertyForUser(propertyName))); + sf->GetPropertyForUser(propertyName)); } status.SetError( cmStrCat("given SOURCE name that could not be found or created: ", @@ -428,9 +433,8 @@ bool HandleVariableMode(cmExecutionStatus& status, const std::string& name, return false; } - return StoreResult( - infoType, status.GetMakefile(), variable, - cmToCStr(status.GetMakefile().GetDefinition(propertyName))); + return StoreResult(infoType, status.GetMakefile(), variable, + status.GetMakefile().GetDefinition(propertyName)); } bool HandleCacheMode(cmExecutionStatus& status, const std::string& name, @@ -442,12 +446,12 @@ bool HandleCacheMode(cmExecutionStatus& status, const std::string& name, return false; } - cmProp value = nullptr; + cmValue value = nullptr; if (status.GetMakefile().GetState()->GetCacheEntryValue(name)) { value = status.GetMakefile().GetState()->GetCacheEntryProperty( name, propertyName); } - StoreResult(infoType, status.GetMakefile(), variable, cmToCStr(value)); + StoreResult(infoType, status.GetMakefile(), variable, value); return true; } |