# Cmake build error hook

**URL:** https://discourse.cmake.org/t/cmake-build-error-hook/3634
**Category:** Code
**Created:** [June 27, 2021, 8:05am UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634 "2021-06-27T08:05:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Christer\_Ekholm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/christer_ekholm/32/1584_2.png) [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)
#### Post date: [June 27, 2021, 8:05am UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/1 "2021-06-27T08:05:54Z")

</div>

Is it possible to add hooks to error in build?

My target is fixing automatically problem with “file(GLOB” what will cause linking error if new files are coming to system after Cmake is runned. Idea would be that build system rerun cmake if previous linking failed.

Perfect solution would be that I could run external command after failed build automatically.

One workaround could be that before linking build system will create file “linkingfailed.txt” and after linking file is deleted. If that file is available at next build then do GLOBing again

---

<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: [June 27, 2021, 12:51pm UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/2 "2021-06-27T12:51:51Z")

</div>

Build tools don’t provide such functionality generally, so CMake can’t provide any such guarantees. One could _maybe_ hook it up with GNU make, but I don’t know if that’s possible.

The solution is to either use `file(GLOB CONFIGURE_DEPENDS)`, but I recommend against `file(GLOB)` for source listing in [that situation as well](https://discourse.cmake.org/t/is-glob-still-considered-harmful-with-configure-depends/808/2).

---

<div class="post-metadata">

### Author: ![Christer\_Ekholm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/christer_ekholm/32/1584_2.png) [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)
#### Post date: [June 27, 2021, 12:54pm UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/3 "2021-06-27T12:54:45Z")

</div>

Cmake I can override default functions and then call original using \_ prefix. Could I override function what is doing linking?

---

<div class="post-metadata">

### Author: ![Christer\_Ekholm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/christer_ekholm/32/1584_2.png) [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)
#### Post date: [June 27, 2021, 12:55pm UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/4 "2021-06-27T12:55:45Z")

</div>

Actually I understand that now it could not work.

---

<div class="post-metadata">

### Author: ![Christer\_Ekholm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/christer_ekholm/32/1584_2.png) [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)
#### Post date: [June 27, 2021, 12:59pm UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/5 "2021-06-27T12:59:28Z")

</div>

Reason not to use CONFIGURE\_DEPENDS is that makes building slow.

---

<div class="post-metadata">

### Author: ![Christer\_Ekholm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/christer_ekholm/32/1584_2.png) [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)
#### Post date: [June 27, 2021, 1:18pm UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/6 "2021-06-27T13:18:48Z")

</div>

Best mitiation idea I have now is that I will add some githooks what will touch cmakefiles so that build system is regenerated always after pull, switch and checkout.

---

<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: [June 27, 2021, 8:42pm UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/7 "2021-06-27T20:42:57Z")

</div>

This still sounds very brittle. My recommendation is still to just list your sources in your CMake code explicitly; it has none of these problems.

---

<div class="post-metadata">

### Author: ![Christer\_Ekholm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/christer_ekholm/32/1584_2.png) [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)
#### Post date: [June 28, 2021, 11:43am UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634/8 "2021-06-28T11:43:21Z")

</div>

The only proplem is to run rebuild cache manually if new files comes system. Maybe I move to listing files schema after project get some maturity but now it would only cause many conflicts in merge or it cause that people stop adding files and starts writing everything to one file.
