首页 > 其他分享 >Manifest使用示例6 - 安装并使用git私有仓库

Manifest使用示例6 - 安装并使用git私有仓库

时间:2022-10-18 18:01:15浏览次数:67  
标签:git cmake 示例 -- x64 Manifest windows vcpkg test

有的开发者会借助github创建自己的私有库,那么如何利用vcpkg 使用git上的私有库呢? 请参考以下示例。

 使用示例

1. 准备一个私有仓库Cheney-W/test, 且为这个私有库生成一个token. (github在2020年8月13日更新以后,停止了对https用户名及密码的支持,所以本示例使用token进行自动认证。)

2. 准备一个Overlay ports,这个port用来在vcpkg中解释这个私有仓库, 库名mytest,使用CMake编译源码包,文件结构如下。

  |---mytest/ (此文件夹可随意放置)

      |---vcpkg.json

      |---portfile.cmake

 vcpkg.json

{
   "name": "mytest",
   "version": "1.0.4",
   "description": "Test manifest mode",
   "dependencies": [
    {
      "name": "vcpkg-cmake",
      "host": true
    },
    {
      "name": "vcpkg-cmake-config",
      "host": true
    }
  ]
}

 portfile.cmake

#从环境变量获取私有库的token 
set(MY_TOKEN_VAR "*******************")
if(DEFINED ENV{MY_TOKEN_VAR})
    set(MY_TOKEN_VAR "$ENV{MY_TOKEN_VAR}@")
endif()

#下载私有库
vcpkg_from_git(
    OUT_SOURCE_PATH SOURCE_PATH
    URL "https://Cheney-W:${MY_TOKEN_VER}@github.com/Cheney-W/test"
    REF 2253a2a3cbe7e1a1047ad6cb5579059a8f70b099 #v1.0.4
    HEAD_REF main
 )

#使用CMake配置工程文件
vcpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}"
)

#使用CMake安装源文件
vcpkg_cmake_install()

#修复库的config文件的路径
vcpkg_cmake_config_fixup()

#删除debug目录下的头文件,vcpkg默认直接调用release目录下的头文件
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

#安装license文件
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)

 

3. 本示例所需的全部的文件结构: (manifest-test即为自己的工程文件夹)

   根目录 C:\ 

|---manifest-test

        |---build/

        |---vcpkg.json

        |---CMakeLists.txt

        |---test.cpp

 vcpkg.json

{
  "name": "test",
  "version-string": "0.0.1",
  "dependencies": [
    "mytest"
  ]
}

 CMakeLists.txt

cmake_minimum_required (VERSION 3.8)
 
project(test)
#Add source to this project's executable.
add_executable (test "test.cpp")

find_package(mytest CONFIG REQUIRED)
target_link_libraries(test PRIVATE mytest)

 test.cpp

#include <iostream>
#include <Mytest.h>

using namespace std;

int main()
{
    cout << addition(10,5) << endl;
    cout << subtraction(10,5) << endl;
    cout << multiplication(10,5) << endl;
    cout << division(10,5) << endl;
    return 0;
}

 

4. 在build文件夹中使用cmd运行以下命令:

Set VCPKG_KEEP_ENV_VARS=MY_TOKEN_VAR
Set MY_TOKEN_VAR=abc123 (这里的值实际上是私有库的token)

cmake.exe "C:\manifest-test" -G "Visual Studio 17 2022" -A x64  -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_TOOLCHAIN_FILE:STRING="C:\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="C:\manifest-test\mytest"

输出:

-- Running vcpkg install
A suitable version of cmake was not found (required v3.24.0). Downloading portable cmake v3.24.0...
Downloading cmake...
https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-windows-i386.zip -> C:\vcpkg\downloads\cmake-3.24.0-windows-i386.zip
Extracting cmake...
Detecting compiler hash for triplet x64-windows...
A suitable version of powershell-core was not found (required v7.2.5). Downloading portable powershell-core v7.2.5...
Downloading powershell-core... https://github.com/PowerShell/PowerShell/releases/download/v7.2.5/PowerShell-7.2.5-win-x86.zip -> C:\vcpkg\downloads\PowerShell-7.2.5-win-x86.zip
Extracting powershell-core...
The following packages will be built and installed:
    mytest[core]:x64-windows -> 1.0.4 -- C:\manifest-test\mytest
  * vcpkg-cmake[core]:x64-windows -> 2022-07-18
  * vcpkg-cmake-config[core]:x64-windows -> 2022-02-06#1
Additional packages (*) will be modified to complete this operation.
Restored 0 package(s) from C:\Users\xxx\AppData\Local\vcpkg\archives in 2.428 ms. Use --debug to see more details.
Installing 1/3 vcpkg-cmake-config:x64-windows...
Building vcpkg-cmake-config[core]:x64-windows...
-- Installing: C:/vcpkg/packages/vcpkg-cmake-config_x64-windows/share/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
-- Installing: C:/vcpkg/packages/vcpkg-cmake-config_x64-windows/share/vcpkg-cmake-config/vcpkg-port-config.cmake
-- Installing: C:/vcpkg/packages/vcpkg-cmake-config_x64-windows/share/vcpkg-cmake-config/copyright
-- Performing post-build validation
-- Performing post-build validation done
A suitable version of 7zip was not found (required v21.7.0). Downloading portable 7zip v21.7.0...
Downloading 7zip...
  https://www.7-zip.org/a/7z2107-extra.7z -> C:\vcpkg\downloads\7z2107-extra.7z
Extracting 7zip...
Stored binary cache: "C:\Users\xxxx\AppData\Local\vcpkg\archives\07\07b134143814967b68c15670722cb68a20ab286426d04e6ec879fa82aa8fb672.zip"
Elapsed time to handle vcpkg-cmake-config:x64-windows: 4.424 s
Installing 2/3 vcpkg-cmake:x64-windows...
Building vcpkg-cmake[core]:x64-windows...
-- Installing: C:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg_cmake_configure.cmake
-- Installing: C:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg_cmake_build.cmake
-- Installing: C:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg_cmake_install.cmake
-- Installing: C:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg-port-config.cmake
-- Installing: C:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/copyright
-- Performing post-build validation
-- Performing post-build validation done
Stored binary cache: "C:\Users\xxxx\AppData\Local\vcpkg\archives\28\28d639c03633f392fd9e42d95b946c3ad098db80eca5f48e61e69e599dac5548.zip"
Elapsed time to handle vcpkg-cmake:x64-windows: 236.2 ms
Installing 3/3 mytest:x64-windows...
Building mytest[core]:x64-windows...
-- Installing port from location: C:\manifest-test\mytest
-- Fetching https://Cheney-W:[email protected]/Cheney-W/test 2253a2a3cbe7e1a1047ad6cb5579059a8f70b099...
-- Extracting source C:/vcpkg/downloads/mytest-2253a2a3cbe7e1a1047ad6cb5579059a8f70b099.tar.gz
-- Using source at C:/vcpkg/buildtrees/mytest/src/9a8f70b099-3bd3e4a0d2.clean
-- Found external ninja('1.10.2').
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Installing: C:/vcpkg/packages/mytest_x64-windows/share/mytest/copyright
-- Performing post-build validation
-- Performing post-build validation done
Stored binary cache: "C:\Users\xxxx\AppData\Local\vcpkg\archives\11\11b32c50932b61b2ad082d5e65fdb5adde62339071bf4274d30d46c38ac91324.zip"

Elapsed time to handle mytest:x64-windows: 11.12 s
Total elapsed time: 2.438 min

mytest provides CMake targets:
    # this is heuristically generated, and may not be correct
    find_package(mytest CONFIG REQUIRED)
    target_link_libraries(main PRIVATE mytest)

-- Running vcpkg install - done
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.33.31424.0
-- The CXX compiler identification is MSVC 19.33.31424.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.33.31424/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.33.31424/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/manifest-test

 

5. 构建CMake工程

cmake.exe --build .

输出:

Microsoft (R) Build Engine version 17.3.0-preview-22226-03+b6fc583d4 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
  Checking Build System
  Building Custom Rule C:/manifest-test/CMakeLists.txt
  test.cpp
  test.vcxproj -> C:\manifest-test\build\Debug\test.exe
  Building Custom Rule C:/manifest-test/CMakeLists.txt

 

6. 运行程序test.exe,显示:

15
5
50
2

 

注意:

本文档示例port的安装文件目录为: E:\Manifest\vcpkg_installed\x64-windows

在MSBuild工程中使用该库,需要在项目——属性——vcpkg 中将User Vcpkg 设为true,将--overlay-ports="<overlay_abs_prefix>\\mytest"添加进Additional Options中。

标签:git,cmake,示例,--,x64,Manifest,windows,vcpkg,test
From: https://www.cnblogs.com/vcpkg/p/16791144.html

相关文章

  • Manifest使用示例2 - 依赖多个vcpkg 的历史版本库
    以下示例将提供在自定义工程中使用vcpkg中fmt、sqlite3、zlib的固定版本。Manifest模式-CMake工程1.示例根目录:E:/test_manifest,文件目录结构如下:E:/ |--test......
  • Manifest使用示例4 - Binarycaching使用缓存文件
    在多人开发环境中,我们仅希望一个人管理项目需要的所有第三方库,并使用服务器部署和分发vcpkg中已编译的库,此时可以使用vcpkg的Binarysource特性。VCPKG默认开启Binaryca......
  • jira集成gitlab
    1.jira集成gitlab原理解析实现原理:jira上配置webhook,自动触发jenkins将webhookData(类似于gitlab钩子触发的runOpts)传递到jenkins流水线,根据参数“webhookEvent”判断触......
  • 『现学现忘』Git基础 — 35、Git中删除文件
    目录1、删除文件说明2、删除文件操作(1)仅删除暂存区的文件(2)完全删除文件3、本文用到的命令总结1、删除文件说明在Git工作目录中要删除某个文件,首先要清楚该文件所处的状态......
  • jenkins拉取git上SpringBoot项目进行构建、编译、打包、部署
    安装Jenkins、Git、Maven和JDKLinux服务器部署Jenkins自动化部署工具Linux服务器Git安装Linux服务器Maven安装参考Linux服务器JDK安装参考安装完这几个插件后,配置g......
  • git问题汇总
    如果出现每次提交/拉取都要再次输入密码解决方案请执行: gitconfig--globalcredential.helperstore再次输入密码之后就不会每次都要输入账号/密码问题git执行 git......
  • Git安装配置
    安装官网下载安装:Git官网下载慢?淘宝镜像地址:npmmirror.com下滑,选择最新版,后选择自己电脑需要的对应版本选择安装位置后无脑下一步安装卸载?清理环境变量,用系统自带......
  • 华为AirEngine 5760-22W Web示例(V200R021C00SPC200版本):NAT网关模式(DHCP方式入网)【
    说明:此版本存在一些默认的WLAN无线业务配置,AP上电启动后,默认创建名称为“HUAWEI-XXXX”的SSID,其中XXXX是APMAC地址的后四位。默认无线业务覆盖使用无认证方式,用户搜索到该......
  • Git忽略提交规则 - .gitignore配置运维总结
    在使用Git的过程中,我们喜欢有的文件比如日志,临时文件,编译的中间文件等不要提交到代码仓库,这时就要设置相应的忽略规则,来忽略这些文件的提交。简单来说一个场景:在你使用git......
  • FZU 2105 Digits Count
     Problem2105DigitsCountAccept:444    Submit:2139TimeLimit:10000mSec    MemoryLimit:262144KB ProblemDescriptionGivenNintegersA={A[0],A......