Merge topic 'fix-CMP0118-NEW'

17eb610a31 Help: Document CMP0118 requirement for boolean values
06feb845aa CMP0118: Fix NEW behavior when looking up target sources

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5921
This commit is contained in:
Brad King
2021-03-19 15:17:12 +00:00
committed by Kitware Robot
23 changed files with 66 additions and 102 deletions

View File

@@ -10,10 +10,16 @@ property of the source. Consequently, the associated ``GENERATED``
property is now visible from any directory scope, not only from the scope
for which it was set.
Additionally, the ``GENERATED`` property may now be set only to boolean
values, and may not be turned off once turned on.
The ``OLD`` behavior of this policy is to only allow ``GENERATED`` to be
visible from the directory scope for which it was set. The ``NEW``
behavior on the other hand allows it to be visible from any scope.
This policy was introduced in CMake version 3.20. CMake version |release|
warns when the policy is not set and uses ``OLD`` behavior. Use the
This policy was introduced in CMake version 3.20. Use the
:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
Unlike many policies, CMake version |release| does *not* warn
when this policy is not set and simply uses ``OLD`` behavior with regard
to visibility of the ``GENERATED`` property. However, CMake does warn
about setting the ``GENERATED`` property to a non-boolean value.

View File

@@ -141,14 +141,21 @@ bool cmSourceFile::FindFullPath(std::string* error,
std::vector<std::string> exts =
makefile->GetCMakeInstance()->GetAllExtensions();
auto cmp0115 = makefile->GetPolicyStatus(cmPolicies::CMP0115);
auto cmp0118 = makefile->GetPolicyStatus(cmPolicies::CMP0118);
bool const cmp0118new =
cmp0118 != cmPolicies::OLD && cmp0118 != cmPolicies::WARN;
// Tries to find the file in a given directory
auto findInDir = [this, &exts, &lPath, cmp0115, cmp0115Warning,
auto findInDir = [this, &exts, &lPath, cmp0115, cmp0115Warning, cmp0118new,
makefile](std::string const& dir) -> bool {
// Compute full path
std::string const fullPath = cmSystemTools::CollapseFullPath(lPath, dir);
// Try full path
if (cmSystemTools::FileExists(fullPath)) {
if (cmp0118new &&
makefile->GetGlobalGenerator()->IsGeneratedFile(fullPath)) {
this->IsGenerated = true;
}
if (this->IsGenerated || cmSystemTools::FileExists(fullPath)) {
this->FullPath = fullPath;
return true;
}
@@ -160,7 +167,11 @@ bool cmSourceFile::FindFullPath(std::string* error,
for (std::string const& ext : exts) {
if (!ext.empty()) {
std::string extPath = cmStrCat(fullPath, '.', ext);
if (cmSystemTools::FileExists(extPath)) {
if (cmp0118new &&
makefile->GetGlobalGenerator()->IsGeneratedFile(extPath)) {
this->IsGenerated = true;
}
if (this->IsGenerated || cmSystemTools::FileExists(extPath)) {
this->FullPath = extPath;
if (cmp0115 == cmPolicies::WARN) {
std::string warning =

View File

@@ -39,13 +39,4 @@ Generated_source6\.txt: # 1b # GENERATED = `1`
Generated_source6\.txt: # 2a # GENERATED = `1`
Generated_source6\.txt: # 2b # GENERATED = `1`
Generated_source6\.txt: # 3a # GENERATED = `0`
Generated_source6\.txt: # 3b # GENERATED = `0`
CMake Error at CMP0118-Common-Test10\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-build/Generated_source4\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test10\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
Generated_source6\.txt: # 3b # GENERATED = `0`$

View File

@@ -52,29 +52,4 @@ Generated_source6\.txt: # 1b # GENERATED = `0`
Generated_source6\.txt: # 2a # GENERATED = `0`
Generated_source6\.txt: # 2b # GENERATED = `0`
Generated_source6\.txt: # 3a # GENERATED = `0`
Generated_source6\.txt: # 3b # GENERATED = `0`
CMake Error at CMP0118-Common-Test11\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-build/Generated_source[4-6]\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test11\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Error at CMP0118-Common-Test11\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-build/Generated_source[4-6]\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test11\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Error at CMP0118-Common-Test11\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-build/Generated_source[4-6]\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test11\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
Generated_source6\.txt: # 3b # GENERATED = `0`$

View File

@@ -39,13 +39,4 @@ Generated_source6\.txt: # 1b # GENERATED = `1`
Generated_source6\.txt: # 2a # GENERATED = `1`
Generated_source6\.txt: # 2b # GENERATED = `1`
Generated_source6\.txt: # 3a # GENERATED = `0`
Generated_source6\.txt: # 3b # GENERATED = `0`
CMake Error at CMP0118-Common-Test14\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-build/Generated_source4\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test14\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
Generated_source6\.txt: # 3b # GENERATED = `0`$

View File

@@ -52,29 +52,4 @@ Generated_source6\.txt: # 1b # GENERATED = `0`
Generated_source6\.txt: # 2a # GENERATED = `0`
Generated_source6\.txt: # 2b # GENERATED = `0`
Generated_source6\.txt: # 3a # GENERATED = `0`
Generated_source6\.txt: # 3b # GENERATED = `0`
CMake Error at CMP0118-Common-Test15\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-build/Generated_source[4-6]\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test15\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Error at CMP0118-Common-Test15\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-build/Generated_source[4-6]\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test15\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Error at CMP0118-Common-Test15\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-build/Generated_source[4-6]\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test15\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
Generated_source6\.txt: # 3b # GENERATED = `0`$

View File

@@ -33,13 +33,4 @@ Generated_source6\.txt: # 1b # GENERATED = `1`
Generated_source6\.txt: # 2a # GENERATED = `1`
Generated_source6\.txt: # 2b # GENERATED = `1`
Generated_source6\.txt: # 3a # GENERATED = `0`
Generated_source6\.txt: # 3b # GENERATED = `0`
CMake Error at CMP0118-Common-Test6\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-build/Generated_source4\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test6\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
Generated_source6\.txt: # 3b # GENERATED = `0`$

View File

@@ -33,13 +33,4 @@ Generated_source6\.txt: # 1b # GENERATED = `1`
Generated_source6\.txt: # 2a # GENERATED = `1`
Generated_source6\.txt: # 2b # GENERATED = `1`
Generated_source6\.txt: # 3a # GENERATED = `0`
Generated_source6\.txt: # 3b # GENERATED = `0`
CMake Error at CMP0118-Common-Test8\.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[ \t]*.*Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-build/Generated_source4\.txt
Call Stack \(most recent call first\):
CMP0118-NEW-Test8\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
Generated_source6\.txt: # 3b # GENERATED = `0`$

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.19)
cmake_policy(SET CMP0115 NEW)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)

View File

@@ -0,0 +1,2 @@
add_custom_target(top)
add_subdirectory(GenInSubdir)

View File

@@ -0,0 +1,2 @@
cmake_policy(SET CMP0118 NEW)
include(GenInSubdir-Common.cmake)

View File

@@ -0,0 +1,8 @@
^CMake Error at GenInSubdir-Common.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[^
]*/Tests/RunCMake/CMP0118/GenInSubdir-OLD-build/GenInSubdir/sub.txt
Call Stack \(most recent call first\):
GenInSubdir-OLD.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\)

View File

@@ -0,0 +1,2 @@
cmake_policy(SET CMP0118 OLD)
include(GenInSubdir-Common.cmake)

View File

@@ -0,0 +1,8 @@
^CMake Error at GenInSubdir-Common.cmake:[0-9]+ \(add_custom_target\):
Cannot find source file:
[^
]*/Tests/RunCMake/CMP0118/GenInSubdir-WARN-build/GenInSubdir/sub.txt
Call Stack \(most recent call first\):
GenInSubdir-WARN.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\)

View File

@@ -0,0 +1,2 @@
include(GenInSubdir-Common.cmake)

View File

@@ -0,0 +1,9 @@
add_custom_command(
OUTPUT sub.txt
COMMAND ${CMAKE_COMMAND} -E touch sub.txt
VERBATIM
)
add_custom_target(gen DEPENDS sub.txt)
add_dependencies(top gen)
target_sources(top PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/sub.txt)

View File

@@ -1,5 +1,9 @@
include(RunCMake)
run_cmake(GenInSubdir-OLD)
run_cmake(GenInSubdir-WARN)
run_cmake(GenInSubdir-NEW)
run_cmake(CMP0118-OLD-Test1)
run_cmake(CMP0118-OLD-Test2)
run_cmake(CMP0118-OLD-Test3)