1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-20 12:53:55 +08:00

pchreuse: ban PCH reuse from targets which disable PCH

This commit is contained in:
Ben Boeckel
2025-06-15 21:24:49 +02:00
parent f78f592b78
commit f9bc615d9a
5 changed files with 84 additions and 0 deletions

View File

@@ -2860,6 +2860,15 @@ cmGeneratorTarget const* cmGeneratorTarget::GetPchReuseTarget() const
}
if (generatorTarget) {
if (generatorTarget->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(
"Target \"", *pchReuseFrom, "\" for the \"", this->GetName(),
R"(" target's "PRECOMPILE_HEADERS_REUSE_FROM" property has set "DISABLE_PRECOMPILE_HEADERS".)"));
return nullptr;
}
if (auto const* recurseReuseTarget =
generatorTarget->GetPchReuseTarget()) {
return recurseReuseTarget;
@@ -2904,6 +2913,15 @@ cmGeneratorTarget* cmGeneratorTarget::GetPchReuseTarget()
}
if (generatorTarget) {
if (generatorTarget->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(
"Target \"", *pchReuseFrom, "\" for the \"", this->GetName(),
R"(" target's "PRECOMPILE_HEADERS_REUSE_FROM" property has set "DISABLE_PRECOMPILE_HEADERS".)"));
return nullptr;
}
if (auto* recurseReuseTarget = generatorTarget->GetPchReuseTarget()) {
return recurseReuseTarget;
}

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
CMake Error in CMakeLists.txt:
Target "pch-generator" for the "reuse_from_nopch" target's
"PRECOMPILE_HEADERS_REUSE_FROM" property has set
"DISABLE_PRECOMPILE_HEADERS".

View File

@@ -0,0 +1,60 @@
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)
set_property(TARGET pch-generator PROPERTY DISABLE_PRECOMPILE_HEADERS 1)
######################################################################
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(reuse_from_nopch ${CMAKE_BINARY_DIR}/message.cxx)
target_precompile_headers(reuse_from_nopch REUSE_FROM pch-generator)
target_include_directories(reuse_from_nopch PRIVATE ${CMAKE_BINARY_DIR})

View File

@@ -33,6 +33,7 @@ run_build_verbose(PchReuseFromIgnoreOwnProps)
run_build_verbose(PchReuseFromUseUpdatedProps)
run_build_verbose(PchReuseConsistency)
run_cmake(PchReuseFromCycle)
run_cmake(PchReuseWithoutPch)
run_cmake(PchMultilanguage)
run_build_verbose(PchReuseDeclarationOrder)
if(RunCMake_GENERATOR MATCHES "Make|Ninja")