From f783ee84b4d6c0ea2bc2d77125c39e9e24546a7d Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sun, 12 Jan 2025 11:22:08 +0100 Subject: [PATCH] Improve debug output of TestFileExists --- test/TestFileExists.cmake | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/TestFileExists.cmake b/test/TestFileExists.cmake index cfc33f2d..a69f49a0 100644 --- a/test/TestFileExists.cmake +++ b/test/TestFileExists.cmake @@ -9,5 +9,19 @@ endif() set(FILE_PATH "${CMAKE_ARGV3}") if(NOT ( EXISTS "${FILE_PATH}" )) - message(FATAL_ERROR "Test failed: File `${FILE_PATH}` does not exist.") + set(error_details "File `${FILE_PATH}` does not exist!\n") + set(PARENT_TREE "${FILE_PATH}") + cmake_path(HAS_PARENT_PATH PARENT_TREE has_parent) + while(has_parent) + cmake_path(GET PARENT_TREE PARENT_PATH PARENT_TREE) + cmake_path(HAS_PARENT_PATH PARENT_TREE has_parent) + if(EXISTS "${PARENT_TREE}") + file(GLOB dir_contents LIST_DIRECTORIES true "${PARENT_TREE}/*") + list(APPEND error_details "Found Parent directory `${PARENT_TREE}` exists and contains:\n" ${dir_contents}) + break() + else() + list(APPEND error_details "Parent directory `${PARENT_TREE}` also does not exist!") + endif() + endwhile() + message(FATAL_ERROR "Test failed: ${error_details}") endif()