Article directory
foreword
vcpkg collects a lot of C++ packages, but there are always some that are not included. Taking the openssl 3.0.0
version as an example, this version of vcpkg is not included. This tutorial will teach you how to add custom vcpkg
New overlay-ports
overlayports
Create a folder named in the vcpkg root directory (in fact, you can name it arbitrarily, and the following tutorials will use this as an example), overlayports
and create two new folders in , respectively ports
,versions
# overlayports目录结构
├─ports
│ └─openssl
└─versions
└─o-
│ └─openssl.json
└─baseline.json
Write baseline.json
Create overlayports/versions
a new directory baseline.json
and save the following content
{
"default": {
"openssl": {
"baseline": "3.0.0",
"port-version": 0
}
}
}
port-version
It comes from version control, and the default is 0. For example, 3.0.0 has two minor versions, which are 0 and 1 respectively.
Write openssl.json
Because openssl starts with the letter o, so overlayports/versions
create a new folder in the directory o-
, o-
create a new folder in the folderopenssl.json
{
"versions": [
{
"git-tree": "3e5163bcf41573dd2bc14130db52e77599f4132d",
"version": "3.0.0",
"port-version": 0
}
]
}
git-tree
The field needs to be the hash of the commit, but it can also be filled in at will
git add ports/openssl
git commit -m "ports: add openssl"
git rev-parse HEAD:ports/openssl
This can be calculated
write configuration
For this, I suggest copying the entire folder ports
from the original directly.openssl
Modify vcpkg.json
version
Change it to 3.0.0
, port-version
change the key value to 0
, and keep the others unchanged.
{
"name": "openssl",
"version": "3.0.0",
"port-version": 1,
"description": "OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.",
"homepage": "https://www.openssl.org",
"license": "Apache-2.0",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "vcpkg-cmake-get-vars",
"host": true
}
],
"features": {
"tools": {
"description": "Install openssl executable and scripts",
"supports": "!uwp"
}
}
}
Modify portfile.cmake
This change is a bit big, and some commands are designed. For example, the openssl on github does not upload the 3.0.0 code, but the official website. It is used to vcpkg_from_github
pull the source code, so it needs to be changed to vcpkg_download_distfile
., the original patch is not available, You need to use additional vcpkg_extract_source_archive
commands to patch, and SHA512 needs to be downloaded to the local calculation to obtain
(Get-FileHash .\openssl-3.0.0.tar.gz -Algorithm SHA512 | Format-List).Hash.ToLower()
- just save
if(EXISTS "${CURRENT_INSTALLED_DIR}/share/libressl/copyright"
OR EXISTS "${CURRENT_INSTALLED_DIR}/share/boringssl/copyright")
message(FATAL_ERROR "Can't build openssl if libressl/boringssl is installed. Please remove libressl/boringssl, and try install openssl again if you need it.")
endif()
if(VCPKG_TARGET_IS_EMSCRIPTEN)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()
if (NOT "${VERSION}" MATCHES [[^([0-9]+)\.([0-9]+)\.([0-9]+)$]])
message(FATAL_ERROR "Version regex did not match.")
endif()
set(OPENSSL_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(OPENSSL_VERSION_MINOR "${CMAKE_MATCH_2}")
set(OPENSSL_VERSION_FIX "${CMAKE_MATCH_3}")
configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake.in" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY)
vcpkg_download_distfile(
ARCHIVE
URLS "https://www.openssl.org/source/old/3.0/openssl-${VERSION}.tar.gz"
FILENAME "openssl-${OPENSSL_VERSION}.tar.gz"
SHA512 1fdf769ef69631eb802671a9e0bb3a01883d58282f651986212983c2d7c9d3499dabe99a6dee0411e997e6fcfa6f682b121b7698596de0d6c78850c2200241b1
)
vcpkg_extract_source_archive(
SOURCE_PATH
ARCHIVE "${ARCHIVE}"
PATCHES
disable-apps.patch
disable-install-docs.patch
script-prefix.patch
windows/install-layout.patch
windows/install-pdbs.patch
unix/android-cc.patch
unix/move-openssldir.patch
unix/no-empty-dirs.patch
unix/no-static-libs-for-shared.patch
)
vcpkg_list(SET CONFIGURE_OPTIONS
enable-static-engine
enable-capieng
no-ssl3
no-weak-ssl-ciphers
no-tests
)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_list(APPEND CONFIGURE_OPTIONS shared)
else()
vcpkg_list(APPEND CONFIGURE_OPTIONS no-shared no-module)
endif()
if(NOT "tools" IN_LIST FEATURES)
vcpkg_list(APPEND CONFIGURE_OPTIONS no-apps)
endif()
if(DEFINED OPENSSL_USE_NOPINSHARED)
vcpkg_list(APPEND CONFIGURE_OPTIONS no-pinshared)
endif()
if(OPENSSL_NO_AUTOLOAD_CONFIG)
vcpkg_list(APPEND CONFIGURE_OPTIONS no-autoload-config)
endif()
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
include("${CMAKE_CURRENT_LIST_DIR}/windows/portfile.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/install-pc-files.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/unix/portfile.cmake")
endif()
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${SOURCE_PATH}/LICENSE.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
mount installation
When executing the vcpkg installation command, you need to enter the path to mount
vcpkg install --overlay-ports=overlayports/ports/openssl openssl:x64-windows-static
- Log
PS E:\vcpkg> vcpkg install --overlay-ports=overlayports/ports/openssl openssl:x64-windows-static
Computing installation plan...
The following packages will be built and installed:
openssl[core]:x64-windows-static -> 3.0.0 -- E:\vcpkg\overlayports/ports/openssl
Detecting compiler hash for triplet x64-windows-static...
-- Automatically setting HTTP(S)_PROXY environment variables to "127.0.0.1:7890".
Restored 0 package(s) from C:\Users\NueXini\AppData\Local\vcpkg\archives in 114 us. Use --debug to see more details.
Installing 1/1 openssl:x64-windows-static...
Building openssl[core]:x64-windows-static...
-- Installing port from location: E:\vcpkg\overlayports/ports/openssl
-- Downloading https://www.openssl.org/source/old/3.0/openssl-3.0.0.tar.gz -> openssl-.tar.gz...
-- Extracting source E:/vcpkg/downloads/openssl-.tar.gz
-- Applying patch disable-apps.patch
-- Applying patch disable-install-docs.patch
-- Applying patch script-prefix.patch
-- Applying patch windows/install-layout.patch
-- Applying patch windows/install-pdbs.patch
-- Applying patch unix/android-cc.patch
-- Applying patch unix/move-openssldir.patch
-- Applying patch unix/no-empty-dirs.patch
-- Applying patch unix/no-static-libs-for-shared.patch
-- Using source at E:/vcpkg/buildtrees/openssl/src/openssl--79f2f1128b.clean
-- Found external ninja('1.11.0').
-- Getting CMake variables for x64-windows-static
-- Getting CMake variables for x64-windows-static
-- Prerunning x64-windows-static-dbg
-- Building x64-windows-static-dbg
-- Prerunning x64-windows-static-rel
-- Building x64-windows-static-rel
-- Fixing pkgconfig file: E:/vcpkg/packages/openssl_x64-windows-static/lib/pkgconfig/libcrypto.pc
-- Fixing pkgconfig file: E:/vcpkg/packages/openssl_x64-windows-static/lib/pkgconfig/libssl.pc
-- Fixing pkgconfig file: E:/vcpkg/packages/openssl_x64-windows-static/lib/pkgconfig/openssl.pc
-- Using cached msys-mingw-w64-i686-pkg-config-0.29.2-3-any.pkg.tar.zst.
-- Using cached msys-mingw-w64-i686-libwinpthread-git-9.0.0.6373.5be8fcd83-1-any.pkg.tar.zst.
-- Using msys root at E:/vcpkg/downloads/tools/msys2/9a1ec3f33446b195
-- Fixing pkgconfig file: E:/vcpkg/packages/openssl_x64-windows-static/debug/lib/pkgconfig/libcrypto.pc
-- Fixing pkgconfig file: E:/vcpkg/packages/openssl_x64-windows-static/debug/lib/pkgconfig/libssl.pc
-- Fixing pkgconfig file: E:/vcpkg/packages/openssl_x64-windows-static/debug/lib/pkgconfig/openssl.pc
-- Installing: E:/vcpkg/packages/openssl_x64-windows-static/share/openssl/usage
-- Installing: E:/vcpkg/packages/openssl_x64-windows-static/share/openssl/copyright
-- Performing post-build validation
Stored binary cache: "C:\Users\NueXini\AppData\Local\vcpkg\archives\52\52725e8d8c97f33f16c3d5b775ac6942aa930813223f43e0faa0b77d8af5b265.zip"
Elapsed time to handle openssl:x64-windows-static: 2 min
Total install time: 2 min
The package openssl is compatible with built-in CMake targets:
find_package(OpenSSL REQUIRED)
target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
This completes the installation of openssl3.0.0
Afterword
The above is all the tutorials for vcpkg to add custom package installation. If you still don’t understand, you can refer to the following article:
enjoy ~