Cmake warnings as error

I am trying to stop cmake from continuing generation if it outputs a warning, i.e. treat all warnings as errors and stop.
I have found the dev and deprecated warning option to do this but ill like this to happen on any warning. e.g. i have sometimes unused variables/options which outputs a cmake warning, to prevent anyone from passing unused variables to the generation i like to enable such an option.

Anyone know how to do this?

2 Likes

Perhaps you want CMAKE_ERROR_DEPRECATED?

cmake ... -D CMAKE_ERROR_DEPRECATED=ON

I am looking for a more general option, something like: CMAKE_WARN_AS_ERROR. the deprecated error/warning only stops on that type. Sometimes you pass an unused variable to cmake and that would output a warning which i like to prevent. if you do:

cmake -DMY_UNUSED_VAR=true

it will output

“CMake Warning: Manually-specified variables were not used by the project: MY_UNUSED_VAR”

I would like to make that warning an error, any any other CMake Warning.

Just registered to this forum for this topic.
I have exactly the same needs as @chrilleman . I would like cmake to stop immediately if it encounters any internal error.
This is to prevent erroneous user parameter settings. Our current project has ~20 sub-directires and we have to manage ~40 custom options. Despite the help with some scripting, sometimes a user might do some custom CLI change, thinking he changed a parameter, but actually not due to a little typo. This has happened for more than 3 time for our team. It would be very helpful if I can set the CMakeLists.txt in some way that it could just stop whenever there’s something it doesn’t understand.

We have also had cases where with circular dependencies with the same files listed as both output and input to a custom command. This gave a warning and unwanted build result. In this case it would have been nice if CMake could stop and not let this pass “unnoticed”…