From 06feb845aab7127a3067567a8fffb5777eac8187 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 17 Mar 2021 12:44:48 -0400 Subject: CMP0118: Fix NEW behavior when looking up target sources Under the CMP0118 NEW behavior, sources generated in one directory should be visible when added to targets in other directories. This was accidentally left out of commit 6624b65b3f (GENERATED prop: Add implementation for policy CMP0118 being set to NEW, 2020-11-09, v3.20.0-rc1~393^2~1). Fixes: #18399 --- Source/cmSourceFile.cxx | 17 +++++++++++--- .../RunCMake/CMP0118/CMP0118-NEW-Test10-result.txt | 1 - .../RunCMake/CMP0118/CMP0118-NEW-Test10-stderr.txt | 11 +-------- .../RunCMake/CMP0118/CMP0118-NEW-Test11-result.txt | 1 - .../RunCMake/CMP0118/CMP0118-NEW-Test11-stderr.txt | 27 +--------------------- .../RunCMake/CMP0118/CMP0118-NEW-Test14-result.txt | 1 - .../RunCMake/CMP0118/CMP0118-NEW-Test14-stderr.txt | 11 +-------- .../RunCMake/CMP0118/CMP0118-NEW-Test15-result.txt | 1 - .../RunCMake/CMP0118/CMP0118-NEW-Test15-stderr.txt | 27 +--------------------- .../RunCMake/CMP0118/CMP0118-NEW-Test6-result.txt | 1 - .../RunCMake/CMP0118/CMP0118-NEW-Test6-stderr.txt | 11 +-------- .../RunCMake/CMP0118/CMP0118-NEW-Test8-result.txt | 1 - .../RunCMake/CMP0118/CMP0118-NEW-Test8-stderr.txt | 11 +-------- Tests/RunCMake/CMP0118/CMakeLists.txt | 2 +- Tests/RunCMake/CMP0118/GenInSubdir-Common.cmake | 2 ++ Tests/RunCMake/CMP0118/GenInSubdir-NEW.cmake | 2 ++ Tests/RunCMake/CMP0118/GenInSubdir-OLD-result.txt | 1 + Tests/RunCMake/CMP0118/GenInSubdir-OLD-stderr.txt | 8 +++++++ Tests/RunCMake/CMP0118/GenInSubdir-OLD.cmake | 2 ++ Tests/RunCMake/CMP0118/GenInSubdir-WARN-result.txt | 1 + Tests/RunCMake/CMP0118/GenInSubdir-WARN-stderr.txt | 8 +++++++ Tests/RunCMake/CMP0118/GenInSubdir-WARN.cmake | 2 ++ Tests/RunCMake/CMP0118/GenInSubdir/CMakeLists.txt | 9 ++++++++ Tests/RunCMake/CMP0118/RunCMakeTest.cmake | 4 ++++ 24 files changed, 60 insertions(+), 102 deletions(-) delete mode 100644 Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-result.txt delete mode 100644 Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-result.txt delete mode 100644 Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-result.txt delete mode 100644 Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-result.txt delete mode 100644 Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-result.txt delete mode 100644 Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-result.txt create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-Common.cmake create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-NEW.cmake create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-OLD-result.txt create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-OLD-stderr.txt create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-OLD.cmake create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-WARN-result.txt create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-WARN-stderr.txt create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir-WARN.cmake create mode 100644 Tests/RunCMake/CMP0118/GenInSubdir/CMakeLists.txt diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 72bc972..3f3c8d5 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -141,14 +141,21 @@ bool cmSourceFile::FindFullPath(std::string* error, std::vector 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 = diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-result.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-stderr.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-stderr.txt index cee4516..2bd1cba 100644 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-stderr.txt +++ b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test10-stderr.txt @@ -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`$ diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-result.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-stderr.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-stderr.txt index 422a3de..05b2353 100644 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-stderr.txt +++ b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test11-stderr.txt @@ -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`$ diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-result.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-stderr.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-stderr.txt index 2f42f36..2bd1cba 100644 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-stderr.txt +++ b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test14-stderr.txt @@ -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`$ diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-result.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-stderr.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-stderr.txt index 65bd577..3166f45 100644 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-stderr.txt +++ b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test15-stderr.txt @@ -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`$ diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-result.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-stderr.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-stderr.txt index 17e2b4a..0c84cfe 100644 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-stderr.txt +++ b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test6-stderr.txt @@ -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`$ diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-result.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-stderr.txt b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-stderr.txt index 7f48bf0..f723875 100644 --- a/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-stderr.txt +++ b/Tests/RunCMake/CMP0118/CMP0118-NEW-Test8-stderr.txt @@ -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`$ diff --git a/Tests/RunCMake/CMP0118/CMakeLists.txt b/Tests/RunCMake/CMP0118/CMakeLists.txt index 0d30651..957fe03 100644 --- a/Tests/RunCMake/CMP0118/CMakeLists.txt +++ b/Tests/RunCMake/CMP0118/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-Common.cmake b/Tests/RunCMake/CMP0118/GenInSubdir-Common.cmake new file mode 100644 index 0000000..6012c79 --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-Common.cmake @@ -0,0 +1,2 @@ +add_custom_target(top) +add_subdirectory(GenInSubdir) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-NEW.cmake b/Tests/RunCMake/CMP0118/GenInSubdir-NEW.cmake new file mode 100644 index 0000000..373e73d --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0118 NEW) +include(GenInSubdir-Common.cmake) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-OLD-result.txt b/Tests/RunCMake/CMP0118/GenInSubdir-OLD-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-OLD-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-OLD-stderr.txt b/Tests/RunCMake/CMP0118/GenInSubdir-OLD-stderr.txt new file mode 100644 index 0000000..d3aa546 --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-OLD-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-OLD.cmake b/Tests/RunCMake/CMP0118/GenInSubdir-OLD.cmake new file mode 100644 index 0000000..48be27e --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-OLD.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0118 OLD) +include(GenInSubdir-Common.cmake) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-WARN-result.txt b/Tests/RunCMake/CMP0118/GenInSubdir-WARN-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-WARN-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-WARN-stderr.txt b/Tests/RunCMake/CMP0118/GenInSubdir-WARN-stderr.txt new file mode 100644 index 0000000..5eb8a34 --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-WARN-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir-WARN.cmake b/Tests/RunCMake/CMP0118/GenInSubdir-WARN.cmake new file mode 100644 index 0000000..8e7e395 --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir-WARN.cmake @@ -0,0 +1,2 @@ + +include(GenInSubdir-Common.cmake) diff --git a/Tests/RunCMake/CMP0118/GenInSubdir/CMakeLists.txt b/Tests/RunCMake/CMP0118/GenInSubdir/CMakeLists.txt new file mode 100644 index 0000000..3f1ce8d --- /dev/null +++ b/Tests/RunCMake/CMP0118/GenInSubdir/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CMP0118/RunCMakeTest.cmake b/Tests/RunCMake/CMP0118/RunCMakeTest.cmake index 72064bd..f7f135e 100644 --- a/Tests/RunCMake/CMP0118/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMP0118/RunCMakeTest.cmake @@ -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) -- cgit v0.12