summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@gmail.com>2019-11-13 13:58:33 (GMT)
committerBrad King <brad.king@kitware.com>2019-11-15 14:47:56 (GMT)
commitbb4c2781ced335c81b3c9307069792dba66d5062 (patch)
treeea358abcc1a7c33124e161225c339eaf32b67977
parent28bc41ca62b00d5c265c83436f317f970a4b9a93 (diff)
downloadCMake-bb4c2781ced335c81b3c9307069792dba66d5062.zip
CMake-bb4c2781ced335c81b3c9307069792dba66d5062.tar.gz
CMake-bb4c2781ced335c81b3c9307069792dba66d5062.tar.bz2
PCH: Do not issue an error on duplicate target_precompile_headers call
Fixes: #19970
-rw-r--r--Source/cmGeneratorTarget.cxx9
-rw-r--r--Source/cmTarget.cxx7
-rw-r--r--Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake9
-rw-r--r--Tests/RunCMake/PrecompileHeaders/foobar.c8
4 files changed, 22 insertions, 11 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index d38e9e1..171c3ed 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -3344,19 +3344,20 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
return std::string();
}
+ const cmGeneratorTarget* generatorTarget = this;
+ const char* pchReuseFrom =
+ generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
+
const auto inserted =
this->PchHeaders.insert(std::make_pair(language + config, ""));
if (inserted.second) {
const std::vector<BT<std::string>> headers =
this->GetPrecompileHeaders(config, language);
- if (headers.empty()) {
+ if (headers.empty() && !pchReuseFrom) {
return std::string();
}
std::string& filename = inserted.first->second;
- const cmGeneratorTarget* generatorTarget = this;
- const char* pchReuseFrom =
- generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
if (pchReuseFrom) {
generatorTarget =
this->GetGlobalGenerator()->FindGeneratorTarget(pchReuseFrom);
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 99c16f2..2db89de 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -1288,11 +1288,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
cmStrCat(reusedFrom, ".dir/").c_str());
- for (auto p : { "COMPILE_PDB_NAME", "PRECOMPILE_HEADERS",
- "INTERFACE_PRECOMPILE_HEADERS" }) {
- this->SetProperty(p, reusedTarget->GetProperty(p));
- }
-
+ this->SetProperty("COMPILE_PDB_NAME",
+ reusedTarget->GetProperty("COMPILE_PDB_NAME"));
this->AddUtility(reusedFrom, impl->Makefile);
} else {
impl->Properties.SetProperty(prop, value);
diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake
index 4502456..03a97ed 100644
--- a/Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake
+++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFrom.cmake
@@ -1,8 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(PchReuseFrom C)
+if(CMAKE_C_COMPILE_OPTIONS_USE_PCH)
+ add_definitions(-DHAVE_PCH_SUPPORT)
+endif()
+
add_library(empty empty.c)
-target_precompile_headers(empty PUBLIC
+target_precompile_headers(empty PRIVATE
<stdio.h>
<string.h>
)
@@ -12,6 +16,9 @@ add_library(foo foo.c)
target_include_directories(foo PUBLIC include)
target_precompile_headers(foo REUSE_FROM empty)
+# should not cause problems if configured multiple times
+target_precompile_headers(foo REUSE_FROM empty)
+
add_executable(foobar foobar.c)
target_link_libraries(foobar foo )
set_target_properties(foobar PROPERTIES PRECOMPILE_HEADERS_REUSE_FROM foo)
diff --git a/Tests/RunCMake/PrecompileHeaders/foobar.c b/Tests/RunCMake/PrecompileHeaders/foobar.c
index 7a135ea..97d465c 100644
--- a/Tests/RunCMake/PrecompileHeaders/foobar.c
+++ b/Tests/RunCMake/PrecompileHeaders/foobar.c
@@ -4,5 +4,11 @@
int main()
{
- return foo() + foo2() + bar();
+ int zeroSize = 0;
+
+#ifdef HAVE_PCH_SUPPORT
+ zeroSize = (int)strlen("");
+#endif
+
+ return foo() + foo2() + bar() + zeroSize;
}