diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-09-02 07:42:14 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-09-02 07:42:31 (GMT) |
commit | 80e0245e0e05c27dee316a9b53e23a4c0b12a9fe (patch) | |
tree | c42b5b1167a4de0d1ce3a099374be229f24805c1 /Source | |
parent | 3078bf20637dd3fc6fbed75c04dc5797926dd5b4 (diff) | |
parent | dc3aa4024eba3067d2cc81087aeccd4b31cf23f0 (diff) | |
download | CMake-80e0245e0e05c27dee316a9b53e23a4c0b12a9fe.zip CMake-80e0245e0e05c27dee316a9b53e23a4c0b12a9fe.tar.gz CMake-80e0245e0e05c27dee316a9b53e23a4c0b12a9fe.tar.bz2 |
Merge topic 'enh-SetProperty-accepts-new-types'
dc3aa4024e Refactor: Use new SetProperty signatures
6dfa581bab Enhancement: SetProperty accept cmProp or std::string
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6478
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddTestCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 19 | ||||
-rw-r--r-- | Source/cmMakefile.h | 5 | ||||
-rw-r--r-- | Source/cmPropertyMap.cxx | 9 | ||||
-rw-r--r-- | Source/cmPropertyMap.h | 5 | ||||
-rw-r--r-- | Source/cmQTWrapCPPCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmQtAutoGenGlobalInitializer.cxx | 2 | ||||
-rw-r--r-- | Source/cmSetDirectoryPropertiesCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmSetPropertyCommand.cxx | 10 | ||||
-rw-r--r-- | Source/cmSetSourceFilesPropertiesCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmSetTestsPropertiesCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 12 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 8 | ||||
-rw-r--r-- | Source/cmState.cxx | 4 | ||||
-rw-r--r-- | Source/cmState.h | 1 | ||||
-rw-r--r-- | Source/cmStateDirectory.cxx | 16 | ||||
-rw-r--r-- | Source/cmStateDirectory.h | 6 | ||||
-rw-r--r-- | Source/cmStateSnapshot.cxx | 2 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 124 | ||||
-rw-r--r-- | Source/cmTarget.h | 6 | ||||
-rw-r--r-- | Source/cmTest.cxx | 4 | ||||
-rw-r--r-- | Source/cmTest.h | 5 | ||||
-rw-r--r-- | Source/cmake.cxx | 4 | ||||
-rw-r--r-- | Source/cmake.h | 5 |
26 files changed, 184 insertions, 88 deletions
diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx index 205c1c7..a0d5732 100644 --- a/Source/cmAddTestCommand.cxx +++ b/Source/cmAddTestCommand.cxx @@ -140,7 +140,7 @@ bool cmAddTestCommandHandleNameMode(std::vector<std::string> const& args, test->SetOldStyle(false); test->SetCommand(command); if (!working_directory.empty()) { - test->SetProperty("WORKING_DIRECTORY", working_directory.c_str()); + test->SetProperty("WORKING_DIRECTORY", working_directory); } test->SetCommandExpandLists(command_expand_lists); mf.AddTestGenerator(cm::make_unique<cmTestGenerator>(test, configurations)); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 3994816..763f12a 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1667,7 +1667,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt) fout << "\n"; } if (cmSourceFile* sf = mf->GetOrCreateSource(fname)) { - sf->SetProperty("LANGUAGE", llang.c_str()); + sf->SetProperty("LANGUAGE", llang); gtgt->AddSource(fname); } } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 74130dd..5fe5c75 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2553,10 +2553,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) continue; } - const std::string pchExtension = - this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION"); + cmProp pchExtension = + this->Makefile->GetDefinition("CMAKE_PCH_EXTENSION"); - if (pchExtension.empty()) { + if (pchExtension.IsEmpty()) { continue; } @@ -2647,7 +2647,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) } } } else { - pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str()); + pch_sf->SetProperty("PCH_EXTENSION", pchExtension); } // Add pchHeader to source files, which will @@ -2788,7 +2788,7 @@ inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf, std::string const& filename) { target->AddSourceFileToUnityBatch(sf->ResolveFullPath()); - sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str()); + sf->SetProperty("UNITY_SOURCE_FILE", filename); } } @@ -2986,7 +2986,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) auto* unity = this->GetMakefile()->GetOrCreateSource(file); target->AddSource(file, true); unity->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "ON"); - unity->SetProperty("UNITY_SOURCE_FILE", file.c_str()); + unity->SetProperty("UNITY_SOURCE_FILE", file); } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0b8778f..7abbd31 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1444,7 +1444,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) std::string ndefs = cmJoin(cmMakeRange(defBegin, defEnd), ";"); // Store the new list. - this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str()); + this->SetProperty("COMPILE_DEFINITIONS", ndefs); } } else { // Append the definition to the directory property. @@ -1465,30 +1465,29 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) // Include transform property. There is no per-config version. { const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"; - this->SetProperty(prop, cmToCStr(parent->GetProperty(prop))); + this->SetProperty(prop, parent->GetProperty(prop)); } // compile definitions property and per-config versions cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043); if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) { this->SetProperty("COMPILE_DEFINITIONS", - cmToCStr(parent->GetProperty("COMPILE_DEFINITIONS"))); + parent->GetProperty("COMPILE_DEFINITIONS")); std::vector<std::string> configs = this->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); for (std::string const& config : configs) { std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config)); cmProp prop = parent->GetProperty(defPropName); - this->SetProperty(defPropName, cmToCStr(prop)); + this->SetProperty(defPropName, prop); } } // labels - this->SetProperty("LABELS", cmToCStr(parent->GetProperty("LABELS"))); + this->SetProperty("LABELS", parent->GetProperty("LABELS")); // link libraries - this->SetProperty("LINK_LIBRARIES", - cmToCStr(parent->GetProperty("LINK_LIBRARIES"))); + this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES")); // the initial project name this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName()); @@ -2308,7 +2307,7 @@ void cmMakefile::ExpandVariablesCMP0019() << " " << dirs << "\n"; /* clang-format on */ } - this->SetProperty("INCLUDE_DIRECTORIES", dirs.c_str()); + this->SetProperty("INCLUDE_DIRECTORIES", dirs); } // Also for each target's INCLUDE_DIRECTORIES property: @@ -3986,6 +3985,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/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index e9670f9..ca0b259 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -6,7 +6,6 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmPolicies.h" -#include "cmProperty.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -41,7 +40,7 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args, cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); cmSourceFile* sf = mf.GetOrCreateSource(newName, true); if (curr) { - sf->SetProperty("ABSTRACT", cmToCStr(curr->GetProperty("ABSTRACT"))); + sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT")); } // Compute the name of the header from which to generate the file. diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 77fe87e..f3ad565 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -186,7 +186,7 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( cmProp folder = makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER"); if (folder) { - target->SetProperty("FOLDER", *folder); + target->SetProperty("FOLDER", folder); } } } diff --git a/Source/cmSetDirectoryPropertiesCommand.cxx b/Source/cmSetDirectoryPropertiesCommand.cxx index 07ad246..9adf537 100644 --- a/Source/cmSetDirectoryPropertiesCommand.cxx +++ b/Source/cmSetDirectoryPropertiesCommand.cxx @@ -32,7 +32,7 @@ bool cmSetDirectoryPropertiesCommand(std::vector<std::string> const& args, "Commands and macros cannot be set using SET_CMAKE_PROPERTIES"); return false; } - status.GetMakefile().SetProperty(prop, (iter + 1)->c_str()); + status.GetMakefile().SetProperty(prop, *(iter + 1)); } return true; diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index c899053..59b4402 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -294,7 +294,7 @@ bool HandleAndValidateSourceFilePropertyGENERATED( sf->SetProperty("GENERATED", nullptr); break; case PropertyOp::Set: - sf->SetProperty("GENERATED", propertyValue.c_str()); + sf->SetProperty("GENERATED", propertyValue); break; } } else { @@ -474,7 +474,7 @@ bool HandleGlobalMode(cmExecutionStatus& status, if (remove) { cm->SetProperty(propertyName, nullptr); } else { - cm->SetProperty(propertyName, propertyValue.c_str()); + cm->SetProperty(propertyName, propertyValue); } } @@ -520,7 +520,7 @@ bool HandleDirectoryMode(cmExecutionStatus& status, if (remove) { mf->SetProperty(propertyName, nullptr); } else { - mf->SetProperty(propertyName, propertyValue.c_str()); + mf->SetProperty(propertyName, propertyValue); } } @@ -631,7 +631,7 @@ bool HandleSource(cmSourceFile* sf, const std::string& propertyName, if (remove) { sf->SetProperty(propertyName, nullptr); } else { - sf->SetProperty(propertyName, propertyValue.c_str()); + sf->SetProperty(propertyName, propertyValue); } } return true; @@ -681,7 +681,7 @@ bool HandleTest(cmTest* test, const std::string& propertyName, if (remove) { test->SetProperty(propertyName, nullptr); } else { - test->SetProperty(propertyName, propertyValue.c_str()); + test->SetProperty(propertyName, propertyValue); } } diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx index 237b67f..ab93ddb 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.cxx +++ b/Source/cmSetSourceFilesPropertiesCommand.cxx @@ -173,7 +173,7 @@ static bool RunCommandForScope( SetPropertyCommand::HandleAndValidateSourceFilePropertyGENERATED( sf, *(k + 1)); } else { - sf->SetProperty(*k, (k + 1)->c_str()); + sf->SetProperty(*k, *(k + 1)); } } } diff --git a/Source/cmSetTestsPropertiesCommand.cxx b/Source/cmSetTestsPropertiesCommand.cxx index c4bff76..a17c964 100644 --- a/Source/cmSetTestsPropertiesCommand.cxx +++ b/Source/cmSetTestsPropertiesCommand.cxx @@ -37,7 +37,7 @@ bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, // loop through all the props and set them for (auto k = propsIter + 1; k != args.end(); k += 2) { if (!k->empty()) { - test->SetProperty(*k, (k + 1)->c_str()); + test->SetProperty(*k, *(k + 1)); } } } else { 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/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 6f13d89..66cbcca 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -395,7 +395,7 @@ void cmStateSnapshot::InitializeFromParent() parent->BuildSystemDirectory->Properties.GetPropertyValue( "INCLUDE_REGULAR_EXPRESSION"); this->Position->BuildSystemDirectory->Properties.SetProperty( - "INCLUDE_REGULAR_EXPRESSION", cmToCStr(include_regex)); + "INCLUDE_REGULAR_EXPRESSION", include_regex); } cmState* cmStateSnapshot::GetState() const diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 656afc6..4f446d8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -267,7 +267,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Replace everything after "CMAKE_" defKey.replace(defKey.begin() + 6, defKey.end(), property); if (cmProp value = mf->GetDefinition(defKey)) { - this->SetProperty(property, *value); + this->SetProperty(property, value); } }; auto initPropValue = [this, mf, &defKey](const std::string& property, @@ -275,7 +275,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Replace everything after "CMAKE_" defKey.replace(defKey.begin() + 6, defKey.end(), property); if (cmProp value = mf->GetDefinition(defKey)) { - this->SetProperty(property, *value); + this->SetProperty(property, value); } else if (default_value) { this->SetProperty(property, default_value); } @@ -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,17 +1385,17 @@ 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()); + this->impl->Properties.SetProperty(prop, reusedFrom); reusedTarget->SetProperty("COMPILE_PDB_NAME", reusedFrom); reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY", cmStrCat(reusedFrom, ".dir/")); cmProp tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME"); - this->SetProperty("COMPILE_PDB_NAME", cmToCStr(tmp)); + this->SetProperty("COMPILE_PDB_NAME", tmp); this->AddUtility(reusedFrom, false, this->impl->Makefile); } else if (prop == propC_STANDARD || prop == propCXX_STANDARD || prop == propCUDA_STANDARD || prop == propHIP_STANDARD || @@ -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); |