Commit e01935ac authored by Cristian Adam's avatar Cristian Adam

PCH: No repeated path for internal generated PCH files

Fixes: #19952
parent adf863f1
......@@ -3360,14 +3360,8 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
this->GetGlobalGenerator()->FindGeneratorTarget(pchReuseFrom);
}
if (this->GetGlobalGenerator()->IsMultiConfig()) {
filename = cmStrCat(
generatorTarget->LocalGenerator->GetCurrentBinaryDirectory(), "/");
} else {
// For GCC we need to have the header file .h[xx]
// next to the .h[xx].gch file
filename = generatorTarget->ObjectDirectory;
}
filename = cmStrCat(
generatorTarget->LocalGenerator->GetCurrentBinaryDirectory(), "/");
const std::map<std::string, std::string> languageToExtension = {
{ "C", ".h" },
......
......@@ -3123,6 +3123,14 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
const char* pchExtension = source.GetProperty("PCH_EXTENSION");
if (pchExtension) {
customOutputExtension = pchExtension;
// Make sure that for the CMakeFiles/<target>.dir/cmake_pch.h|xx.c|xx
// source file, we don't end up having
// CMakeFiles/<target>.dir/CMakeFiles/<target>.dir/cmake_pch.h|xx.pch
cmsys::RegularExpression var("(CMakeFiles/[^/]+.dir/)");
while (var.find(objectName)) {
objectName.erase(var.start(), var.end() - var.start());
}
}
// Remove the source extension if it is to be replaced.
......
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/CMakeFiles/foo.dir/cmake_pch.h")
set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.h")
else()
set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/cmake_pch.h")
set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h")
endif()
set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/cmake_pch.h")
set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h")
if (NOT EXISTS ${foo_pch_header})
set(RunCMake_TEST_FAILED "Generated foo pch header ${foo_pch_header} does not exist")
......
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/CMakeFiles/foo.dir/cmake_pch.h")
set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.h")
else()
set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/cmake_pch.h")
set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h")
endif()
set(foo_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foo.dir/cmake_pch.h")
set(foobar_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h")
if (NOT EXISTS ${foo_pch_header})
set(RunCMake_TEST_FAILED "Generated foo pch header ${foo_pch_header} does not exist")
......
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(foobar_pch_h_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.h")
set(foobar_pch_hxx_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/CMakeFiles/foobar.dir/cmake_pch.hxx")
else()
set(foobar_pch_h_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h")
set(foobar_pch_hxx_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.hxx")
endif()
set(foobar_pch_h_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.h")
set(foobar_pch_hxx_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/foobar.dir/cmake_pch.hxx")
if (NOT EXISTS ${foobar_pch_h_header})
set(RunCMake_TEST_FAILED "Generated foobar C pch header ${foobar_pch_h_header} does not exist")
......
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/CMakeFiles/main.dir/cmake_pch.hxx")
else()
set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/cmake_pch.hxx")
endif()
set(main_pch_header "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/main.dir/cmake_pch.hxx")
file(STRINGS ${main_pch_header} main_pch_header_strings)
string(REGEX MATCH "#pragma warning\\(push, 0\\).*#include.*pch.h.*#pragma warning\\(pop\\)" matched_code ${main_pch_header_strings})
......
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