summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-08-15 14:04:47 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2021-08-25 08:09:02 (GMT)
commit6dfa581babfb051461341ca92e0463481799361f (patch)
treeb78a81eb4e7e170820e11d324e8206045c37d29f
parent71bf838cf35fabc27ff009f2901eeffc786fa753 (diff)
downloadCMake-6dfa581babfb051461341ca92e0463481799361f.zip
CMake-6dfa581babfb051461341ca92e0463481799361f.tar.gz
CMake-6dfa581babfb051461341ca92e0463481799361f.tar.bz2
Enhancement: SetProperty accept cmProp or std::string
Methods SetProperty of classes cmPropertyMap, cmStateDirectory and cmMakefile accept now cmProp or std::string as argument.
-rw-r--r--Source/cmMakefile.cxx4
-rw-r--r--Source/cmMakefile.h5
-rw-r--r--Source/cmPropertyMap.cxx9
-rw-r--r--Source/cmPropertyMap.h5
-rw-r--r--Source/cmSourceFile.cxx12
-rw-r--r--Source/cmSourceFile.h8
-rw-r--r--Source/cmState.cxx4
-rw-r--r--Source/cmState.h1
-rw-r--r--Source/cmStateDirectory.cxx16
-rw-r--r--Source/cmStateDirectory.h6
-rw-r--r--Source/cmTarget.cxx116
-rw-r--r--Source/cmTarget.h6
-rw-r--r--Source/cmTest.cxx4
-rw-r--r--Source/cmTest.h5
-rw-r--r--Source/cmake.cxx4
-rw-r--r--Source/cmake.h5
16 files changed, 154 insertions, 56 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 0b8778f..5a62dda 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -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)
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index a3d2a81..fd9a679 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -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;
diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx
index 3e3a44b..8ad3c6f 100644
--- a/Source/cmPropertyMap.cxx
+++ b/Source/cmPropertyMap.cxx
@@ -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)
diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h
index cda585a..b28d3c9 100644
--- a/Source/cmPropertyMap.h
+++ b/Source/cmPropertyMap.h
@@ -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,
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index f2b5cc4..6caae3a 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -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)
{
diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h
index 32ed687..78e0d27 100644
--- a/Source/cmSourceFile.h
+++ b/Source/cmSourceFile.h
@@ -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;
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index bde3e2e..a045545 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -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)
diff --git a/Source/cmState.h b/Source/cmState.h
index 8561fc0..0fd28d0 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -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);
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx
index b90cf7e..ed5b5d8 100644
--- a/Source/cmStateDirectory.cxx
+++ b/Source/cmStateDirectory.cxx
@@ -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)
diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h
index b8abccb..65e2f30 100644
--- a/Source/cmStateDirectory.h
+++ b/Source/cmStateDirectory.h
@@ -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_;
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 656afc6..345efed 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -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,
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 29130c7..de0c4e3 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -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;
diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx
index 5bc10c2..9d25ce9 100644
--- a/Source/cmTest.cxx
+++ b/Source/cmTest.cxx
@@ -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)
diff --git a/Source/cmTest.h b/Source/cmTest.h
index 63e5e87..a790501 100644
--- a/Source/cmTest.h
+++ b/Source/cmTest.h
@@ -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;
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 7f8f654..beb5d16 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -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)
diff --git a/Source/cmake.h b/Source/cmake.h
index 12cce7e..32c7582 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -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);