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?
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.
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 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?
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.
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.