diff options
author | Brad King <brad.king@kitware.com> | 2022-07-28 12:11:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-07-28 12:11:19 (GMT) |
commit | d9cca8e83df9900565e5101e389c916c33f80466 (patch) | |
tree | ddd6098aadae8b7c63159273d616694b6ed83421 | |
parent | e7670480b35472915979d72eeac413859b8ef1ab (diff) | |
parent | 27fd172d8dcd42f5c9dc362cc3572f4f4d8132cd (diff) | |
download | CMake-d9cca8e83df9900565e5101e389c916c33f80466.zip CMake-d9cca8e83df9900565e5101e389c916c33f80466.tar.gz CMake-d9cca8e83df9900565e5101e389c916c33f80466.tar.bz2 |
Merge topic 'verify-interface-header-sets-add-compile-definitions'
27fd172d8d VERIFY_INTERFACE_HEADER_SETS: Finalize compile info for verify targets
626e641a19 cmTarget: Factor out FinalizeTargetCompileInfo()
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7516
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 6 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 34 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 45 | ||||
-rw-r--r-- | Source/cmTarget.h | 6 | ||||
-rw-r--r-- | Tests/RunCMake/VerifyHeaderSets/VerifyHeaderSets.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/VerifyHeaderSets/a.h | 4 |
6 files changed, 68 insertions, 29 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 433c1d5..8eac097 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -16,6 +16,7 @@ #include <utility> #include <cm/memory> +#include <cm/optional> #include <cm/string_view> #include <cmext/algorithm> #include <cmext/string_view> @@ -8636,6 +8637,11 @@ bool cmGeneratorTarget::AddHeaderSetVerification() verifyTarget->SetProperty("AUTOUIC", "OFF"); verifyTarget->SetProperty("DISABLE_PRECOMPILE_HEADERS", "ON"); verifyTarget->SetProperty("UNITY_BUILD", "OFF"); + cm::optional<std::map<std::string, cmValue>> + perConfigCompileDefinitions; + verifyTarget->FinalizeTargetCompileInfo( + this->Makefile->GetCompileDefinitionsEntries(), + perConfigCompileDefinitions); } if (fileCgesContextSensitive) { diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ebb12f8..edc4118 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -14,6 +14,7 @@ #include <utility> #include <cm/memory> +#include <cm/optional> #include <cmext/algorithm> #include <cmext/string_view> @@ -1823,39 +1824,14 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() // Construct per-target generator information. for (const auto& mf : this->Makefiles) { - const cmBTStringRange noconfig_compile_definitions = + const cmBTStringRange noConfigCompileDefinitions = mf->GetCompileDefinitionsEntries(); + cm::optional<std::map<std::string, cmValue>> perConfigCompileDefinitions; for (auto& target : mf->GetTargets()) { cmTarget* t = &target.second; - if (t->GetType() == cmStateEnums::GLOBAL_TARGET) { - continue; - } - - t->AppendBuildInterfaceIncludes(); - - if (t->GetType() == cmStateEnums::INTERFACE_LIBRARY) { - continue; - } - - for (auto const& def : noconfig_compile_definitions) { - t->InsertCompileDefinition(def); - } - - cmPolicies::PolicyStatus polSt = - mf->GetPolicyStatus(cmPolicies::CMP0043); - if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) { - std::vector<std::string> configs = - mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); - - for (std::string const& c : configs) { - std::string defPropName = - cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(c)); - if (cmValue val = mf->GetProperty(defPropName)) { - t->AppendProperty(defPropName, *val); - } - } - } + t->FinalizeTargetCompileInfo(noConfigCompileDefinitions, + perConfigCompileDefinitions); } // The standard include directories for each language diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c76e2cb..eafea05 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1935,6 +1935,51 @@ void cmTarget::AppendBuildInterfaceIncludes() } } +void cmTarget::FinalizeTargetCompileInfo( + const cmBTStringRange& noConfigCompileDefinitions, + cm::optional<std::map<std::string, cmValue>>& perConfigCompileDefinitions) +{ + if (this->GetType() == cmStateEnums::GLOBAL_TARGET) { + return; + } + + this->AppendBuildInterfaceIncludes(); + + if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + return; + } + + for (auto const& def : noConfigCompileDefinitions) { + this->InsertCompileDefinition(def); + } + + auto* mf = this->GetMakefile(); + cmPolicies::PolicyStatus polSt = mf->GetPolicyStatus(cmPolicies::CMP0043); + if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) { + if (perConfigCompileDefinitions) { + for (auto const& it : *perConfigCompileDefinitions) { + if (cmValue val = it.second) { + this->AppendProperty(it.first, *val); + } + } + } else { + perConfigCompileDefinitions.emplace(); + std::vector<std::string> configs = + mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); + + for (std::string const& c : configs) { + std::string defPropName = + cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(c)); + cmValue val = mf->GetProperty(defPropName); + (*perConfigCompileDefinitions)[defPropName] = val; + if (val) { + this->AppendProperty(defPropName, *val); + } + } + } + } +} + void cmTarget::InsertInclude(BT<std::string> const& entry, bool before) { auto position = before ? this->impl->IncludeDirectoriesEntries.begin() diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 94d6688..3d0a06b 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -5,12 +5,15 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <map> #include <memory> #include <set> #include <string> #include <utility> #include <vector> +#include <cm/optional> + #include "cmAlgorithms.h" #include "cmFileSet.h" #include "cmPolicies.h" @@ -233,6 +236,9 @@ public: void InsertPrecompileHeader(BT<std::string> const& entry); void AppendBuildInterfaceIncludes(); + void FinalizeTargetCompileInfo( + const cmBTStringRange& noConfigCompileDefinitions, + cm::optional<std::map<std::string, cmValue>>& perConfigCompileDefinitions); std::string GetDebugGeneratorExpressions(const std::string& value, cmTargetLinkLibraryType llt) const; diff --git a/Tests/RunCMake/VerifyHeaderSets/VerifyHeaderSets.cmake b/Tests/RunCMake/VerifyHeaderSets/VerifyHeaderSets.cmake index 82ed935..a601491 100644 --- a/Tests/RunCMake/VerifyHeaderSets/VerifyHeaderSets.cmake +++ b/Tests/RunCMake/VerifyHeaderSets/VerifyHeaderSets.cmake @@ -1,5 +1,7 @@ enable_language(C CXX) +add_compile_definitions(TEST_ADD_COMPILE_DEFINITIONS) + set_property(SOURCE a.h PROPERTY LANGUAGE C) set_property(SOURCE dir/c.h PROPERTY LANGUAGE C) set_property(SOURCE dir/cxx.h PROPERTY LANGUAGE CXX) diff --git a/Tests/RunCMake/VerifyHeaderSets/a.h b/Tests/RunCMake/VerifyHeaderSets/a.h index 8b17182..898da49 100644 --- a/Tests/RunCMake/VerifyHeaderSets/a.h +++ b/Tests/RunCMake/VerifyHeaderSets/a.h @@ -2,4 +2,8 @@ # error "TEST_A_H defined" #endif +#ifndef TEST_ADD_COMPILE_DEFINITIONS +# error "TEST_ADD_COMPILE_DEFINITIONS not defined" +#endif + extern void a_h(void); |