首页 > 其他分享 >自定义vcpkg注册表(一)

自定义vcpkg注册表(一)

时间:2024-01-22 10:33:06浏览次数:40  
标签:src cmake TARGET 自定义 cgraph VCPKG 注册表 vcpkg

vcpkg提供自定义注册表的功能,主要用途可以是:公司私有库的注册表,自己对官方port的补充但是目前还不想提交到官方的port以及自己和官方对同一个库有不同的构建意见。

在自定义注册表中新建port

尽管我经常说vcpkg的本质是git和cmake的组合使用,但其实vcpkg还提供了vcpkg.exe和一整套相关的脚本,如果单纯按照官方博客所说的只建立一个vcpkg注册表且只包含ports和versions两个文件夹,使用是没有问题的,但是在创建过程中没法使用官方vcpkg已经提供的脚本了(create format 和 add version)。我能想到两种办法,一种是先在官方的vcpkg下利用官方脚本新增port调试然后拷贝到自定义注册表中,另一种就是在自己的注册表中实现一套脚本。

利用官方vcpkg新增port

CGraph为例, 先切一个官方vcpkg的分支

git checkout -b feature_add_cgraph

vcpkg.exe提供了相当多的脚本,但是create的命令只能适用于利用压缩包创建的情况

vcpkg create <port-name> <url-to-source> [archive-file-name]

vcpkg create cgraph https://github.com/ChunelFeng/CGraph/archive/refs/tags/v2.5.4.tar.gz cgraph-2.5.4.tar.gz

生成的模板为
portfile.cmake

# Common Ambient Variables:
#   CURRENT_BUILDTREES_DIR    = ${VCPKG_ROOT_DIR}\buildtrees\${PORT}
#   CURRENT_PACKAGES_DIR      = ${VCPKG_ROOT_DIR}\packages\${PORT}_${TARGET_TRIPLET}
#   CURRENT_PORT_DIR          = ${VCPKG_ROOT_DIR}\ports\${PORT}
#   CURRENT_INSTALLED_DIR     = ${VCPKG_ROOT_DIR}\installed\${TRIPLET}
#   DOWNLOADS                 = ${VCPKG_ROOT_DIR}\downloads
#   PORT                      = current port name (zlib, etc)
#   TARGET_TRIPLET            = current triplet (x86-windows, x64-windows-static, etc)
#   VCPKG_CRT_LINKAGE         = C runtime linkage type (static, dynamic)
#   VCPKG_LIBRARY_LINKAGE     = target library linkage type (static, dynamic)
#   VCPKG_ROOT_DIR            = <C:\path\to\current\vcpkg>
#   VCPKG_TARGET_ARCHITECTURE = target architecture (x64, x86, arm)
#   VCPKG_TOOLCHAIN           = ON OFF
#   TRIPLET_SYSTEM_ARCH       = arm x86 x64
#   BUILD_ARCH                = "Win32" "x64" "ARM"
#   DEBUG_CONFIG              = "Debug Static" "Debug Dll"
#   RELEASE_CONFIG            = "Release Static"" "Release DLL"
#   VCPKG_TARGET_IS_WINDOWS
#   VCPKG_TARGET_IS_UWP
#   VCPKG_TARGET_IS_LINUX
#   VCPKG_TARGET_IS_OSX
#   VCPKG_TARGET_IS_FREEBSD
#   VCPKG_TARGET_IS_ANDROID
#   VCPKG_TARGET_IS_MINGW
#   VCPKG_TARGET_EXECUTABLE_SUFFIX
#   VCPKG_TARGET_STATIC_LIBRARY_SUFFIX
#   VCPKG_TARGET_SHARED_LIBRARY_SUFFIX
#
# 	See additional helpful variables in /docs/maintainers/vcpkg_common_definitions.md

# Also consider vcpkg_from_* functions if you can; the generated code here is for any web accessable
# source archive.
#  vcpkg_from_github
#  vcpkg_from_gitlab
#  vcpkg_from_bitbucket
#  vcpkg_from_sourceforge
vcpkg_download_distfile(ARCHIVE
    URLS "https://github.com/ChunelFeng/CGraph/archive/refs/tags/v2.5.4.tar.gz"
    FILENAME "cgraph-2.5.4.tar.gz"
    SHA512 b52e6c8387eb56b02acf5f4d5ae76104885feb7da69fed833967b7fcfea41755d3a9f7c9d4c8edc3356c0df9c3ef036ab191b85c5b889add3c8b4467fb78d4c9
)

vcpkg_extract_source_archive_ex(
    OUT_SOURCE_PATH SOURCE_PATH
    ARCHIVE "${ARCHIVE}"
    # (Optional) A friendly name to use instead of the filename of the archive (e.g.: a version number or tag).
    # REF 1.0.0
    # (Optional) Read the docs for how to generate patches at:
    # https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/examples/patching.md
    # PATCHES
    #   001_port_fixes.patch
    #   002_more_port_fixes.patch
)

# # Check if one or more features are a part of a package installation.
# # See /docs/maintainers/vcpkg_check_features.md for more details
# vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
#   FEATURES
#     tbb   WITH_TBB
#   INVERTED_FEATURES
#     tbb   ROCKSDB_IGNORE_PACKAGE_TBB
# )

vcpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}"
    # OPTIONS -DUSE_THIS_IN_ALL_BUILDS=1 -DUSE_THIS_TOO=2
    # OPTIONS_RELEASE -DOPTIMIZE=1
    # OPTIONS_DEBUG -DDEBUGGABLE=1
)

vcpkg_cmake_install()

# # Moves all .cmake files from /debug/share/cgraph/ to /share/cgraph/
# # See /docs/maintainers/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.md for more details
# When you uncomment "vcpkg_cmake_config_fixup()", you need to add the following to "dependencies" vcpkg.json:
#{
#    "name": "vcpkg-cmake-config",
#    "host": true
#}
# vcpkg_cmake_config_fixup()

# Uncomment the line below if necessary to install the license file for the port
# as a file named `copyright` to the directory `${CURRENT_PACKAGES_DIR}/share/${PORT}`
# vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

vcpkg.json

{
  "name": "cgraph",
  "version": "",
  "homepage": "",
  "description": "",
  "license": "",
  "dependencies": [
    {
      "name": "vcpkg-cmake",
      "host": true
    }
  ],

  "default-features": [],
  "features": {
    "example-feature": {
      "description": "",
      "dependencies": []
    }
  }
}

可以看到在portfile.cmake中源码来源有五种途径

#  vcpkg_from_github
#  vcpkg_from_gitlab
#  vcpkg_from_bitbucket
#  vcpkg_from_sourceforge
vcpkg_download_distfile

脚本自动生成了SHA512码

SHA512 b52e6c8387eb56b02acf5f4d5ae76104885feb7da69fed833967b7fcfea41755d3a9f7c9d4c8edc3356c0df9c3ef036ab191b85c5b889add3c8b4467fb78d4c9

SHA-512是一种加密算法,用于计算文件的哈希值。vcpkg使用SHA-512哈希值来验证下载的软件包的完整性,以确保它们没有被篡改或损坏。vcpkg hash命令可以单独生成。

接着简单完善一下vcpkg.json相关内容,

{
  "name": "cgraph",
  "version": "2.5.4",
  "homepage": "www.chunel.cn",
  "description": "CGraph is a cross-platform Directed Acyclic Graph framework based on pure C++ without any 3rd-party dependencies.",
  "license": "MIT",
  "dependencies": [
    {
      "name": "vcpkg-cmake",
      "host": true
    }
  ],

  "default-features": [],
  "features": {
    "example-feature": {
      "description": "",
      "dependencies": []
    }
  }
}

接着直接添加一下version看看效果

PS C:\src\vcpkg> git add ports/cgraph/
PS C:\src\vcpkg> git commit -m "add port"
PS C:\src\vcpkg> .\vcpkg.exe x-add-version cgraph

报错

error: cgraph is not properly formatted
Run `vcpkg format-manifest "C:\src\vcpkg\ports\cgraph\vcpkg.json"` to format the file
Don't forget to commit the result!

说明vcpkg.json刚刚格式不对,可能是空格问题,直接按提示使用格式化脚本

PS C:\src\vcpkg> ./vcpkg.exe format-manifest  "C:\src\vcpkg\ports\cgraph\vcpkg.json"
PS C:\src\vcpkg> .\vcpkg.exe x-add-version cgraph

versions文件夹中的内容生成完毕

added version 2.5.4 to C:\src\vcpkg\versions\c-\cgraph.json (new file)
added version 2.5.4 to C:\src\vcpkg\versions\baseline.json

执行安装看看效果,这里就是在执行一般的cmake编译过程,虽然大概率会报错。

PS C:\src\vcpkg> .\vcpkg.exe install cgraph

确实报错了

CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:134 (message):
    Command failed: "C:/Program Files/CMake/bin/cmake.exe" --build . --config Debug --target install -- -v -j9
    Working Directory: C:/src/vcpkg/buildtrees/cgraph/x64-windows-dbg
    See logs for more information:
      C:\src\vcpkg\buildtrees\cgraph\install-x64-windows-dbg-out.log
      C:\src\vcpkg\buildtrees\cgraph\install-x64-windows-dbg-err.log

根据提示查看日志定位问题
ninja: error: unknown target 'install'
查看CGraph 2.5.4的源代码,是的,CGraph的cmake没有提供install部分的内容。vcpkg的理想cmake工程是编译选项清晰,依赖库独立,包含find_packge,add_library,install的modern cmake工程,但是目前很多工程是“将自己作为源代码嵌入用户工程”或者“将依赖库源码嵌入自己”为导向的,这些都造成了必须打补丁的问题。针对这种情况需要自己通过补丁重写部分源代码的cmake内容,使其适配vcpkg的编译机制。

编写补丁

标签:src,cmake,TARGET,自定义,cgraph,VCPKG,注册表,vcpkg
From: https://www.cnblogs.com/QiXiaoQiuRen/p/17968684

相关文章

  • 自定义按钮模板
    自定义按钮模板本文同时为b站WPF课程的笔记,相关示例代码对应09上半节课自定义模板对于当前的这个样式不满意——想要自己控制它这个控件长什么样子比如在一节课中,为了实现圆角按钮,我们是从网上面抄了一段代码过来那么,如何建立一种自带圆角的按钮模板呢?<ButtonWidth="300"......
  • 自定义tabbar
    [基础能力/自定义tabBar(qq.com)]1.在app.json中在原来的tabbar配置里面顶部添加 “custom”:true;添加  "usingComponents": {},"tabBar":{"custom":true,"color":"#000","selectedColor":"blue&qu......
  • 自定义排序
    问题:如何对数据进行自定义排序函数解决:=SORTBY(A2:A21,MATCH(A2:A21,E2:E11,))按自定义序列排序:选取数据中任一单元格》数据(或开始)》排序》自定义排序》勾选包含标题》次序》自定义序列》选取》确定》确定设置自定义序列:选取数据》文件》选项》自定义序列》从单元格导......
  • 死磕Spring之IoC篇 - 解析自定义标签(XML 文件)
    解析自定义标签(XML文件)上一篇《BeanDefinition的解析阶段(XML文件)》文章分析了Spring处理 org.w3c.dom.Document 对象(XMLDocument)的过程,会解析里面的元素。默认命名空间(为空或者 http://www.springframework.org/schema/beans)的元素,例如 <bean/> 标签会被解析成Generic......
  • 微信小程序自定义顶部tap栏
    第一步:隐藏原生导航栏效果                        (默认效果)json中配置: "window": {   "navigationStyle": "custom"  } (成功去除顶部tab栏,只留下了胶囊,但轮播图直接与顶部图标融在一起了)第二步:适应各种手机......
  • STM32CubeMX教程18 DAC - DMA输出自定义波形
    1、准备材料开发板(正点原子stm32f407探索者开发板V2.4)STM32CubeMX软件(Version6.10.0)野火DAP仿真器keilµVision5IDE(MDK-Arm)ST-LINK/V2驱动一台示波器逻辑分析仪nanoDLA2、实验目标使用STM32CubeMX软件配置STM32F407开发板的DACOUT1实现输出0-3.3V周期为12.8ms的正弦......
  • 用户自定义模板中数据区域
    在实际的Word文档开发中,经常需要自动填充数据到Word模板中,以生成动态的Word文档,那么应该如何编辑制作Word模板呢?方法一:直接打开Word文件插入书签假如使用数据区域(DataRegion)来定义模板中动态填充数据的位置,那么直接打开一个Word文件,在其中添加“PO_”开头的书签即可制作word模板......
  • HarmonyOS4.0系列——03、声明式UI、链式编程、事件方法、以及自定义组件简单案例
    HarmonyOS4.0系列——03、声明式UI、链式编程、事件方法、以及自定义组件简单案例声明式UIArkTS以声明方式组合和扩展组件来描述应用程序的UI,同时还提供了基本的属性、事件和子组件配置方法,帮助开发者实现应用交互逻辑。如果组件的接口定义没有包含必选构造参数,则组件后面的“()”......
  • MFC 自定义控件添加 tip
    一、要求1.自定义tip提示并实时提示,跟随鼠标移动2.避免重复刷导致tip闪烁3.picture控件添加自定义变量二、tip涉及2.1CMFCToolTipCtrl、CMFCToolTipInfoCMFCToolTipCtrl*m_ptooltip;//注册控件、传递提示消息CMFCToolTipInfo*m_ttinfo;//样式处理......
  • vue+antd-vue(自定义iconfont图标组件)
    1.方式一代码如下import{createFromIconfontCN}from'@ant-design/icons-vue';constIconFont=createFromIconfontCN({scriptUrl:newURL('./assets/font/iconfont.js',import.meta.url).href});app.component('IconFont',IconFont);......