Enhancement: SetProperty accept cmProp or std::string

Methods SetProperty of classes cmPropertyMap, cmStateDirectory
and cmMakefile accept now cmProp or std::string as argument.
This commit is contained in:
Marc Chevrier 2021-08-15 16:04:47 +02:00
parent 71bf838cf3
commit 6dfa581bab
16 changed files with 154 additions and 56 deletions

View File

@ -3986,6 +3986,10 @@ void cmMakefile::SetProperty(const std::string& prop, const char* value)
{
this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace);
}
void cmMakefile::SetProperty(const std::string& prop, cmProp value)
{
this->StateSnapshot.GetDirectory().SetProperty(prop, value, this->Backtrace);
}
void cmMakefile::AppendProperty(const std::string& prop,
const std::string& value, bool asString)

View File

@ -769,6 +769,11 @@ public:
//! Set/Get a property of this directory
void SetProperty(const std::string& prop, const char* value);
void SetProperty(const std::string& prop, cmProp value);
void SetProperty(const std::string& prop, const std::string& value)
{
this->SetProperty(prop, cmProp(value));
}
void AppendProperty(const std::string& prop, const std::string& value,
bool asString = false);
cmProp GetProperty(const std::string& prop) const;

View File

@ -19,6 +19,15 @@ void cmPropertyMap::SetProperty(const std::string& name, const char* value)
this->Map_[name] = value;
}
void cmPropertyMap::SetProperty(const std::string& name, cmProp value)
{
if (!value) {
this->Map_.erase(name);
return;
}
this->Map_[name] = *value;
}
void cmPropertyMap::AppendProperty(const std::string& name,
const std::string& value, bool asString)

View File

@ -26,6 +26,11 @@ public:
//! Set the property value
void SetProperty(const std::string& name, const char* value);
void SetProperty(const std::string& name, cmProp value);
void SetProperty(const std::string& name, const std::string& value)
{
this->SetProperty(name, cmProp(value));
}
//! Append to the property value
void AppendProperty(const std::string& name, const std::string& value,

View File

@ -269,7 +269,8 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc)
return this->Location.Matches(loc);
}
void cmSourceFile::SetProperty(const std::string& prop, const char* value)
template <typename ValueType>
void cmSourceFile::StoreProperty(const std::string& prop, ValueType value)
{
if (prop == propINCLUDE_DIRECTORIES) {
this->IncludeDirectories.clear();
@ -294,6 +295,15 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value)
}
}
void cmSourceFile::SetProperty(const std::string& prop, const char* value)
{
this->StoreProperty(prop, value);
}
void cmSourceFile::SetProperty(const std::string& prop, cmProp value)
{
this->StoreProperty(prop, value);
}
void cmSourceFile::AppendProperty(const std::string& prop,
const std::string& value, bool asString)
{

View File

@ -42,6 +42,11 @@ public:
//! Set/Get a property of this source file
void SetProperty(const std::string& prop, const char* value);
void SetProperty(const std::string& prop, cmProp value);
void SetProperty(const std::string& prop, const std::string& value)
{
this->SetProperty(prop, cmProp(value));
}
void AppendProperty(const std::string& prop, const std::string& value,
bool asString = false);
//! Might return a nullptr if the property is not set or invalid
@ -145,6 +150,9 @@ public:
std::string GetObjectLibrary() const;
private:
template <typename ValueType>
void StoreProperty(const std::string& prop, ValueType value);
cmSourceFileLocation Location;
cmPropertyMap Properties;
std::unique_ptr<cmCustomCommand> CustomCommand;

View File

@ -569,6 +569,10 @@ void cmState::SetGlobalProperty(const std::string& prop, const char* value)
{
this->GlobalProperties.SetProperty(prop, value);
}
void cmState::SetGlobalProperty(const std::string& prop, cmProp value)
{
this->GlobalProperties.SetProperty(prop, value);
}
void cmState::AppendGlobalProperty(const std::string& prop,
const std::string& value, bool asString)

View File

@ -178,6 +178,7 @@ public:
std::vector<std::string> GetCommandNames() const;
void SetGlobalProperty(const std::string& prop, const char* value);
void SetGlobalProperty(const std::string& prop, cmProp value);
void AppendGlobalProperty(const std::string& prop, const std::string& value,
bool asString = false);
cmProp GetGlobalProperty(const std::string& prop);

View File

@ -361,8 +361,9 @@ void cmStateDirectory::ClearLinkDirectories()
this->Snapshot_.Position->LinkDirectoriesPosition);
}
void cmStateDirectory::SetProperty(const std::string& prop, const char* value,
cmListFileBacktrace const& lfbt)
template <typename ValueType>
void cmStateDirectory::StoreProperty(const std::string& prop, ValueType value,
cmListFileBacktrace const& lfbt)
{
if (prop == "INCLUDE_DIRECTORIES") {
if (!value) {
@ -408,6 +409,17 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value,
this->DirectoryState->Properties.SetProperty(prop, value);
}
void cmStateDirectory::SetProperty(const std::string& prop, const char* value,
cmListFileBacktrace const& lfbt)
{
this->StoreProperty(prop, value, lfbt);
}
void cmStateDirectory::SetProperty(const std::string& prop, cmProp value,
cmListFileBacktrace const& lfbt)
{
this->StoreProperty(prop, value, lfbt);
}
void cmStateDirectory::AppendProperty(const std::string& prop,
const std::string& value, bool asString,
cmListFileBacktrace const& lfbt)

View File

@ -73,6 +73,8 @@ public:
void SetProperty(const std::string& prop, const char* value,
cmListFileBacktrace const& lfbt);
void SetProperty(const std::string& prop, cmProp value,
cmListFileBacktrace const& lfbt);
void AppendProperty(const std::string& prop, const std::string& value,
bool asString, cmListFileBacktrace const& lfbt);
cmProp GetProperty(const std::string& prop) const;
@ -84,6 +86,10 @@ public:
void AddImportedTargetName(std::string const& name);
private:
template <typename ValueType>
void StoreProperty(const std::string& prop, ValueType value,
cmListFileBacktrace const& lfbt);
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator
DirectoryState;
cmStateSnapshot Snapshot_;

View File

@ -1177,32 +1177,59 @@ cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
return cmMakeRange(this->impl->LinkImplementationPropertyBacktraces);
}
void cmTarget::SetProperty(const std::string& prop, const char* value)
namespace {
#define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
MAKE_PROP(C_STANDARD);
MAKE_PROP(CXX_STANDARD);
MAKE_PROP(CUDA_STANDARD);
MAKE_PROP(HIP_STANDARD);
MAKE_PROP(OBJC_STANDARD);
MAKE_PROP(OBJCXX_STANDARD);
MAKE_PROP(COMPILE_DEFINITIONS);
MAKE_PROP(COMPILE_FEATURES);
MAKE_PROP(COMPILE_OPTIONS);
MAKE_PROP(PRECOMPILE_HEADERS);
MAKE_PROP(PRECOMPILE_HEADERS_REUSE_FROM);
MAKE_PROP(CUDA_PTX_COMPILATION);
MAKE_PROP(EXPORT_NAME);
MAKE_PROP(IMPORTED);
MAKE_PROP(IMPORTED_GLOBAL);
MAKE_PROP(INCLUDE_DIRECTORIES);
MAKE_PROP(LINK_OPTIONS);
MAKE_PROP(LINK_DIRECTORIES);
MAKE_PROP(LINK_LIBRARIES);
MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES);
MAKE_PROP(NAME);
MAKE_PROP(SOURCES);
MAKE_PROP(TYPE);
MAKE_PROP(BINARY_DIR);
MAKE_PROP(SOURCE_DIR);
MAKE_PROP(FALSE);
MAKE_PROP(TRUE);
#undef MAKE_PROP
}
namespace {
// to workaround bug on GCC/AIX
// Define a template to force conversion to std::string
template <typename ValueType>
std::string ConvertToString(ValueType value);
template <>
std::string ConvertToString<const char*>(const char* value)
{
return std::string(value);
}
template <>
std::string ConvertToString<cmProp>(cmProp value)
{
return std::string(*value);
}
}
template <typename ValueType>
void cmTarget::StoreProperty(const std::string& prop, ValueType value)
{
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
MAKE_STATIC_PROP(C_STANDARD);
MAKE_STATIC_PROP(CXX_STANDARD);
MAKE_STATIC_PROP(CUDA_STANDARD);
MAKE_STATIC_PROP(HIP_STANDARD);
MAKE_STATIC_PROP(OBJC_STANDARD);
MAKE_STATIC_PROP(OBJCXX_STANDARD);
MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
MAKE_STATIC_PROP(COMPILE_FEATURES);
MAKE_STATIC_PROP(COMPILE_OPTIONS);
MAKE_STATIC_PROP(PRECOMPILE_HEADERS);
MAKE_STATIC_PROP(PRECOMPILE_HEADERS_REUSE_FROM);
MAKE_STATIC_PROP(CUDA_PTX_COMPILATION);
MAKE_STATIC_PROP(EXPORT_NAME);
MAKE_STATIC_PROP(IMPORTED_GLOBAL);
MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
MAKE_STATIC_PROP(LINK_OPTIONS);
MAKE_STATIC_PROP(LINK_DIRECTORIES);
MAKE_STATIC_PROP(LINK_LIBRARIES);
MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
MAKE_STATIC_PROP(NAME);
MAKE_STATIC_PROP(SOURCES);
MAKE_STATIC_PROP(TYPE);
#undef MAKE_STATIC_PROP
if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
this->impl->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
@ -1327,7 +1354,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
this->GetGlobalGenerator()->IndexTarget(this);
}
} else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
!this->impl->CheckImportedLibName(prop, value ? value : "")) {
!this->impl->CheckImportedLibName(
prop, value ? value : std::string{})) {
/* error was reported by check method */
} else if (prop == propCUDA_PTX_COMPILATION &&
this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
@ -1357,7 +1385,7 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
std::string reusedFrom = reusedTarget->GetSafeProperty(prop);
if (reusedFrom.empty()) {
reusedFrom = value;
reusedFrom = ConvertToString(value);
}
this->impl->Properties.SetProperty(prop, reusedFrom.c_str());
@ -1486,6 +1514,15 @@ void cmTarget::AppendProperty(const std::string& prop,
}
}
void cmTarget::SetProperty(const std::string& prop, const char* value)
{
this->StoreProperty(prop, value);
}
void cmTarget::SetProperty(const std::string& prop, cmProp value)
{
this->StoreProperty(prop, value);
}
void cmTarget::AppendBuildInterfaceIncludes()
{
if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
@ -1693,31 +1730,6 @@ cmProp cmTarget::GetComputedProperty(const std::string& prop,
cmProp cmTarget::GetProperty(const std::string& prop) const
{
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
MAKE_STATIC_PROP(C_STANDARD);
MAKE_STATIC_PROP(CXX_STANDARD);
MAKE_STATIC_PROP(CUDA_STANDARD);
MAKE_STATIC_PROP(OBJC_STANDARD);
MAKE_STATIC_PROP(OBJCXX_STANDARD);
MAKE_STATIC_PROP(LINK_LIBRARIES);
MAKE_STATIC_PROP(TYPE);
MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
MAKE_STATIC_PROP(COMPILE_FEATURES);
MAKE_STATIC_PROP(COMPILE_OPTIONS);
MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
MAKE_STATIC_PROP(LINK_OPTIONS);
MAKE_STATIC_PROP(LINK_DIRECTORIES);
MAKE_STATIC_PROP(PRECOMPILE_HEADERS);
MAKE_STATIC_PROP(IMPORTED);
MAKE_STATIC_PROP(IMPORTED_GLOBAL);
MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
MAKE_STATIC_PROP(NAME);
MAKE_STATIC_PROP(BINARY_DIR);
MAKE_STATIC_PROP(SOURCE_DIR);
MAKE_STATIC_PROP(SOURCES);
MAKE_STATIC_PROP(FALSE);
MAKE_STATIC_PROP(TRUE);
#undef MAKE_STATIC_PROP
static std::unordered_set<std::string> const specialProps{
propC_STANDARD,
propCXX_STANDARD,

View File

@ -170,9 +170,10 @@ public:
//! Set/Get a property of this target file
void SetProperty(const std::string& prop, const char* value);
void SetProperty(const std::string& prop, cmProp value);
void SetProperty(const std::string& prop, const std::string& value)
{
this->SetProperty(prop, value.c_str());
this->SetProperty(prop, cmProp(value));
}
void AppendProperty(const std::string& prop, const std::string& value,
bool asString = false);
@ -283,6 +284,9 @@ public:
};
private:
template <typename ValueType>
void StoreProperty(const std::string& prop, ValueType value);
// Internal representation details.
friend class cmGeneratorTarget;

View File

@ -57,6 +57,10 @@ void cmTest::SetProperty(const std::string& prop, const char* value)
{
this->Properties.SetProperty(prop, value);
}
void cmTest::SetProperty(const std::string& prop, cmProp value)
{
this->Properties.SetProperty(prop, value);
}
void cmTest::AppendProperty(const std::string& prop, const std::string& value,
bool asString)

View File

@ -35,6 +35,11 @@ public:
//! Set/Get a property of this source file
void SetProperty(const std::string& prop, const char* value);
void SetProperty(const std::string& prop, cmProp value);
void SetProperty(const std::string& prop, const std::string& value)
{
this->SetProperty(prop, cmProp(value));
}
void AppendProperty(const std::string& prop, const std::string& value,
bool asString = false);
cmProp GetProperty(const std::string& prop) const;

View File

@ -2919,6 +2919,10 @@ void cmake::SetProperty(const std::string& prop, const char* value)
{
this->State->SetGlobalProperty(prop, value);
}
void cmake::SetProperty(const std::string& prop, cmProp value)
{
this->State->SetGlobalProperty(prop, value);
}
void cmake::AppendProperty(const std::string& prop, const std::string& value,
bool asString)

View File

@ -396,6 +396,11 @@ public:
//! Set/Get a property of this target file
void SetProperty(const std::string& prop, const char* value);
void SetProperty(const std::string& prop, cmProp value);
void SetProperty(const std::string& prop, const std::string& value)
{
this->SetProperty(prop, cmProp(value));
}
void AppendProperty(const std::string& prop, const std::string& value,
bool asString = false);
cmProp GetProperty(const std::string& prop);