Skip to content

Makefiles: Explicitly tell 'make' tool what Makefile name to use

CMake did not specify the filename of the Makefile generated by it. Due to GNU make precedence rules this means that the presence of a GNUmakefile or makefile would take precedence over the generated Makefile.

This is only relevant for in-source builds and only whenever an alternative makefile by the above mentioned names exists.

This patch adds the (seemingly universal) -f switch and the (hardcoded) filename (it is now hardcoded separately in these two files):

  • cmLocalUnixMakefileGenerator3.cxx
  • cmGlobalUnixMakefileGenerator3.cxx

Fixes: #21418 (closed)


NB: I'll be happy to add a test, but I'd need some guidance (see my comment in #21418 (closed), if this is desired).

The only test (aside from running the test suite with ctest) I did right now was to verify that indeed in the presence of a GNUmakefile the Makefile generated by CMake will get picked up.

[2] os@host:~/CMake/build/test$ cmake --build .
g++     hello.cpp   -o hello
Hello from GNUmakefile
[2] os@host:~/CMake/build/test$ ../bin/cmake --build .
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello

The CMake in the PATH is a 3.18.4 I built myself from the respective tag. The ../bin/cmake is the patched one.

With best regards.

Edited by Brad King

Merge request reports