file(REAL_PATH): Warn on non-existing paths The command is documented to work only for cases that the referenced path exists. Fixes: #26260
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f5cd6e8..6e646c1 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx
@@ -1439,6 +1439,13 @@ 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;
diff --git a/Tests/RunCMake/file/REAL_PATH-existing.cmake b/Tests/RunCMake/file/REAL_PATH-existing.cmake new file mode 100644 index 0000000..5f67739 --- /dev/null +++ b/Tests/RunCMake/file/REAL_PATH-existing.cmake
@@ -0,0 +1,2 @@ +file(REAL_PATH "dir" real_path_dir) +file(REAL_PATH "dir/empty.txt" real_path_file)
diff --git a/Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt b/Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt new file mode 100644 index 0000000..4ac7521 --- /dev/null +++ b/Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt
@@ -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.$
diff --git a/Tests/RunCMake/file/REAL_PATH-non-existing.cmake b/Tests/RunCMake/file/REAL_PATH-non-existing.cmake new file mode 100644 index 0000000..c6357a8 --- /dev/null +++ b/Tests/RunCMake/file/REAL_PATH-non-existing.cmake
@@ -0,0 +1,2 @@ + +file(REAL_PATH "dir/bad-magic-file.txt" real_path)
diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake index 524636d..38ec2ac 100644 --- a/Tests/RunCMake/file/RunCMakeTest.cmake +++ b/Tests/RunCMake/file/RunCMakeTest.cmake
@@ -99,6 +99,8 @@ 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)