summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-10-31 15:59:20 (GMT)
committerBrad King <brad.king@kitware.com>2022-10-31 16:16:45 (GMT)
commit17096aeba815437abc6948954d62f9c64f8bdadd (patch)
tree0a027e90985f8e03fb3cd40bfe11e41a081c526d
parentc8f3ba7214769b940cbd60623d33b62f697ba43c (diff)
downloadCMake-17096aeba815437abc6948954d62f9c64f8bdadd.zip
CMake-17096aeba815437abc6948954d62f9c64f8bdadd.tar.gz
CMake-17096aeba815437abc6948954d62f9c64f8bdadd.tar.bz2
cmLocalGenerator: Factor out helper to compute MSVC_DEBUG_INFORMATION_FORMAT
-rw-r--r--Source/cmLocalGenerator.cxx42
-rw-r--r--Source/cmLocalGenerator.h4
2 files changed, 30 insertions, 16 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 2a50dd3..33255c5 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -2046,25 +2046,15 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
}
}
- // Add MSVC debug information format flags. This is activated by the presence
- // of a default selection whether or not it is overridden by a property.
- cmValue msvcDebugInformationFormatDefault = this->Makefile->GetDefinition(
- "CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT");
- if (cmNonempty(msvcDebugInformationFormatDefault)) {
- cmValue msvcDebugInformationFormatValue =
- target->GetProperty("MSVC_DEBUG_INFORMATION_FORMAT");
- if (!msvcDebugInformationFormatValue) {
- msvcDebugInformationFormatValue = msvcDebugInformationFormatDefault;
- }
- std::string const msvcDebugInformationFormat =
- cmGeneratorExpression::Evaluate(*msvcDebugInformationFormatValue, this,
- config, target);
- if (!msvcDebugInformationFormat.empty()) {
+ // Add MSVC debug information format flags if CMP0141 is NEW.
+ if (cm::optional<std::string> msvcDebugInformationFormat =
+ this->GetMSVCDebugFormatName(config, target)) {
+ if (!msvcDebugInformationFormat->empty()) {
if (cmValue msvcDebugInformationFormatOptions =
this->Makefile->GetDefinition(
cmStrCat("CMAKE_", lang,
"_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_",
- msvcDebugInformationFormat))) {
+ *msvcDebugInformationFormat))) {
this->AppendCompileOptions(flags, *msvcDebugInformationFormatOptions);
} else if ((this->Makefile->GetSafeDefinition(
cmStrCat("CMAKE_", lang, "_COMPILER_ID")) == "MSVC"_s ||
@@ -2074,7 +2064,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
// The compiler uses the MSVC ABI so it needs a known runtime library.
this->IssueMessage(MessageType::FATAL_ERROR,
cmStrCat("MSVC_DEBUG_INFORMATION_FORMAT value '",
- msvcDebugInformationFormat,
+ *msvcDebugInformationFormat,
"' not known for this ", lang,
" compiler."));
}
@@ -2871,6 +2861,26 @@ void cmLocalGenerator::CopyPchCompilePdb(
target_compile_pdb_dir);
}
+cm::optional<std::string> cmLocalGenerator::GetMSVCDebugFormatName(
+ std::string const& config, cmGeneratorTarget const* target)
+{
+ // MSVC debug information format selection is activated by the presence
+ // of a default whether or not it is overridden by a property.
+ cm::optional<std::string> msvcDebugInformationFormat;
+ cmValue msvcDebugInformationFormatDefault = this->Makefile->GetDefinition(
+ "CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT");
+ if (cmNonempty(msvcDebugInformationFormatDefault)) {
+ cmValue msvcDebugInformationFormatValue =
+ target->GetProperty("MSVC_DEBUG_INFORMATION_FORMAT");
+ if (!msvcDebugInformationFormatValue) {
+ msvcDebugInformationFormatValue = msvcDebugInformationFormatDefault;
+ }
+ msvcDebugInformationFormat = cmGeneratorExpression::Evaluate(
+ *msvcDebugInformationFormatValue, this, config, target);
+ }
+ return msvcDebugInformationFormat;
+}
+
namespace {
inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf,
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 0529431..765441c 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -646,6 +646,10 @@ private:
cmGeneratorTarget* reuseTarget,
std::vector<std::string> const& extensions);
+ // Returns MSVC_DEBUG_INFORMATION_FORMAT value if CMP0141 is NEW.
+ cm::optional<std::string> GetMSVCDebugFormatName(
+ std::string const& config, cmGeneratorTarget const* target);
+
struct UnityBatchedSource
{
cmSourceFile* Source = nullptr;