As of vwersion 3.19.8 I get -MD and -MT flags in my gcc makefile

As of from version 3.19.8 I get makefiles which introduce the -MD and -MT flags in my makefile. It then wants to find a file .d which might exsist, but is not supposed to be used by our (very old) gcc compiler.

The compiler does not understand these flags.

What caused Cmake to introduce these flags in my output?

These flags are used to compute effective dependencies of source files.
You can disable this behavior by setting variable CMAKE_DEPENDS_USE_COMPILER with value FALSE.

Can you specify which compiler you are using and on which platform?

CMake v3.20 introduced depfiles in Makefile generators.
In previous versions it’s only used for Ninja generator.

I guess you have used a newer CMake version. Otherwise you need to bisect to pin down the responsible CMake version or commit that causes you the problem.
Or you say “makefile” but mean “ninja build files”.

Hello Josef,

Thank you for the reply. I then indeed have a problem with the introduction (version 3.20) of the depfiles. The options for the depfiles are not (properly) supported by our pretty old gcc compiler. Is there a way to prevent the generation of these depency files and generate makefiles like V3.19.8 did?

I now see that Marc already provides the answer. I will try.

Thanks, This CMAKE_DEPENDS_USE_COMPILER with value FALSE indeed solved my issue.
I am still wondering why this option hasn’t been implemented the other way around: Default no change, set to True to have a change. That would have kept it backward compatible.

My guess:

  • it’s faster
  • it’s more accurate
  • it’s proven, as it’s used for Ninja for a long time
  • it’s supported by gcc for 23 years

I don’t know if a policy was forgotten, or such old gcc versions were simply not considered.

Probably this flag can be set to false automatically for gcc < 3 in CMake’s compiler modules.
This would make it compatible, without sacrifying the benefits for newer versions.

1 Like

Can an issue be filed about this so that it can be tracked?

Is it reasonable to fill an issue for the support of a compiler which is older than 23 years?

If it’s still in use…yes. (That’s why I ask others to file the issue; if that is too much burden, then it’s obviously not that big of a problem. It also ensures that someone with a stake in the problem is in any discussion of the issue right from the start.)

Try something like this:

option(CMAKE_DEPENDS_IN_PROJECT_ONLY "do not use system header files" YES)
if(CMAKE_DEPENDS_IN_PROJECT_ONLY)
  set(CMAKE_DEPFILE_FLAGS_C "-MMD" CACHE STRING "dependency flag" FORCE)
  set(CMAKE_DEPFILE_FLAGS_CXX "-MMD" CACHE STRING "dependency flag" FORCE)
else()
  set(CMAKE_DEPFILE_FLAGS_C "-MD" CACHE STRING "dependency flag" FORCE)
  set(CMAKE_DEPFILE_FLAGS_CXX "-MD" CACHE STRING "dependency flag" FORCE)
endif()

But be warned, CMAKE_DEPFILE_FLAGS_ are manipulated from many cmake modules!