CMake

Modern CMake

Shown to me by Kajanan.

There are so many things to understand

C++ Flags

  • Disable Compiler Extensions: set(CMAKE_CXX_EXTENSIONS OFF) instructs CMake to use the standard-compliant version of the C++ language without any compiler-specific extensions. It promotes portability of your code across different compilers.

https://cliutils.gitlab.io/modern-cmake/

Instead of this,

~/package $ mkdir build
~/package $ cd build
~/package/build $ cmake ..
~/package/build $ make

You can replace the make line with cmake --build . if you’d like, and it will call make or whatever build tool you are using. If you are using a newer version of CMake (which you usually should be, except for checking compatibility with older CMake), you can instead do this:

~/package $ cmake -S . -B build
~/package $ cmake --build build

I don't like this

It’s essentially specifying that all of the build is inside the build folder, but you don’t have to cd into it.