diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-08-15 14:04:47 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-08-25 08:09:02 (GMT) |
commit | 6dfa581babfb051461341ca92e0463481799361f (patch) | |
tree | b78a81eb4e7e170820e11d324e8206045c37d29f /Source/cmTarget.cxx | |
parent | 71bf838cf35fabc27ff009f2901eeffc786fa753 (diff) | |
download | CMake-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.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 116 |
1 files changed, 64 insertions, 52 deletions
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, |