Commit 797689ab authored by Brad King's avatar Brad King
Browse files

PCH: Fix Makefile dependencies to rebuild PCH on header changes

Teach the Makefile generator to scan the implicit dependencies of PCH
creation.  When a header named by `target_precompile_headers` changes
the corresponding PCH must be rebuilt and all consumers recompiled.

Fixes: #19830
parent 0b10b3ed
...@@ -458,10 +458,14 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( ...@@ -458,10 +458,14 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
const std::string pchSource = const std::string pchSource =
this->GeneratorTarget->GetPchSource(config, lang); this->GeneratorTarget->GetPchSource(config, lang);
if (!pchSource.empty() && !source.GetProperty("SKIP_PRECOMPILE_HEADERS")) { if (!pchSource.empty() && !source.GetProperty("SKIP_PRECOMPILE_HEADERS")) {
depends.push_back(this->GeneratorTarget->GetPchHeader(config, lang)); std::string const& pchHeader =
this->GeneratorTarget->GetPchHeader(config, lang);
depends.push_back(pchHeader);
if (source.GetFullPath() != pchSource) { if (source.GetFullPath() != pchSource) {
depends.push_back(this->GeneratorTarget->GetPchFile(config, lang)); depends.push_back(this->GeneratorTarget->GetPchFile(config, lang));
} }
this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, lang,
objFullPath, pchHeader);
} }
std::string relativeObj = std::string relativeObj =
......
...@@ -62,6 +62,12 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx ...@@ -62,6 +62,12 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
"static const char* zot_macro_dir = \"zot_macro_dir\";\n") "static const char* zot_macro_dir = \"zot_macro_dir\";\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
"static const char* zot_macro_tgt = \"zot_macro_tgt\";\n") "static const char* zot_macro_tgt = \"zot_macro_tgt\";\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_pch.hxx
"#ifndef ZOT_PCH_HXX\n"
"#define ZOT_PCH_HXX\n"
"static const char* zot_pch = \"zot_pch\";\n"
"#endif\n"
)
file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
"#define link_depends_no_shared_lib_value 1\n") "#define link_depends_no_shared_lib_value 1\n")
...@@ -155,7 +161,7 @@ execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult) ...@@ -155,7 +161,7 @@ execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
string(REGEX REPLACE "[\r\n]" " " out "${out}") string(REGEX REPLACE "[\r\n]" " " out "${out}")
message("Run result: ${runResult} Output: \"${out}\"") message("Run result: ${runResult} Output: \"${out}\"")
set(VALUE_UNCHANGED "[zot] [zot_custom] [zot_macro_dir] [zot_macro_tgt] ") set(VALUE_UNCHANGED "[zot] [zot_custom] [zot_macro_dir] [zot_macro_tgt] [zot_pch] ")
if("${out}" STREQUAL "${VALUE_UNCHANGED}") if("${out}" STREQUAL "${VALUE_UNCHANGED}")
message("Worked!") message("Worked!")
else() else()
...@@ -245,6 +251,12 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx ...@@ -245,6 +251,12 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_dir.hxx
"static const char* zot_macro_dir = \"zot_macro_dir changed\";\n") "static const char* zot_macro_dir = \"zot_macro_dir changed\";\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
"static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n") "static const char* zot_macro_tgt = \"zot_macro_tgt changed\";\n")
file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_pch.hxx
"#ifndef ZOT_PCH_HXX\n"
"#define ZOT_PCH_HXX\n"
"static const char* zot_pch = \"zot_pch changed\";\n"
"#endif\n"
)
file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
"#define link_depends_no_shared_lib_value 0\n") "#define link_depends_no_shared_lib_value 0\n")
...@@ -326,7 +338,7 @@ string(REGEX REPLACE "[\r\n]" " " out "${out}") ...@@ -326,7 +338,7 @@ string(REGEX REPLACE "[\r\n]" " " out "${out}")
message("Run result: ${runResult} Output: \"${out}\"") message("Run result: ${runResult} Output: \"${out}\"")
set(VALUE_CHANGED set(VALUE_CHANGED
"[zot changed] [zot_custom changed] [zot_macro_dir changed] [zot_macro_tgt changed] " "[zot changed] [zot_custom changed] [zot_macro_dir changed] [zot_macro_tgt changed] [zot_pch changed] "
) )
if("${out}" STREQUAL "${VALUE_CHANGED}") if("${out}" STREQUAL "${VALUE_CHANGED}")
message("Worked!") message("Worked!")
......
...@@ -93,6 +93,12 @@ add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx ...@@ -93,6 +93,12 @@ add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
zot_macro_dir.cxx zot_macro_tgt.cxx) zot_macro_dir.cxx zot_macro_tgt.cxx)
add_dependencies(zot zot_custom) add_dependencies(zot zot_custom)
add_library(zot_pch zot_pch.cxx)
target_link_libraries(zot zot_pch)
if(NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]")
target_precompile_headers(zot_pch PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/zot_pch.hxx)
endif()
# Test the #include line macro transformation rule support. # Test the #include line macro transformation rule support.
set_property( set_property(
TARGET zot TARGET zot
......
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
const char* zot_macro_dir_f(); const char* zot_macro_dir_f();
const char* zot_macro_tgt_f(); const char* zot_macro_tgt_f();
const char* zot_pch_f();
int main() int main()
{ {
printf("[%s] [%s] [%s] [%s]\n", zot, zot_custom, zot_macro_dir_f(), printf("[%s] [%s] [%s] [%s] [%s]\n", zot, zot_custom, zot_macro_dir_f(),
zot_macro_tgt_f()); zot_macro_tgt_f(), zot_pch_f());
fflush(stdout); fflush(stdout);
return 0; return 0;
} }
#include <zot_pch.hxx>
const char* zot_pch_f()
{
return zot_pch;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment