CMake Error messages in a more clickable way.

When running CMAKE - it will sometimes print a message like this:

CMake Error at foo/board-bar/CMakeLists.txt:117:

Question #1 - Is there a way to tell CMAKE to print the ABSOLUTE path to the file instead?

Question #2 - When CMAKE executes GMAKE …
how can I get Cmake to execute with “gmake -C ${SOMEDIR} target”
Instead of internal doing: “cd ${SOMEDIR} ; gmake target”

WHY?
simply put - there are tools that "automatically parse the output for errors.
VS Code is an example, as does Emacs when you “compile things”

Both tools then convert the ERROR messages into “clickable links” to take you to the issue.

OPTION 1 - The clickable error link involves an ABSOLUTE path or RELATIVE PATH

ABSOLUTE Paths are easy… relative paths depend on the current directory
GMAKE - if you use “-C ${DIRNAME}” - will print

Entering directory '${SOMEDIR}' 
Leaving directory '${SOMEDIR}'

Smart tools - track / search for these messages and then use these messages to help find or track the state of the current directory - and thus - it makes the CLICKABLE errors usable

EMACS reference link:

VIM - has similar features known as :cnext and :cprevious

I don’t know how to find a Link for Visual Code…

For #1, not that I’m aware of. Source paths in error messages seem to always be relative to the CMAKE_SOURCE_DIR. (They’re not actually dependent on the current working directory at all — if you run cmake -B /some/build/dir -S /some/source/dir from anywhere, any messages output involving a CMakeLists.txt file will be relative to /some/source/dir.)

But I can certainly see how having an option to output absolute paths could be useful.

On #2, I doubt you can because… well, two reasons:

  1. make is only one of several buildsystems for CMake,
  2. (because of that) The Makefiles being run by make aren’t actually located in the build directory for the target being built.

When you generate a CMake build system (out-of-tree, so say in a directory named _build) that includes a binary target foo, say in directory src/foo/, CMake doesn’t generate a Makefile to build foo in src/foo, or even in _build/src/foo. Most likely, it generates a build.make file in _build/src/foo/CMakeFiles/foo.dir/, then does this from _build/src/foo/Makefile:

foo.c.o:
        cd /path/to/build/root && $(MAKE) $(MAKESILENT) \
        -f src/foo/CMakeFiles/foo.dir/build.make \
        src/foo/CMakeFiles/foo.dir/foo.c.o
.PHONY : foo.c.o

This is partly because, like I said, make isn’t the only option for build tools. So, CMake itself handles the recursion and parallelism in the build tree in a standard way, rather than leaving it to the build tool.

So, what you’ll see with a “Makefile Generator” build system is a lot of “Entering directory ‘/path/to/build/root’”, followed by cd /path/to/build/root/src/foo && <compile /path/to/src/foo/foo.c into foo/CMakeFiles/foo.dir/foo.cpp.o>

…But both the compiler command lines and its error messages should be using absolute paths to input files, so those “Entering” messages are really meaningless and the messages can be parsed without them.

Those paths kind of have to be absolute, because with CMake you’re doing out-of-source builds (or SHOULD be!). So when you hit a compilation error in /path/to/src/foo/foo.c, it doesn’t matter if the current working directory for that compile is /path/to/build/root or /path/to/build/root/src/foo. Either way, the source file in question isn’t located anywhere relative to that directory.