{"id":1923,"date":"2026-05-16T00:03:22","date_gmt":"2026-05-16T00:03:22","guid":{"rendered":"https:\/\/jaimerios.com\/?p=1923"},"modified":"2026-05-16T00:03:22","modified_gmt":"2026-05-16T00:03:22","slug":"c-package-management-using-vcpkg","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=1923","title":{"rendered":"C++ package management using vcpkg"},"content":{"rendered":"\n<p>The below are instructions for setting up vcpkg in a CMake based C++ project. I&#8217;ve done this enough times to warrant a post on this site, that I can look up quickly instead of having to load up my notes app.<\/p>\n\n\n\n<p><strong>Steps<\/strong><\/p>\n\n\n\n<p>1 &#8211; Create a folder named ThirdParty, if it doesn&#8217;t already exist.<\/p>\n\n\n\n<p>2 &#8211; Add vcpkg to that newly created folder, as a git submodule<\/p>\n\n\n\n<p><code>git submodule add <a href=\"https:\/\/github.com\/Microsoft\/vcpkg.git\">https:\/\/github.com\/Microsoft\/vcpkg.git<\/a> ThirdParty\/vcpkg<\/code><\/p>\n\n\n\n<p>3 &#8211; Add the submodule to your git repo<\/p>\n\n\n\n<p><code>git add ThirdParty\/vcpkg .gitmodules<br>git commit -m \"Add vcpkg as submodule in ThirdParty\"<br>git push <\/code><\/p>\n\n\n\n<p>4 &#8211; Initialize the git submodule and run the bootstrap process<\/p>\n\n\n\n<p><code>git submodule update --init --recursive<br>cd ThirdParty\/vcpkg<br>.\/bootstrap-vcpkg.sh<\/code><br><\/p>\n\n\n\n<p>5 &#8211; Build the CMake project, using the vcpkg cmake file to tell the project where the dependencies are:<\/p>\n\n\n\n<p><code>cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=ThirdParty\/vcpkg\/scripts\/buildsystems\/vcpkg.cmake [other flags]<\/code><\/p>\n\n\n\n<p><strong>Note<\/strong>, to add packages to the project, run the following commands:<\/p>\n\n\n\n<p><code>.\\ThirdParty\\vcpkg\\vcpkg.exe new --application<br>vcpkg add port opencv<\/code><\/p>\n\n\n\n<p><strong>Note<\/strong>, to have the bootstrap process run as part of the CMake configuration process, add the following CMake code to your topmost CMakeLists.txt file:<\/p>\n\n\n\n<p><code>if(CMAKE_HOST_SYSTEM_NAME STREQUAL \"Windows\")<br>    set(bootstrap_vcpkg_ext \"bat\")<br>else()<br>    set(bootstrap_vcpkg_ext \"sh\")<br>endif()<br><br>execute_process(<br>    COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}\/ThirdParty\/vcpkg\/bootstrap-vcpkg.${bootstrap_vcpkg_ext}\"<br>    RESULT_VARIABLE bootstrap_vcpkg_result<br>)<br><br>if(NOT bootstrap_vcpkg_result EQUAL 0)<br>    message(FATAL_ERROR \"Bootstrapping failed with code: ${bootstrap_vcpkg_result}\")<br>else()<br>    message(STATUS \"Bootstrapping succeeded.\")<br>endif()<br><br>set(CMAKE_TOOLCHAIN_FILE \"${CMAKE_CURRENT_SOURCE_DIR}\/ThirdParty\/vcpkg\/scripts\/buildsystems\/vcpkg.cmake\"<br>CACHE STRING \"vcpkg toolchain file\")<\/code><\/p>\n\n\n\n<p><strong>Note<\/strong>, The project definition has to come after the CMAKE_TOOLCHAIN_FILE variable declaration. This will trip you up if this is not in the right place.<\/p>\n\n\n\n<p><strong>Note<\/strong>, vcpkg may try to install packages on every file change or any change to CMakeLists.txt. If the packages are not changing between edits, consider setting the variable VCPKG_MANIFEST_INSTALL to &#8220;OFF&#8221;. This can be done as a variable in CMake or a setting in the CMakePresets.json file. For example:<\/p>\n\n\n\n<p><code>{<br>    \"version\": 6,<br>        \"cmakeMinimumRequired\": {<br><code>        <\/code>        \"major\": 3,<br><code>        <\/code>        \"minor\": 30,<br><code>        <\/code>        \"patch\": 0<br><code>        <\/code>},<br><code>    <\/code>\"configurePresets\": [<br><code>    <\/code>{<br><code>        <\/code>\"name\": \"vcpkg_defaults\",<br><code>        <\/code>\"cacheVariables\": {<br><code>        <\/code>\"VCPKG_MANIFEST_INSTALL\": \"OFF\"<br><code>      <\/code><\/code>    <code>}<\/code><br>[&#8230;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The below are instructions for setting up vcpkg in a CMake based C++ project. I&#8217;ve done this enough times to warrant a post on this site, that I can look up quickly instead of having to load up my notes app. Steps 1 &#8211; Create a folder named ThirdParty, if it doesn&#8217;t already exist. 2 &#8230; <a title=\"C++ package management using vcpkg\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=1923\" aria-label=\"Read more about C++ package management using vcpkg\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1923","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/1923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1923"}],"version-history":[{"count":1,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/1923\/revisions"}],"predecessor-version":[{"id":1924,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/1923\/revisions\/1924"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}