打包存档文件示例:zlib

使用 create 启动

首先,找到库源代码的全局可访问存档。 Zip、gzip 和 bzip 均受支持。 强烈推荐官方来源或镜像而不是非官方镜像。

查看 zlib 的网站,URL http://zlib.net/zlib-1.2.13.tar.gz 看起来很合适。

其次,确定合适的包名称。 此项应为 ASCII、小写并且对了解库“人名”的用户可识别。 如果库已在另一个包管理器中打包,则首选该名称。

由于 zlib 已打包为 zlib,因此我们对本例使用名称 zlib2。

最后,如果存档的服务器名不是很有描述性(例如从 GitHub 下载压缩提交或分支),请选择 <packagename>-<version>.zip 形式的易记存档名。

zlib-1.2.13.zip 是一个易记的名称,因此无需更改。

然后,所有这些信息都可以传递到 create 命令中,该命令将下载源代码并在 ports/<packagename> 内启动打包过程。

PS D:\src\vcpkg> .\vcpkg create zlib2 http://zlib.net/zlib-1.2.13.tar.gz zlib-1.2.13.tar.gz
-- Downloading http://zlib.net/zlib-1.2.13.tar.gz -> zlib-1.2.13.tar.gz...
-- Generated portfile: D:\src\vcpkg\ports\zlib2\portfile.cmake
-- Generated manifest: D:\src\vcpkg\ports\zlib2\vcpkg.json
-- To launch an editor for these new files, run
--     .\vcpkg edit zlib2

创建清单文件

除了生成的 ports/<package>/portfile.cmake,我们还需要 ports/<package>/vcpkg.json 文件。 此文件是描述包元数据的一组简单字段。

对于 zlib2,我们将创建包含以下内容的文件 ports/zlib2/vcpkg.json

{
  "name": "zlib2",
  "version": "1.2.13",
  "description": "A Massively Spiffy Yet Delicately Unobtrusive Compression Library"
}

调整生成的端口文件

构建的 portfile.cmake 需要经过一些编辑才能正确打包大多数野生库,但我们可以从尝试构建开始。

PS D:\src\vcpkg> .\vcpkg install zlib2
Computing installation plan...
The following packages will be built and installed:
    zlib2[core]:x64-uwp
Starting package 1/1: zlib2:x64-uwp
Building package zlib2[core]:x64-uwp...
-- Using cached C:/src/vcpkg/downloads/zlib-1.2.13.tar.gz
-- Cleaning sources at C:/src/vcpkg/buildtrees/zlib2/src/1.2.13-deec42f53b.clean. Pass --editable to vcpkg to reuse sources.
-- Extracting source C:/src/vcpkg/downloads/zlib-1.2.13.tar.gz
-- Applying patch cmake_dont_build_more_than_needed.patch
-- Using source at C:/src/vcpkg/buildtrees/zlib2/src/1.2.13-deec42f53b.clean
-- Configuring x64-uwp
-- Building x64-uwp-dbg
-- Building x64-uwp-rel
-- Installing: C:/src/vcpkg/packages/zlib2_x64-uwp/share/zlib2/copyright
-- Performing post-build validation
Include files should not be duplicated into the /debug/include directory. If this cannot be disabled in the project cmake, use
    file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
/debug/share should not exist. Please reorganize any important files, then use
    file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
The software license must be available at ${CURRENT_PACKAGES_DIR}/share/zlib2/copyright
Found 3 error(s). Please correct the portfile:
    D:\src\vcpkg\ports\zlib2\portfile.cmake

此时,需要读取错误消息和日志文件,同时稳步提高端口文件的质量。 Zlib 需要提供 LICENSE 的离散副本标准版以复制到包中,禁止构建和安装可执行文件和标头,并在安装后移除静态库。

建议的示例端口文件

ports/ 目录中有许多可用作示例的库,包括许多不基于 CMake 的库。

  • 仅标头库
    • rapidjson
    • range-v3
  • 基于 MSBuild
    • chakracore
  • 非 CMake,自定义构建系统
    • openssl
    • ffmpeg