Wiki vcpkg
vcpkg
is cross-platform C/C++ package manager, and its peers include conan
.
The most common type of package is a C/C++ library consisting of headers, source code, and binaries.
Some useful folders in VCPKG_ROOT=/path/to/vcpkg
in vcpkg
:
How vcpkg
install fmt
library when calling vcpkg install fmt
in classic mode?
- Download the source code
fmt.tar.gz
into%VCPKG_ROOT%/downloads/
directory. - build tree ->
%VCPKG_ROOT%/buildtrees
:- Put the source code under
%VCPKG_ROOT%/buildtrees/fmt/src/xxxx-xxxx.clean/
directory. - Create building directory:
%VCPKG_ROOT%/buildtrees/fmt/arm64-osx-dynamic-rel/
(triplet
+release/debug
) and then start building
- Put the source code under
- package tree ->
%VCPKG_ROOT%/package
:- Package
fmt
built library likefmt.dylib
, itsheader
files andbinaries
(tools) in build tree into%VCPKG_ROOT%/packages/fmt_arm64-osx-dynamic/
- Package
- install tree ->
%VCPKG_ROOT%/installed
:- Install
fmt
'slibs
,headers
andtools
in package tree into%VCPKG_ROOT%/installed/arm64-osx-dynamic/lib
,%VCPKG_ROOT%/installed/arm64-osx-dynamic/include
and%VCPKG_ROOT%/installed/arm64-osx-dynamic/tools
respectively.
- Install
As it outlines, vcpkg
builds each package separately in build tree and package tree stages and finally in install tree stage reduce
all packages into the central set in %VCPKG_ROOT%/installed/arm64-osx-dynamic/
.
Classic mode
Official saying: In Classic mode, vcpkg maintains a central installed tree inside the vcpkg instance built up by individual vcpkg install
and vcpkg remove
commands. This central set of packages can then be shared by any number of projects.
All packages are installed in a common %VCPKG_ROOT%/installed
directory.
Classic mode how-to
Just run vcpkg install %package%
to use classic mode as the package will be installed into %VCPKG_ROOT%/installed/
.
Manifest mode
Official saying: In Manifest mode, vcpkg creates separate installed trees for each project and configuration. This allows separate projects to use different versions of libraries. The vcpkg.json
file and optional vcpkg-configuration.json
file form a project's manifest. The manifest declares the project's direct dependencies, version constraints, and registries used.
All packages are installed in their own ${project}/vcpkg_installed
directory inside the ${project}
directory.
Manifest mode how-to
Create vcpkg.json
in the project, then run vcpkg install
to use manifest mode as all the packages declared in vcpkg.json
will be installed into ${project}/vcpkg_installed/
.
Useful environment variables for development
CURRENT_INSTALLED_DIR
CURRENT_PACKAGES_DIR
set(VCPKG_RELEASE_LIBDIR "${CURRENT_INSTALLED_DIR}/lib")
set(VCPKG_DEBUG_LIBDIR "${CURRENT_INSTALLED_DIR}/debug/lib")
set(VCPKG_TOOLS_DIR "${CURRENT_INSTALLED_DIR}/tools")
set(VCPKG_SHARE_DIR "${CURRENT_INSTALLED_DIR}/share")
set(VCPKG_INCLUDE_DIR "${CURRENT_INSTALLED_DIR}/include")
Tips and Tricks
How to specify a compiler fof vcpkg install
?
As vcpkg
just use cmake
toolchain to do install, how to set a specific compile is cmake
things.
A fast way is use CC
and CXX
environment variables.
export CC=gcc-4.2
export CXX=/usr/bin/g++-4.2
See more ways at iar - How to specify a compiler in CMake? - Stack Overflow
Install *-osx-dynamic
vcpkg install libpq --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic
Reinstall packages without caching
vcpkg remove icu --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic
vcpkg install icu --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic --no-binarycaching
vcpkg install libpq --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic --binarysource=clear
vcpkg remove libpq --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic
vcpkg remove "qtbase[gui,widgets]" --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic
vcpkg install "qtbase[gui,widgets]" --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic --no-binarycaching
vcpkg install "qtbase[gui,widgets]" --host-triplet=arm64-osx-dynamic --triplet=arm64-osx-dynamic --binarysource=clear
Clean up all packages
rm -rf /opt/vcpkg/installed/
rm -rf /opt/vcpkg/packages/
rm -rf /opt/vcpkg/buildtrees/
Clean up all caching packages
rm -rf ~/.cache/vcpkg/archives/
INSTALL_RPATH_USE_LINK_PATH
different behaviours in manifest mode and classic mode
INSTALL_RPATH_USE_LINK_PATH
will not work properly when being used in the manifest mode, because CMake
will don't handle libraries located in buildtree
:
set_target_properties(${PROJECT_NAME} PROPERTIES
INSTALL_RPATH "@executable_path/../Frameworks"
INSTALL_RPATH_USE_LINK_PATH ON
)
After ${PROJECT_NAME}
installed, in the manifest mode:
❯ otoolll /Users/frankchen/Documents/vcpkg-qt-app/install/./helloworld.app/Contents/MacOS/helloworld
cmd LC_RPATH
cmdsize 48
path @executable_path/../Frameworks (offset 12)
After ${PROJECT_NAME}
installed, in the classic mode:
❯ otoolll /Users/frankchen/Documents/vcpkg-qt-app/install/./helloworld.app/Contents/MacOS/helloworld
cmd LC_RPATH
cmdsize 56
path /opt/vcpkg/installed/arm64-osx-dynamic/lib (offset 12)
Load command 27
cmd LC_FUNCTION_STARTS
--
cmd LC_RPATH
cmdsize 48
path @executable_path/../Frameworks (offset 12)
[wiki-cmake.mdx#RPATH in CMake](./wiki-cmake.mdx#RPATH in CMake)
Resources
TODO: Fix qtbase tools/config in release/debug osx
https://github.com/microsoft/vcpkg/tree/master/ports/qtbase
https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_cmake_config_fixup