An example of trying to use modern CMake practices, it includes:
- MyApp - a top-level application that depends on the two libraries
- MyLib - a simple library that doesn't create a cmake config, so requires extra effort in MyApp
- ThirdPartyLib - a library that creates a cmake config and, thus, doesn't require extra effort
- MyHeaderLib - a header-only library that creates a cmake config and, thus, doesn't require extra effort
mkdir _build
cd _build
# To configure for a release build
cmake -DCMAKE_BUILD_TYPE=Release ..
# To configure for a debug build
cmake -DCMAKE_BUILD_TYPE=Debug ..
# To configure for a shared build
cmake -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug ..
# Linux
make
sudo make install
# Win32 command line
cmake --build .
mkdir _build
cd _build
# To configure for a release build
cmake -DCMAKE_BUILD_TYPE=Release ..
# To configure for a debug build
cmake -DCMAKE_BUILD_TYPE=Debug ..
# To configure for a shared build
cmake -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug ..
# Linux
make
sudo make install
# Win32 command line
cmake --build .
mkdir _build
cd _build
# Build
cmake ..
# Linux
# Call make to generate cmake config
make
sudo make install
- Not setting the CMake build type doesn't necessarily mean it builds debug - it may build an empty build type (depends on the compiler and linker). It is better to be explicit.
- In terms of libraries, PUBLIC means the everything can access it, PRIVATE means only the library itself can access it and INTERFACE means that everything but the library can access it.