This is a template for building a C++ plugin as a shared-lib/DLL/CFBundle. It uses Conan for dependencies and CMake as the build generator. It's intended to show best practices for using modern (as of 2024) cmake, 3.28 or later, and Conan v2.
It uses the new-for-2024 conan-cmake integration, where cmake calls
conan to install the dependencies and then configure the build. A copy
of that integration is included in this repo as
conan_provider.cmake
.
To build the plugin, use ./build.sh.
This runs cmake --preset Release
to configure, and then
cmake --build --preset Release
to do the build using the
configured build tool (cmake's default is Makefiles).
The configure step invokes conan
to build/install the dependencies.
In this template, I've used the spdlog
logging framework based on
fmt
as a sample dependency, just to show how the system works.
The CMakePresets.json
default preset is configured to include the
conan-cmake provider which makes cmake invoke
conan to install the dependencies and pass along all the necessary
generator, compiler info, etc.
-
To use a different generator, e.g. "Ninja Multi-Config":
cmake --preset default -G "Ninja Multi-Config" cmake --build --preset default --config Debug cmake --build --preset default --config Release
(this is in build-ninja.sh)
-
To do a build with a manual
conan install
invocation, do it like this:conan install . --build=missing cmake --preset conan-release # or on Windows, cmake --preset conan-default, because VS is multi-config cmake --build --preset conan-release
and to build in debug mode, do this:
conan install . -s build_type=Debug --build=missing cmake --preset conan-debug # or on Windows, cmake --preset conan-default cmake --build --preset conan-debug
-
To do a multi-config build with manual
conan install
, do this:conan install . --build=missing -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" -s build_type=Debug conan install . --build=missing -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" cmake --preset conan-default cmake --build --preset conan-debug cmake --build --preset conan-release
(this is in build-conan-ninja.sh)
-
To do a clean build, remove the
build
directory, andCMakeUserPresets.json
. If you don't remove the presets file the build will fail becauseCMakeUserPresets.json
, which is generated by conan, refers to files inbuild
. Thebuild.sh
script will remove that preset file ifbuild
doesn't exist, to prevent that error.