I am trying to port our dependencies to use vcpkg and I'm struggling to resolve how to use a custom triplet in our build.
For illustration sake say we are using a dynamic build of xerces-c and a static one of google glog: I have added a triplet with the following content in vcpkg/triplets/x86-windows-csir-custom.cmake:
set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
if(PORT MATCHES "glog")
set(VCPKG_LIBRARY_LINKAGE static)
endif()
Then to install the libraries in a cmd prompt:
SET VCPKG_DEFAULT_TRIPLET=x86-windows-csir-custom
.\vcpkg.exe install ^
--triplet x86-windows-csir-custom ^
glog ^
xerces-c
This seems to work as desired with the dependencies built/installed in vcpkg\installed\x86-windows-csir-custom
However when invoking CMake:
SET TOOLCHAIN_FILE=%VCPKG_DIR%/scripts/buildsystems/vcpkg.cmake
cmake -DCMAKE_TOOLCHAIN_FILE=%TOOLCHAIN_FILE% ^
-DVCPKG_DEFAULT_TRIPLET=%VCPKG_DEFAULT_TRIPLET%^
-A Win32 ..
I get the following error:
CMake Warning at vcpkg/scripts/buildsystems/vcpkg.cmake:104 (message):
There are no libraries installed for the Vcpkg triplet x86-windows.
..
CMake Error at vcpkg/scripts/buildsystems/vcpkg.cmake:263 (_find_package):
Could not find a package configuration file provided by "XercesC" with any
of the following names:
XercesCConfig.cmake
xercesc-config.cmake
Add the installation prefix of "XercesC" to CMAKE_PREFIX_PATH or set
"XercesC_DIR" to a directory containing one of the above files. If
"XercesC" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
CMakeLists.txt:7 (find_package)
-- Configuring incomplete, errors occurred!
The error seems to be related to the 'There are no libraries installed for the Vcpkg triplet x86-windows.' warning and does not occur when using only the default x86-windows triplet.
I have been able to resolve the issue by manually defining the following before invoking CMake:
SET XercesC_DIR=%VCPKG_DIR%\installed\x86-windows-csir-custom\share\xercesc
SET glog_DIR=%VCPKG_DIR%\installed\x86-windows-csir-custom\share\glog
:: indirect dependency of glog
SET gflags_DIR=%VCPKG_DIR%\installed\x86-windows-csir-custom\share\gflags
However this does not seem ideal to me: in our code base, we have a large number of dependencies and needing to define multiple environmental variables per dependency introduces a lot of complexity, as well as makes it error prone to change the library type (e.g. from static to dynamic, etc).
Is there a better way to do this?
The documentation that could use clarification is the following:
https://vcpkg.readthedocs.io/en/latest/users/triplets/#additional-remarks
set(VCPKG_TARGET_TRIPLET <your triplet> CACHE STRING "VCPKG Target Triplet to use")
or via cmd line use -DVCPKG_TARGET_TRIPLET=<your triplet>
but it is documented here:
https://vcpkg.readthedocs.io/en/latest/users/integration/#triplet-selection
Try adding your custom triplet to the cmake command line:
cmake -CMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x86-windows-csir-custom
Most helpful comment
set(VCPKG_TARGET_TRIPLET <your triplet> CACHE STRING "VCPKG Target Triplet to use")or via cmd line use
-DVCPKG_TARGET_TRIPLET=<your triplet>but it is documented here:
https://vcpkg.readthedocs.io/en/latest/users/integration/#triplet-selection