cd project cmake -B build cmake --build build # fails cd build make cd .. cmake --build build # succeeds
Error Message:
gmake[2]: *** No rule to make target ‘/d/home/skidmarks/Projects/Test/cmake/Modern_CMake/src/main.cpp’, needed by ‘src/CMakeFiles/HelloWorld.dir/main.cpp.o’. Stop.
gmake[1]: *** [CMakeFiles/Makefile2:106: src/CMakeFiles/HelloWorld.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
The order of commands (cmake --build build and make) is immaterial. cmake always fails until make is executed and always succeeds afterwards. Is there any reason for this?
Since you haven’t specified the generator, it probably defaults to Unix Makefiles, and you likely did not provide CMAKE_BUILD_TYPE for it either, so I would try that. If this doesn’t help, then maybe try using Ninja generator instead. And if that still fails, then I would blame the weird paths in Cygwin.
CMAKE_BUILD_TYPE is nowhere specified in the Tutorial Steps 1-4 nor in the Mastering Modern CMake book up to page 26 or in the Modern CMake book.
Where is CMAKE_BUILD_TYPE defined in the Tutorial? And if it is needed in order to execute a cmake --build why isn’t it defined?
The failures I see are in the Tutorial Steps and in the Mastering Modern CMake book. You are correct in that the (undefined) default generator is used, that is, I don’t remember seeing any notion of defined generators in Step 0-4 of the Tutorial and I assume that what you are saying is correct from experimentation.
It is up to you (developer) to choose a generator and a build type, CMake cannot guess for you. Although I somewhat agree that if it does default to Unix Makefiles, then why doesn’t it also default to some build type instead of going with an undefined one - in that case it would be better (consistent?) to fail right away with something like “You haven’t set a generator!”.
Referencing something in Step 0 is not a definition. If you follow all the references you spend hours chasing elements. Which brings to mind that the tutorial is ill-defined. And I have followed many references and it has taken hours and I wonder what the tutorial is meant to show. And I have looked at the language manual and I find it mainly deficient.
The tutorial is supposed to guide me. It is the 1990’s Teach by Example (TBE). You say I should read the referenced link and decide what to do with the information therein, but this makes it unclear what the tutorial is supposed to teach. I mean, how do you expect me to discover the critical nature of CMAKE_… when the tutorial never addresses it and looking at the referenced documents I have no way to determine what is important or relevant because I am trying to learn the system. You are effectively saying that in order to learn the system I have to know the system.
Based on your comments I have looked at CMAKE_… . It is nowhere indicated that the effect of not using it will cause cmake --build to fail. Instead it says a default value will be provided, which may be blank, “”, but in this case no default action is provided. But no failure modes are given. In other words, the document says by default that if CMAKE_… is not used that the CMake will se to supplying a correct value.
Could you explain how a default value will produce a failure for a C++ compile/build? Are you saying that the default value is in error? Are you saying that no suitable default will be provided? Are you saying that the documentation for CMAKE_… is faulty and the tutorial is faulty for not describing it as a requirement.