summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-01 12:53:42 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-11-01 12:53:51 (GMT)
commit3f5d8562df4ecfe4bf6445630e9833a2609cf7b3 (patch)
treeb63b765984dc668c4e5e8019fb551a0ad8608de9
parent41cd9610864e2e9de65966e2ce7a5c53729d5f46 (diff)
parent183b9a9eca8bdf7684a6c281c677c58f3c0a66fd (diff)
downloadCMake-3f5d8562df4ecfe4bf6445630e9833a2609cf7b3.zip
CMake-3f5d8562df4ecfe4bf6445630e9833a2609cf7b3.tar.gz
CMake-3f5d8562df4ecfe4bf6445630e9833a2609cf7b3.tar.bz2
Merge topic 'cmp0141-pch-reuse'
183b9a9eca CMP0141: Fix PCH REUSE_FROM under policy NEW behavior 4d13f472a2 Tests: Drop redundant project init from RunCMake.PrecompileHeaders cases 2e65fe92db cmLocalGenerator: Clarify name of local PDB type variable 17096aeba8 cmLocalGenerator: Factor out helper to compute MSVC_DEBUG_INFORMATION_FORMAT Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !7854
-rw-r--r--Source/cmLocalGenerator.cxx67
-rw-r--r--Source/cmLocalGenerator.h4
-rw-r--r--Tests/RunCMake/PrecompileHeaders/DisabledPch.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchDebugGenex.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchIncludedAllLanguages.cmake4
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchIncludedOneLanguage.cmake4
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchInterface.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchLibObjLibExe.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake4
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue.cmake5
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-NEW.cmake2
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-OLD.cmake2
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFrom-common.cmake (renamed from Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake)3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFromObjLib.cmake5
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFromSubdir.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/PrecompileHeaders/SkipPrecompileHeaders.cmake5
18 files changed, 72 insertions, 54 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 2a50dd3..fb269b2 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."));
}
@@ -2685,13 +2675,22 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
this->Makefile->GetSafeDefinition(
cmStrCat("CMAKE_", lang, "_FLAGS_", configUpper));
- bool editAndContinueDebugInfo =
- langFlags.find("/ZI") != std::string::npos ||
- langFlags.find("-ZI") != std::string::npos;
-
- bool enableDebuggingInformation =
- langFlags.find("/Zi") != std::string::npos ||
- langFlags.find("-Zi") != std::string::npos;
+ bool editAndContinueDebugInfo = false;
+ bool programDatabaseDebugInfo = false;
+ if (cm::optional<std::string> msvcDebugInformationFormat =
+ this->GetMSVCDebugFormatName(config, target)) {
+ editAndContinueDebugInfo =
+ *msvcDebugInformationFormat == "EditAndContinue";
+ programDatabaseDebugInfo =
+ *msvcDebugInformationFormat == "ProgramDatabase";
+ } else {
+ editAndContinueDebugInfo =
+ langFlags.find("/ZI") != std::string::npos ||
+ langFlags.find("-ZI") != std::string::npos;
+ programDatabaseDebugInfo =
+ langFlags.find("/Zi") != std::string::npos ||
+ langFlags.find("-Zi") != std::string::npos;
+ }
// MSVC 2008 is producing both .pdb and .idb files with /Zi.
bool msvc2008OrLess =
@@ -2707,7 +2706,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
if (editAndContinueDebugInfo || msvc2008OrLess) {
this->CopyPchCompilePdb(config, target, *ReuseFrom,
reuseTarget, { ".pdb", ".idb" });
- } else if (enableDebuggingInformation) {
+ } else if (programDatabaseDebugInfo) {
this->CopyPchCompilePdb(config, target, *ReuseFrom,
reuseTarget, { ".pdb" });
}
@@ -2871,6 +2870,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;
diff --git a/Tests/RunCMake/PrecompileHeaders/DisabledPch.cmake b/Tests/RunCMake/PrecompileHeaders/DisabledPch.cmake
index 59ee14b..18b09c1 100644
--- a/Tests/RunCMake/PrecompileHeaders/DisabledPch.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/DisabledPch.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
-project(DisabledPch C)
+enable_language(C)
add_library(foo foo.c)
target_include_directories(foo PUBLIC include)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchDebugGenex.cmake b/Tests/RunCMake/PrecompileHeaders/PchDebugGenex.cmake
index 854689f..039a546 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchDebugGenex.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchDebugGenex.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchDebugGenex C)
+enable_language(C)
add_library(foo foo.c)
target_include_directories(foo PUBLIC include)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchIncludedAllLanguages.cmake b/Tests/RunCMake/PrecompileHeaders/PchIncludedAllLanguages.cmake
index a455410..eef189a 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchIncludedAllLanguages.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchIncludedAllLanguages.cmake
@@ -1,5 +1,5 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchIncludedAllLanguages C CXX)
+enable_language(C)
+enable_language(CXX)
if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH)
add_definitions(-DHAVE_PCH_SUPPORT)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchIncludedOneLanguage.cmake b/Tests/RunCMake/PrecompileHeaders/PchIncludedOneLanguage.cmake
index dd582ac..6c5e89d 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchIncludedOneLanguage.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchIncludedOneLanguage.cmake
@@ -1,5 +1,5 @@
-cmake_minimum_required(VERSION 3.16)
-project(PchIncludedAllLanguages C CXX)
+enable_language(C)
+enable_language(CXX)
if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH)
add_definitions(-DHAVE_PCH_SUPPORT)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchInterface.cmake b/Tests/RunCMake/PrecompileHeaders/PchInterface.cmake
index aab20d8..c031660 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchInterface.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchInterface.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchInterface C)
+enable_language(C)
add_library(foo foo.c)
target_include_directories(foo PUBLIC include)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchLibObjLibExe.cmake b/Tests/RunCMake/PrecompileHeaders/PchLibObjLibExe.cmake
index b4fdb71..ad8a328 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchLibObjLibExe.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchLibObjLibExe.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.16)
-project(PchLibObjLibExe CXX)
+enable_language(CXX)
foreach(i 1 2 3)
file(WRITE ${CMAKE_BINARY_DIR}/empty${i}.cpp "void nothing${i}() {}\n")
diff --git a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake
index bb18a64..d8abf8e 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchMultilanguage.cmake
@@ -1,5 +1,5 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchMultilanguage C CXX)
+enable_language(C)
+enable_language(CXX)
add_executable(foobar
foo.c
diff --git a/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue.cmake b/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue.cmake
index 3e27620..988c4c6 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchPrologueEpilogue.cmake
@@ -1,6 +1,5 @@
-cmake_minimum_required(VERSION 3.15)
-
-project(PchPrologueEpilogue)
+enable_language(C)
+enable_language(CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-NEW.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-NEW.cmake
new file mode 100644
index 0000000..daf7a38
--- /dev/null
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0141 NEW)
+include(PchReuseFrom-common.cmake)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-OLD.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-OLD.cmake
new file mode 100644
index 0000000..9586887
--- /dev/null
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-CMP0141-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0141 OLD)
+include(PchReuseFrom-common.cmake)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-common.cmake
index f8fba44..8d5e945 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom-common.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchReuseFrom C)
+enable_language(C)
if(CMAKE_C_COMPILE_OPTIONS_USE_PCH)
add_definitions(-DHAVE_PCH_SUPPORT)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFromObjLib.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFromObjLib.cmake
index ba504a3..510877f 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchReuseFromObjLib.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFromObjLib.cmake
@@ -1,6 +1,5 @@
-cmake_minimum_required(VERSION 3.18)
-
-project(PchReuseFromObjLib)
+enable_language(C)
+enable_language(CXX)
set(CMAKE_PCH_WARN_INVALID OFF)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake
index e306d8e..14703e3 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchReuseFromPrefixed C)
+enable_language(C)
if(CMAKE_C_COMPILE_OPTIONS_USE_PCH)
add_definitions(-DHAVE_PCH_SUPPORT)
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFromSubdir.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFromSubdir.cmake
index fff74dc..fefb4ee 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchReuseFromSubdir.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFromSubdir.cmake
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
-project(PchReuseFromSubdir C)
+enable_language(C)
add_library(empty empty.c)
target_precompile_headers(empty PUBLIC
diff --git a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake
index fd41e2f..687fc0e 100644
--- a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake
@@ -15,7 +15,8 @@ run_test(PchInterface)
run_cmake(PchPrologueEpilogue)
run_test(SkipPrecompileHeaders)
run_test(CXXnotC)
-run_test(PchReuseFrom)
+run_test(PchReuseFrom-CMP0141-OLD)
+run_test(PchReuseFrom-CMP0141-NEW)
run_test(PchReuseFromPrefixed)
run_test(PchReuseFromSubdir)
run_cmake(PchMultilanguage)
diff --git a/Tests/RunCMake/PrecompileHeaders/SkipPrecompileHeaders.cmake b/Tests/RunCMake/PrecompileHeaders/SkipPrecompileHeaders.cmake
index 49efbfb..7405e65 100644
--- a/Tests/RunCMake/PrecompileHeaders/SkipPrecompileHeaders.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/SkipPrecompileHeaders.cmake
@@ -1,6 +1,5 @@
-cmake_minimum_required(VERSION 3.15)
-
-project(SkipPrecompileHeaders)
+enable_language(C)
+enable_language(CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)