On 5/31/2021 3:24 AM, Alexander Grund via Boost wrote:
OK, I will bite <g>.
// Beginning of rant
The difficulty of specifying a compiler to use with CMake, compared with the elegance of b2's toolset definitions, makes me really wonder why the majority of the C++ world considers CMake anything but software gone terribly wrong. I know b2 has some abstruse weaknesses, but specifying a toolset/definition is not one of them. Maybe I have missed something but I certainly do not see how some CMake generator equates to a particular compiler other than the Visual C++ generators, where each generator name equates to a particular version of VC++. There must be more I am missing but there is not anything in the CMake documentation I can find which explains to me how I can specify, for instance, a particular version of mingw-w64 gcc or clang on Windows for CMake to use. The explanation for the CMake generators at https://cmake.org/cmake/help/v3.20/manual/cmake-generators.7.html#manual:cma...) is so pathetic that if I did not know the majority of C++ programmers swear by CMake I would really have thought that such software documentation would have doomed such software for popular use eons ago.
// End of rant
I'll bite back ;-)
CMake has 2 levels of things you specify because CMake is not a build system (as B2, make, ninja, ...) but a buildsystem generator. In short:
- With "-G" you choose the build system to generate files for, e.g. VS Solutions, Makefiles, Ninja configs, ... - With CMAKE_<lang>_COMPILER you choose the compiler to use, e.g. `cmake -DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_C_COMPILER=gcc-10 ...`
The defaults if unset are chosen reasonably. E.g. for make/ninja (make is the default) it chooses $CC/$CXX (and maybe some fallbacks such es `cc`) and for the VS generators it chooses the VS compiler for that version.
What do you gain from this? By switching the generator (and nothing else) you can develop your project in whatever you want. E.g. VS, VScode, vim (with a language server), ... I find that quite powerful, especially if you need to develop on Windows. So for that CMake is better than B2.
However I agree that for building/testing alone B2 is clearly superior.
So yeah, CMake is a tool, it has strengths and weaknesses and has some historic backage due to the need to be backwards compatible (just as C++ has...)
My beef is that the CMake documentation does not tell you what compilers a particular generator supports, except for the Visual Studio generators. Period. It is not the process but the lack of documentation. The lack of documentation is noticeable because I think the average programmer will first ask: What compiler can I use to do X, Y, and Z, and how do I specify commands to that compiler. That seems perfectly natural to me and the fact that one uses -DCMAKE_CXX_COMPILER with the path to the compiler and options separated by semicolons, is lost amidst the welter of basic explanations about generators.