Skip to content
Tobias Ulvgård edited this page Oct 8, 2018 · 8 revisions

CMake

The library can also be installed using CMake. Version of CMake must be 3.0+ and can be checked by --version:

> cmake --version
cmake version 3.3.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Generate

Generate project in _builds directory using CMakeLists.txt from current (.) directory, run one of the commands depending on the OS and generator you need:

> cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Release # Default generator is Makefile for *nix platform
> cmake -H. -B_builds -GXcode # Xcode generator on OS X (multi-config, no need for CMAKE_BUILD_TYPE)
> cmake -H. -B_builds "-GVisual Studio 12 2013" # Visual Studio IDE, Windows, multi-config

or toolchains:

> cmake -H. -B_builds -DCMAKE_TOOLCHAIN_FILE=/path/to/iOS.cmake -GXcode
> cmake -H. -B_builds -DCMAKE_TOOLCHAIN_FILE=/path/to/android.cmake -DCMAKE_BUILD_TYPE=Release

To add examples use SPDLOG_BUILD_EXAMPLES=ON option:

> cmake -H. -B_builds -DSPDLOG_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release

Build/test

Open generated project and run build/test targets. Also command line can be used too:

> cmake --build _builds --config Release
> cd _builds && ctest -VV -C Release

Install

Headers can be installed along with the config files so library can be found by find_package(spdlog CONFIG REQUIRED):

[spdlog]> cmake -H. -B_builds -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_BUILD_TYPE=Release
[spdlog]> cmake --build _builds --target install

Usage can be tested by building examples as a stand-alone project:

[spdlog/examples]> cmake -H. -B_builds -DCMAKE_PREFIX_PATH=/path/to/install -DCMAKE_BUILD_TYPE=Release
[spdlog/examples]> cmake --build _builds

Cross-compiling for Android with CMake 3.7

Cross-compiling with CMake is reported working using CMake version 3.7 which includes native support for configuring the toolchain with Android NDK and SDK (https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling-for-android). Please note that spdlog targets older versions of CMake and this example is a community contribution.

Below is an example on to configure and build spdlog using the Android NDK:

> git clone https://github.com/gabime/spdlog
> mkdir build
> cd build 
> cmake ../spdlog \
  -DCMAKE_SYSTEM_NAME=Android \
  -DCMAKE_SYSTEM_VERSION=21 \
  -DCMAKE_ANDROID_ARCH_ABI="armeabi-v7a" \
  -DCMAKE_ANDROID_ARM_NEON=ON \
  -DCMAKE_ANDROID_NDK=$HOME/Android/Ndk/android-ndk-r13b/
> cmake --build .

See the CMake documentation (link above) for the meaning of the CMake configuration options used in the example.