Starting with cmake 3.20, a series of GNU-specific options are added to the compile lines, and I'm not sure why CMAKE_C_FLAGS does not remove them.
Prior to the release of cmake 3.20, those options were not added by default.
cmake_minimum_required(VERSION 3.20) project(TEST_SUITE) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_C_COMPILER customCCompiler) set(CMAKE_CXX_COMPILER customCXXCompiler) add_compile_options(-fjust-one-option) add_link_options(-ltest) file(GLOB C_C_FILES "/a/path/to/*.c") foreach(file ${C_C_FILES}) cmake_path(GET file STEM LAST_ONLY title) add_executable(${title} ${file}) endforeach() When ran with cmake /path/to/CMakeLists.txt, the config shows the following information:
-- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/user/path I get that in order to change the C compiler indentification from GNU to the customCCompiler, I would need to update the cmake command (which is currently ran without any other options other than the source directory of CMAkeLists.txt), what I don't get is why during compilation I am seeing -MD -MT -MF in the compile line:
[ 25%] Building C object CMakeFiles/fenv.dir/a/path/fev.c.o customCCompiler -fjust-one-option -MD -MT CMakeFiles/fenv.dir/a/path/fev.c.o -MF CMakeFiles/fenv.dir/a/path/fev.c.o.d -o CMakeFiles/fenv.dir/a/path/fev.c.o -c /a/path/fev.c warning: unsupported option -MD
project()call is wrong, see that my answer.