6

My question is, how to integrate vcpkg in linux with cross build toolchain, as well as sysroot? example:

  • build machine is fedora30
  • cross build toolchain is x86_64-centos7-gnu

from https://github.com/microsoft/vcpkg quickstart says:

> git clone https://github.com/Microsoft/vcpkg.git
> cd vcpkg

PS> .\bootstrap-vcpkg.bat
Linux:~/$ ./bootstrap-vcpkg.sh

On my machine I have gcc 9.1 installed which is detected by vcpkg's bootstrap.sh and work fine;

Meanwhile, I built a toolchain for crossbuilding, which sits in $HOME/cross/x64_86-centos7-linux-gnu/

How can I setup another vcpkg dir tree which uses that perticular toolchain?

By 'use', I mean vcpkg and all its packages should be compiled by that toolchain, and my projects which use vcpkg's toolchain_file '$vcpkg_home/scripts/buildsystems/vcpkg.cmake' should all have that toolchain as $CC and build toolset?

Michaelzh
  • 441
  • 5
  • 14
  • Did you follow all the steps from the Quickstart? Did you get errors? Which steps worked, or didn't work? Please add these details to your question post! – Kevin Nov 09 '19 at 14:49
  • edit: On my machine I have gcc 9.1 installed which is detected by vcpkg's bootstrap.sh and work fine; Meanwhile, I built a toolchain for crossbuilding, which sits in $HOME/cross/x64_86-centos7-linux-gnu/ How can I setup another vcpkg dir tree which uses that perticular toolchain? By 'use', I mean vcpkg and all its packages should be compiled by that toolchain, and my projects which use vcpkg's toolchain_file '$vcpkg_home/scripts/buildsystems/vcpkg.cmake' should all have that toolchain as $CC and build toolset? – Michaelzh Nov 09 '19 at 16:32
  • Please add all this information to your **question post** – Kevin Nov 09 '19 at 16:38
  • Quick start: all steps to me work fine, compiled and runned a program with some vcpkg's packages; Non-quickstart: problem is no cmake-ish xxx-toolchain.cmake in my cross compile toolchain dir tree to try as a -DCMAKE_TOOLCHAIN_FILE list item. – Michaelzh Nov 09 '19 at 16:43
  • Not to mention that wish to compile vcpkg downloaded packages to install with that toolchain which I think is obviously a requirement to build projects. – Michaelzh Nov 09 '19 at 16:47
  • To set up one can download a raspberry PI build toolset tarball to try with. – Michaelzh Nov 09 '19 at 16:52

1 Answers1

7

You should write a triplet file that references your desired toolchain. Create a file ${VCPKG_ROOT}/triplets/x64-centos7 with content

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Linux)

set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE /your/cmake/toolchain.cmake)

/your/cmake/toolchain.cmake beeing a CMake toolchain like

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)

set(CMAKE_SYSROOT /your/sysroot)

set(tools $HOME/cross/x64_86-centos7-linux-gnu/)
set(CMAKE_C_COMPILER ${tools}/bin/your-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/your-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Moritz
  • 1,954
  • 2
  • 18
  • 28