From the CMake file you provided, you can simply delete the CMAKE_CXX_FLAGS
line, or perhaps replace it with a C one like this:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
The rest of it should be fine, apart from renaming main.cpp to main.c as you said.