mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 17:31:57 +08:00
pchreuse: defer PCH consistency checks to generation time
There's no reason that during-configure inconsistencies should block generation. It can be detected at that point instead.
This commit is contained in:
@@ -2817,6 +2817,13 @@ cmGeneratorTarget const* cmGeneratorTarget::GetPchReuseTarget() const
|
|||||||
if (!pchReuseFrom) {
|
if (!pchReuseFrom) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (this->GetProperty("PRECOMPILE_HEADERS").IsOn()) {
|
||||||
|
this->Makefile->IssueMessage(
|
||||||
|
MessageType::FATAL_ERROR,
|
||||||
|
cmStrCat("PRECOMPILE_HEADERS property is already set on target (\"",
|
||||||
|
this->GetName(), "\")\n"));
|
||||||
|
}
|
||||||
|
|
||||||
// Guaranteed to exist because `SetProperty` does a target lookup.
|
// Guaranteed to exist because `SetProperty` does a target lookup.
|
||||||
return this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
return this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
||||||
}
|
}
|
||||||
@@ -2827,6 +2834,13 @@ cmGeneratorTarget* cmGeneratorTarget::GetPchReuseTarget()
|
|||||||
if (!pchReuseFrom) {
|
if (!pchReuseFrom) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (this->GetProperty("PRECOMPILE_HEADERS").IsOn()) {
|
||||||
|
this->Makefile->IssueMessage(
|
||||||
|
MessageType::FATAL_ERROR,
|
||||||
|
cmStrCat("PRECOMPILE_HEADERS property is already set on target (\"",
|
||||||
|
this->GetName(), "\")\n"));
|
||||||
|
}
|
||||||
|
|
||||||
// Guaranteed to exist because `SetProperty` does a target lookup.
|
// Guaranteed to exist because `SetProperty` does a target lookup.
|
||||||
return this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
return this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
||||||
}
|
}
|
||||||
|
@@ -2148,13 +2148,6 @@ void cmTarget::SetProperty(std::string const& prop, cmValue value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (prop == propPRECOMPILE_HEADERS_REUSE_FROM) {
|
} else if (prop == propPRECOMPILE_HEADERS_REUSE_FROM) {
|
||||||
if (this->GetProperty("PRECOMPILE_HEADERS")) {
|
|
||||||
std::ostringstream e;
|
|
||||||
e << "PRECOMPILE_HEADERS property is already set on target (\""
|
|
||||||
<< this->impl->Name << "\")\n";
|
|
||||||
this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto* reusedTarget = this->impl->Makefile->GetCMakeInstance()
|
auto* reusedTarget = this->impl->Makefile->GetCMakeInstance()
|
||||||
->GetGlobalGenerator()
|
->GetGlobalGenerator()
|
||||||
->FindTarget(value);
|
->FindTarget(value);
|
||||||
@@ -2202,15 +2195,6 @@ void cmTarget::AppendProperty(std::string const& prop,
|
|||||||
"imported targets (\"",
|
"imported targets (\"",
|
||||||
this->impl->Name, "\")\n"));
|
this->impl->Name, "\")\n"));
|
||||||
}
|
}
|
||||||
if (prop == propPRECOMPILE_HEADERS &&
|
|
||||||
this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
|
|
||||||
this->impl->Makefile->IssueMessage(
|
|
||||||
MessageType::FATAL_ERROR,
|
|
||||||
cmStrCat(
|
|
||||||
"PRECOMPILE_HEADERS_REUSE_FROM property is already set on target (\"",
|
|
||||||
this->impl->Name, "\")\n"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UsageRequirementProperty* usageRequirements[] = {
|
UsageRequirementProperty* usageRequirements[] = {
|
||||||
&this->impl->IncludeDirectories,
|
&this->impl->IncludeDirectories,
|
||||||
|
67
Tests/RunCMake/PrecompileHeaders/PchReuseConsistency.cmake
Normal file
67
Tests/RunCMake/PrecompileHeaders/PchReuseConsistency.cmake
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
enable_language(CXX)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH)
|
||||||
|
add_definitions(-DHAVE_PCH_SUPPORT)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/pch.cxx [=[
|
||||||
|
void nothing()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
]=])
|
||||||
|
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/string.hxx [=[
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
struct string
|
||||||
|
{
|
||||||
|
char storage[20];
|
||||||
|
|
||||||
|
string(const char* s) {
|
||||||
|
strcpy(storage, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* c_str() const {
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]=])
|
||||||
|
|
||||||
|
add_library(pch-generator ${CMAKE_BINARY_DIR}/pch.cxx)
|
||||||
|
target_precompile_headers(pch-generator PRIVATE ${CMAKE_BINARY_DIR}/string.hxx)
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/message.cxx [=[
|
||||||
|
#include "message.hxx"
|
||||||
|
|
||||||
|
#ifndef HAVE_PCH_SUPPORT
|
||||||
|
#include "string.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char* message()
|
||||||
|
{
|
||||||
|
static std::string greeting("hi there");
|
||||||
|
return greeting.c_str();
|
||||||
|
}
|
||||||
|
]=])
|
||||||
|
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/message.hxx [=[
|
||||||
|
const char* message();
|
||||||
|
]=])
|
||||||
|
|
||||||
|
add_library(pch_before_reuse_reuse ${CMAKE_BINARY_DIR}/message.cxx)
|
||||||
|
target_precompile_headers(pch_before_reuse_reuse PRIVATE "${CMAKE_BINARY_DIR}/string.hxx")
|
||||||
|
target_precompile_headers(pch_before_reuse_reuse REUSE_FROM pch-generator)
|
||||||
|
set_property(TARGET pch_before_reuse_reuse PROPERTY PRECOMPILE_HEADERS "")
|
||||||
|
target_include_directories(pch_before_reuse_reuse PRIVATE ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
add_library(reuse_before_pch_reuse ${CMAKE_BINARY_DIR}/message.cxx)
|
||||||
|
target_precompile_headers(reuse_before_pch_reuse REUSE_FROM pch-generator)
|
||||||
|
target_precompile_headers(reuse_before_pch_reuse PRIVATE "${CMAKE_BINARY_DIR}/string.hxx")
|
||||||
|
set_property(TARGET reuse_before_pch_reuse PROPERTY PRECOMPILE_HEADERS "")
|
||||||
|
target_include_directories(reuse_before_pch_reuse PRIVATE ${CMAKE_BINARY_DIR})
|
@@ -31,6 +31,7 @@ run_test(PchReuseFromPrefixed)
|
|||||||
run_test(PchReuseFromSubdir)
|
run_test(PchReuseFromSubdir)
|
||||||
run_build_verbose(PchReuseFromIgnoreOwnProps)
|
run_build_verbose(PchReuseFromIgnoreOwnProps)
|
||||||
run_build_verbose(PchReuseFromUseUpdatedProps)
|
run_build_verbose(PchReuseFromUseUpdatedProps)
|
||||||
|
run_build_verbose(PchReuseConsistency)
|
||||||
run_cmake(PchMultilanguage)
|
run_cmake(PchMultilanguage)
|
||||||
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
|
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
|
||||||
run_cmake(PchWarnInvalid)
|
run_cmake(PchWarnInvalid)
|
||||||
|
Reference in New Issue
Block a user