# CMake Error messages in a more clickable way.

**URL:** <https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431>\
**Category:** Code\
**Created:** [August 12, 2024, 3:25pm UTC](https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431 "2024-08-12T15:25:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![duaneellis\_inno](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@duaneellis\_inno](https://discourse.cmake.org/u/duaneellis_inno)\
**Post date:** [August 12, 2024, 3:25pm UTC](https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431/1 "2024-08-12T15:25:11Z")

</div>

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:

> <https://github.com/emacs-mirror/emacs/blob/master/lisp/progmodes/compile.el#L817>

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

> <https://stackoverflow.com/questions/1747091/how-do-you-use-vims-quickfix-feature>

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

---

<div class="post-metadata">

**Author:** ![ferdnyc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ferdnyc/32/267_2.png) [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)\
**Post date:** [August 14, 2024, 2:09pm UTC](https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431/2 "2024-08-14T14:09:29Z")

</div>

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 `Makefile`s 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`:

```make
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.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [July 25, 2025, 2:52pm UTC](https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431/3 "2025-07-25T14:52:46Z")

</div>

It should be possible to add error output parsing for CMake to the editors. Not sure how the top-level source directory would be retrieved just from the output though…
