Make CMake error give the full path to the faulty CMakeLists.txt

Given a simple structure:

- project
--- CMakeLists.txt
--- lib
--- --- CMakeLists.txt

The top level CMakeLists.txt file just does an add_subdirectory(lib). If the lib CMakeLists.txt file is faulty, an error like the following is given:

CMake Error at lib/CMakeLists.txt:1:
  Parse error.  Expected a command name, got unquoted argument with text...

Is there a way to configure the project such that the lib/CMakeLists.txt is a full path? This would simply make IDE integration better. Thank you!

There is, AFAIK, no way to force full paths there.

FWIW, we currently rely on that in our test harnesses (where we use regexes to match output). The backtrace stack printing would also need changed.

However, the only relative paths are those to the top-level source directory which seems like something IDEs can assume when handling CMake output to me.

Cc: @brad.king

There is not currently a way to get an absolute path in that message. If the file is inside the top-level source tree (or build tree IIRC) then it will be expressed relative to that. I think some IDEs have been able to handle that but it does take special logic.

For reference, I searched the old mailing list archives and found this was raised before:

I’ve opened CMake Issue 20649 for this.