Cmake build error hook

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

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.

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

Actually I understand that now it could not work.

Reason not to use CONFIGURE_DEPENDS is that makes building slow.

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.

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.

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.