1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 12:16:40 +08:00

file(REAL_PATH): Warn on non-existing paths

The command is documented to work only for cases that the referenced
path exists.

Fixes: #26260
This commit is contained in:
Alex Overchenko
2024-09-10 19:51:07 +03:00
committed by Brad King
parent 613a883470
commit 00c1161b01
5 changed files with 22 additions and 0 deletions

View File

@@ -1439,6 +1439,13 @@ bool HandleRealPathCommand(std::vector<std::string> const& args,
realPath = oldPolicyPath;
}
if (!cmSystemTools::FileExists(realPath)) {
status.GetMakefile().IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat("Given path:\n ", input,
"\ndoes not refer to an existing path on disk."));
}
status.GetMakefile().AddDefinition(args[2], realPath);
return true;

View File

@@ -0,0 +1,2 @@
file(REAL_PATH "dir" real_path_dir)
file(REAL_PATH "dir/empty.txt" real_path_file)

View File

@@ -0,0 +1,9 @@
^CMake Warning \(dev\) at REAL_PATH-non-existing.cmake:[0-9]+ \(file\):
Given path:
dir/bad-magic-file\.txt
does not refer to an existing path on disk.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$

View File

@@ -0,0 +1,2 @@
file(REAL_PATH "dir/bad-magic-file.txt" real_path)

View File

@@ -99,6 +99,8 @@ if(NOT WIN32
endif()
endif()
run_cmake(REAL_PATH-non-existing)
run_cmake(REAL_PATH-existing)
run_cmake(REAL_PATH-unexpected-arg)
run_cmake(REAL_PATH-no-base-dir)
run_cmake(REAL_PATH)