CMAKE_MAKE_PROGRAM 3.19 issue?

In my cmake toolchain I set the CMAKE_MAKE_PROGRAM.

To clarify I was setting my ninja executable like this:

if (CMAKE_GENERATOR MATCHES "Ninja")
        # Force update the program to allow updating the ninja version
        # Don't worry about bad builds
        # Ninja handles this update by starting over. Here is the error message ninja gave from
        # upgrading from version 1.7 -> 1.10
        # "ninja: warning: bad deps log signature or version; starting over"
        # This is why ninja is fantastic
        set(CMAKE_MAKE_PROGRAM "D:/foobar/ninja/1.10.0/ninja.exe" CACHE FILEPATH "" FORCE)
endif()

This seemed to work until cmake 3.19. And then I upgraded and this logic broke. Now I have to specify the CMAKE_MAKE_PROGRAM outside the toolchain.

Is there any reason why? Was I not supposed to be doing this?

1 Like

This is the error message I was getting:

CMake Error: CMake was unable to find a build program corresponding to “Ninja”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
– Configuring incomplete, errors occurred!

It is now ‘fixed’ by setting the CMAKE_MAKE_PROGRAM before the first project file outside of the toolchain.

To clarify more cmake wouldn’t even process my toolchain at all unless this was defined.

Where/when are you setting CMAKE_MAKE_PROGRAM? It would have to be set before the project() line in your CMakeFile.txt, I’m thinking, because the project() command is what triggers CMake to probe for compilers and etc. for all of the LANGUAGEs specified for the project.

So, if you’re setting it from the script, make sure it’s right at the top before the project() line. (You might even try setting it as a regular variable instead of a cache variable, or even explicitly setting it both ways.)

Since I see Windows paths in your command line, what environment are you running CMake in? MSYS2? Windows / Visual Studio?

I’m setting CMAKE_MAKE_PROGRAM in my toolchain file.

The toolchain is called before the project command:
https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html

Environment:
Windows
Ninja
MSVC

I have been able to replicate this problem where CMAKE_MAKE_PROGRAM is evaluated before parsing of the contents of the CMAKE_TOOLCHAIN_FILE file in 3.19 compared to 3.18.

@brad.king Do you know what would have caused this regression in 3.19?

1 Like

Cc: @kyle.edwards

This is due to commit d5b5c19278. I opened CMake Issue 21486 for this.

1 Like

I would actually appreciate the new behavior! I use FetchContent in my toolchain file to download the toolchain binaries (and yes, that works great). And with e.g. CMake 3.18, it complains that this variable wasn’t set, yet. Very unfortunate, actually.

Maybe you can try a combination of both and make the early try non-fatal.

Will this issue be fixed in a 3.19 patch or in cmake 3.20?

According to https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5529#note_d0154bec13f7881fe5fab20c765d61181c55dd06, the fix shoud have been part of 3.19.1, but it seems to have been missed/postponed.

The fix is in 3.19.1:

$ git describe --contains ef91fb02f3658954b631e46858e254008ca58132
v3.19.1~2^2

Does it still not work?

@brad.king apologies for the confusion.

Turns out I was having an extremely similar issue caused by FetchContent.

Which I still need to investigate/report properly. I can confirm this issue was fixed.

1 Like

After looking into this more. I’m not sure it was good to have made the changes you guys did for me.

Essentially the problem was me setting CMAKE_MAKE_PROGRAM in the toolchain.

The simple fix for this was to simply just add Ninja to the path. And that doesn’t require much effort on the developer.

Also a very similar issue occurs with FetchContent anyway. So we have to fix the toolchain code to not do that anyway, since the plan in the future is to grab the toolchain via FetchContent.

Overall what you guys had before was correct and I apologize.

My only suggestion being a slight change to the error message. So that users like me don’t take the incorrect course of action.

Error message:
CMake Error: CMake was unable to find a build program corresponding to “Ninja”.
Tip: Consider adding Ninja to your PATH so that CMake can find it.
CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
– Configuring incomplete, errors occurred!

If CMAKE_MAKE_PROGRAM is set in the main project, FetchContent passes that through to the underlying sub-build is uses to do the actual population. Setting that variable should be enough, you shouldn’t have to have Ninja on the PATH (and I often run without it on my PATH because of how environments are handled in a somewhat quirky way on macOS). If you have a minimal project which demonstrates a case where having CMAKE_MAKE_PROGRAM set doesn’t work, please open a new issue in CMake’s issue tracker and attach the project to it.

I’ll create a sample project and create a new thread to show the issue.

I’ve created the sample project and reproducible example: