VCPKG Setup with CMake

Setting up VCPKG with CMake

This is a quick look up blog post for setting up vcpkg with CMake. This is something I often do, when setting up c++ projects.

Installing vcpkg

Clone Repo
git clone https://github.com/microsoft/vcpkg.git

Run Bootstrap Script

cd vcpkg && ./bootstrap-vcpkg.sh

Setting up Project

export VCPKG_ROOT=/path/to/vcpkg
export PATH=$VCPKG_ROOT:$PATH

Creating Project Directory

mkdir helloworld && cd helloworld

Creating vcpkg manifest file

vcpkg new --application

Adding Dependency

vcpkg add port fmt

CMake Starter file

cmake_minimum_required(VERSION 3.10)

project(HelloWorld)

find_package(fmt CONFIG REQUIRED)

add_executable(HelloWorld helloworld.cpp)

target_link_libraries(HelloWorld PRIVATE fmt::fmt)

Sample App Code

#include <fmt/core.h>

int main()
{
    fmt::print("Hello World!\n");
    return 0;
}

Building the app

cd build 
cmake ..
make