Problem with set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)

CMake version: 3.31.6-msvc6

My top level cmake file says: set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
and a lower level cmake file says: set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)

But, when I try to build the project the lower level builds with the MSVC compiler option /WX which forces warnings to be errors which I don’t want to for that particular set of code.

What am I doing wrong please?

What applies is the value the variable has at the point a target is created. Are you setting it to OFF before creating the relevant target(s)?

I was setting as the first line in the lower level CMake file. In the end I removed the set (CMAKE_COMPILE_WARNING_AS_ERROR ON)from the top level CMake file.

D.