This example project provides the boilerplate and a potential starting point for a C++ project that utilizes the CMAKE build system, VCPKG package manager, and PMM package manager manager.
This sample project uses PMM to automatically bootstrap VCPKG, download the required packages, and integrate the packages into CMAKE when CMAKE is run. The main build target executable source code, which utilizes the FMT library, can be found in src/main.cpp
.
Please consult the documentation for CMAKE, VCPKG, PMM, and FMT for more details.
- Git
- CMAKE version 3.2 or later
- C++17 compiler
The following steps assume you're using a Linux OS, but the steps for a Windows OS should be similar, except for potentially the directory structure generated by the build.
-
Clone the repository
$
git clone https://github.com/ariveron/boilerplate-pmm-vcpkg-cmake
-
Go into the repo directory
$
cd boilerplate-pmm-vcpkg-cmake
-
Run CMAKE to create the build files
$
cmake .
-
Use CMAKE to build the project
$
cmake --build .
-
You should now be able to run the program
$
./bin/main
The answer is 42
In the root level CMakeLists.txt
file, within the pmm
CMAKE function, you can see where the VCPKG REVISION
is specified as the master
branch of the VCPKG repositor. You can change this to a revision or a tag so that the VCPKG version used is the same on every build.
Within the pmm
cmake function you'll also notice the list of required VCPKG packages after the REQUIRES
keyword. In this example the only package specified is fmt
. This should be a space-seperated list of VCPKG names.
You should consult the documentation for each package. Typically, you'll be able to bring in the package into CMAKE by using the find_package
cmake function. In the case of the FMT library, we can add it to the main
target (src/CMakeLists
) using the target_link_libraries
CMAKE function.
If you're going to be using this template as a starting point for your project, simply add and remove packages and libraries from the CMakeLists.txt
files as needed. You may also want to change the CMAKE project name and create a new git repository for it at the very least.