Is there a way to show an add_subdirectory() compile failure from a long list of add_subdirectory() instances?

My scenario is as follows.

I have an example folder with 20+ examples in it. Each example is separated into it’s own sub-folder with it’s own CMakeLists.txt file, source/include folder, etc.

Examples
├───Ex1
│   ├───include
│   └───source
├───Ex2
│   ├───include
│   └───source
├───Ex3
│   ├───include
│   └───source
...
├───Ex20
│   ├───include
│   └───source
└───EX21
    ├───include
    └───source

I have a top level CMakeLists.txt file under Examples. That file is basically a bunch of add_subdirectory() calls to all the Ex# subdirectories.


I had a case where I ran

cmake --build .

The compile for Ex2 failed, but everything else succeeded. As anti-luck would have it I wasn’t watching the compile so I didn’t see the error message/failure scroll by.

Nothing in the final screen of output from the cmake command made me think that I had any failures earlier on, so I started to do next step action. Which eventually lead me to finding out that Ex2 actually failed to compile.

I know that I could have done the command

echo %ERRORLEVEL%

after running cmake --build ., however that’s not really a common practice when working with the cli. It is for scripts, but not manual CLI interaction.

Is there a method, a pattern, or a practice that I can use so that cmake will display a summary or some indicate of a failure at the end?