Can CMake use g++ to compile C files?

If you need to switch the whole project, set it in the project directive:

project(derproject LANGUAGES CXX)

To have cmake treat all C files as C++ files use:

file(GLOB_RECURSE CFILES "${CMAKE_SOURCE_DIR}/*.c")
SET_SOURCE_FILES_PROPERTIES(${CFILES} PROPERTIES LANGUAGE CXX )

You should not override the compiler for this purpose. If you really need to compile your C files as C++ then you should teach cmake that your files belong to C++ language:

set_source_files_properties(filename.c PROPERTIES LANGUAGE CXX )

Tags:

Gcc

G++

Cmake