AutoGen: Account for CMP0116 in the depfile

Fixes: #21467
This commit is contained in:
Kyle Edwards
2020-12-07 14:43:25 -05:00
committed by Brad King
parent 287c591079
commit 1080935732
5 changed files with 40 additions and 7 deletions

View File

@@ -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<cmGlobalNinjaGenerator*>(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/",

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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()