From 287c59107997f33ba97e1637206a468ac0470033 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Dec 2020 14:49:08 -0500 Subject: cmake -E: Fix cmake_transform_depfile escaping of transformed paths In commit b2c14bc774 (cmake -E: Add cmake_transform_depfile internal command, 2020-10-02) we forgot to use `WriteFilenameGcc` in one place. --- Source/cmTransformDepfile.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmTransformDepfile.cxx b/Source/cmTransformDepfile.cxx index e1f8753..163d7e0 100644 --- a/Source/cmTransformDepfile.cxx +++ b/Source/cmTransformDepfile.cxx @@ -47,7 +47,8 @@ void WriteGccDepfile(cmsys::ofstream& fout, const cmGccDepfileContent& content) } fout << ':'; for (auto const& path : dep.paths) { - fout << " \\\n " << path; + fout << " \\\n "; + WriteFilenameGcc(fout, path); } fout << '\n'; } -- cgit v0.12 From 10809357322789889670d5829bb96fcc545870af Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 7 Dec 2020 14:43:25 -0500 Subject: AutoGen: Account for CMP0116 in the depfile Fixes: #21467 --- Source/cmQtAutoGenInitializer.cxx | 23 ++++++++++++++++++----- Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake | 3 +++ Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt | 4 ++++ Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt | 4 ++++ Tests/RunCMake/Ninja/RunCMakeTest.cmake | 13 +++++++++++-- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt create mode 100644 Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index f27b788..67834f1 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -29,6 +29,7 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmGlobalNinjaGenerator.h" #include "cmLinkItem.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" @@ -1237,11 +1238,23 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() const std::string outputFile = cmStrCat(this->Dir.Build, "/", timestampFileName); this->AutogenTarget.DepFile = cmStrCat(this->Dir.Build, "/deps"); - auto relativeBinaryDir = cmSystemTools::RelativePath( - this->LocalGen->GetBinaryDirectory(), - this->LocalGen->GetCurrentBinaryDirectory()); - if (!relativeBinaryDir.empty()) { - relativeBinaryDir = cmStrCat(relativeBinaryDir, "/"); + std::string relativeBinaryDir; + if (dynamic_cast(this->GlobalGen)) { + switch (this->LocalGen->GetPolicyStatus(cmPolicies::CMP0116)) { + case cmPolicies::OLD: + case cmPolicies::WARN: + relativeBinaryDir = cmSystemTools::RelativePath( + this->LocalGen->GetBinaryDirectory(), + this->LocalGen->GetCurrentBinaryDirectory()); + if (!relativeBinaryDir.empty()) { + relativeBinaryDir = cmStrCat(relativeBinaryDir, "/"); + } + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + break; + } } this->AutogenTarget.DepFileRuleName = cmStrCat(relativeBinaryDir, this->GenTarget->GetName(), "_autogen/", diff --git a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake index d69a119..d314ff3 100644 --- a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake +++ b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake @@ -7,3 +7,6 @@ set(CMAKE_AUTOMOC ON) add_library(simple_lib SHARED simple_lib.cpp) add_executable(app_with_qt app.cpp app_qt.cpp) target_link_libraries(app_with_qt PRIVATE simple_lib Qt5::Core) + +add_subdirectory(QtSubDir1) +add_subdirectory(QtSubDir2) diff --git a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt new file mode 100644 index 0000000..64016b6 --- /dev/null +++ b/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_policy(SET CMP0116 OLD) + +add_executable(sub_exe_1 ../app.cpp) +target_link_libraries(sub_exe_1 PRIVATE Qt5::Core) diff --git a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt new file mode 100644 index 0000000..3176426 --- /dev/null +++ b/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_policy(SET CMP0116 NEW) + +add_executable(sub_exe_2 ../app.cpp) +target_link_libraries(sub_exe_2 PRIVATE Qt5::Core) diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index e6f86a1..b91ab00 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -338,8 +338,17 @@ function(run_Qt5AutoMocDeps) # Build and assert that AUTOMOC was not run for app_with_qt. run_ninja("${RunCMake_TEST_BINARY_DIR}") if(ninja_stdout MATCHES "Automatic MOC for target app_with_qt") - message(FATAL_ERROR - "AUTOMOC should not have executed for 'app_with_qt' target:\nstdout:\n${ninja_stdout}") + message(FATAL_ERROR + "AUTOMOC should not have executed for 'app_with_qt' target:\nstdout:\n${ninja_stdout}") + endif() + # Assert that the subdir executables were not rebuilt. + if(ninja_stdout MATCHES "Automatic MOC for target sub_exe_1") + message(FATAL_ERROR + "AUTOMOC should not have executed for 'sub_exe_1' target:\nstdout:\n${ninja_stdout}") + endif() + if(ninja_stdout MATCHES "Automatic MOC for target sub_exe_2") + message(FATAL_ERROR + "AUTOMOC should not have executed for 'sub_exe_2' target:\nstdout:\n${ninja_stdout}") endif() endif() endfunction() -- cgit v0.12