mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-15 19:20:44 -06:00
PCH: Do not issue an error on duplicate target_precompile_headers call
Fixes: #19970
This commit is contained in:
@@ -3344,19 +3344,20 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
|
|||||||
if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
|
if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
const cmGeneratorTarget* generatorTarget = this;
|
||||||
|
const char* pchReuseFrom =
|
||||||
|
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
|
||||||
|
|
||||||
const auto inserted =
|
const auto inserted =
|
||||||
this->PchHeaders.insert(std::make_pair(language + config, ""));
|
this->PchHeaders.insert(std::make_pair(language + config, ""));
|
||||||
if (inserted.second) {
|
if (inserted.second) {
|
||||||
const std::vector<BT<std::string>> headers =
|
const std::vector<BT<std::string>> headers =
|
||||||
this->GetPrecompileHeaders(config, language);
|
this->GetPrecompileHeaders(config, language);
|
||||||
if (headers.empty()) {
|
if (headers.empty() && !pchReuseFrom) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
std::string& filename = inserted.first->second;
|
std::string& filename = inserted.first->second;
|
||||||
|
|
||||||
const cmGeneratorTarget* generatorTarget = this;
|
|
||||||
const char* pchReuseFrom =
|
|
||||||
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
|
|
||||||
if (pchReuseFrom) {
|
if (pchReuseFrom) {
|
||||||
generatorTarget =
|
generatorTarget =
|
||||||
this->GetGlobalGenerator()->FindGeneratorTarget(pchReuseFrom);
|
this->GetGlobalGenerator()->FindGeneratorTarget(pchReuseFrom);
|
||||||
|
|||||||
@@ -1288,11 +1288,8 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
|
|||||||
reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
|
reusedTarget->SetProperty("COMPILE_PDB_OUTPUT_DIRECTORY",
|
||||||
cmStrCat(reusedFrom, ".dir/").c_str());
|
cmStrCat(reusedFrom, ".dir/").c_str());
|
||||||
|
|
||||||
for (auto p : { "COMPILE_PDB_NAME", "PRECOMPILE_HEADERS",
|
this->SetProperty("COMPILE_PDB_NAME",
|
||||||
"INTERFACE_PRECOMPILE_HEADERS" }) {
|
reusedTarget->GetProperty("COMPILE_PDB_NAME"));
|
||||||
this->SetProperty(p, reusedTarget->GetProperty(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
this->AddUtility(reusedFrom, impl->Makefile);
|
this->AddUtility(reusedFrom, impl->Makefile);
|
||||||
} else {
|
} else {
|
||||||
impl->Properties.SetProperty(prop, value);
|
impl->Properties.SetProperty(prop, value);
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(PchReuseFrom C)
|
project(PchReuseFrom C)
|
||||||
|
|
||||||
|
if(CMAKE_C_COMPILE_OPTIONS_USE_PCH)
|
||||||
|
add_definitions(-DHAVE_PCH_SUPPORT)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(empty empty.c)
|
add_library(empty empty.c)
|
||||||
target_precompile_headers(empty PUBLIC
|
target_precompile_headers(empty PRIVATE
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<string.h>
|
<string.h>
|
||||||
)
|
)
|
||||||
@@ -12,6 +16,9 @@ add_library(foo foo.c)
|
|||||||
target_include_directories(foo PUBLIC include)
|
target_include_directories(foo PUBLIC include)
|
||||||
target_precompile_headers(foo REUSE_FROM empty)
|
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)
|
add_executable(foobar foobar.c)
|
||||||
target_link_libraries(foobar foo )
|
target_link_libraries(foobar foo )
|
||||||
set_target_properties(foobar PROPERTIES PRECOMPILE_HEADERS_REUSE_FROM foo)
|
set_target_properties(foobar PROPERTIES PRECOMPILE_HEADERS_REUSE_FROM foo)
|
||||||
|
|||||||
@@ -4,5 +4,11 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
return foo() + foo2() + bar();
|
int zeroSize = 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_PCH_SUPPORT
|
||||||
|
zeroSize = (int)strlen("");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return foo() + foo2() + bar() + zeroSize;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user