summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@gmail.com>2019-09-24 22:08:15 (GMT)
committerCristian Adam <cristian.adam@gmail.com>2019-10-01 16:33:40 (GMT)
commite6e189e02bb6e3efafc5d635edf5eb9688291e71 (patch)
tree02a1d57f1c6163db9a9f7e4595a8518b64d1d787
parentec16afc9e8aed8aebd387c416af5b5eef4ad337a (diff)
downloadCMake-e6e189e02bb6e3efafc5d635edf5eb9688291e71.zip
CMake-e6e189e02bb6e3efafc5d635edf5eb9688291e71.tar.gz
CMake-e6e189e02bb6e3efafc5d635edf5eb9688291e71.tar.bz2
PCH: Report error when setting COMPILE_PDB_NAME property
Reusable precompile headers require specific COMPILE_PDB_NAME property values. Report error if the user tries to set a different value.
-rw-r--r--Source/cmGlobalGenerator.cxx40
-rw-r--r--Source/cmGlobalGenerator.h1
-rw-r--r--Tests/RunCMake/VS10Project/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-result.txt1
-rw-r--r--Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-stderr.txt7
-rw-r--r--Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName.cmake9
6 files changed, 59 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index a75e2ed..abe483a9 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -355,6 +355,42 @@ bool cmGlobalGenerator::CheckTargetsForType() const
return failed;
}
+bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
+{
+ if (!this->GetLanguageEnabled("C") && !this->GetLanguageEnabled("CXX")) {
+ return false;
+ }
+ bool failed = false;
+ for (cmLocalGenerator* generator : this->LocalGenerators) {
+ for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) {
+ if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
+ target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
+ target->GetType() == cmStateEnums::TargetType::UTILITY ||
+ cmIsOn(target->GetProperty("ghs_integrity_app"))) {
+ continue;
+ }
+
+ const std::string reuseFrom =
+ target->GetSafeProperty("PRECOMPILE_HEADERS_REUSE_FROM");
+ const std::string compilePdb =
+ target->GetSafeProperty("COMPILE_PDB_NAME");
+
+ if (!reuseFrom.empty() && reuseFrom != compilePdb) {
+ const std::string e = cmStrCat(
+ "PRECOMPILE_HEADERS_REUSE_FROM property is set on target (\"",
+ target->GetName(),
+ "\"). Reusable precompile headers requires the COMPILE_PDB_NAME"
+ " property to have the value \"",
+ reuseFrom, "\"\n");
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e,
+ target->GetBacktrace());
+ failed = true;
+ }
+ }
+ }
+ return failed;
+}
+
bool cmGlobalGenerator::IsExportedTargetsFile(
const std::string& filename) const
{
@@ -1398,6 +1434,10 @@ bool cmGlobalGenerator::Compute()
return false;
}
+ if (this->CheckTargetsForPchCompilePdb()) {
+ return false;
+ }
+
for (cmLocalGenerator* localGen : this->LocalGenerators) {
localGen->ComputeHomeRelativeOutputPath();
}
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index cf9c951..eb5ee27 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -610,6 +610,7 @@ private:
bool CheckTargetsForMissingSources() const;
bool CheckTargetsForType() const;
+ bool CheckTargetsForPchCompilePdb() const;
void CreateLocalGenerators();
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
index dcdd177..44ccd6b 100644
--- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -26,6 +26,7 @@ run_cmake(VsPackageReferences)
run_cmake(VsDpiAware)
run_cmake(VsDpiAwareBadParam)
run_cmake(VsPrecompileHeaders)
+run_cmake(VsPrecompileHeadersReuseFromCompilePDBName)
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
run_cmake(VsJustMyCode)
diff --git a/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-result.txt b/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-stderr.txt b/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-stderr.txt
new file mode 100644
index 0000000..2ff57cd
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error at VsPrecompileHeadersReuseFromCompilePDBName.cmake:6 \(add_library\):
+ PRECOMPILE_HEADERS_REUSE_FROM property is set on target \("b"\). Reusable
+ precompile headers requires the COMPILE_PDB_NAME property to have the value
+ "a"
+
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName.cmake b/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName.cmake
new file mode 100644
index 0000000..ec11008
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsPrecompileHeadersReuseFromCompilePDBName.cmake
@@ -0,0 +1,9 @@
+project(VsPrecompileHeadersReuseFromCompilePDBName CXX)
+
+add_library(a SHARED empty.cxx)
+target_precompile_headers(a PRIVATE <windows.h>)
+
+add_library(b SHARED empty.cxx)
+target_precompile_headers(b REUSE_FROM a)
+
+set_target_properties(b PROPERTIES COMPILE_PDB_NAME b)