1

I am using vcpkg and I would like to set the variable VCPKG_TARGET_TRIPLET to my specific triplet.

The help here https://vcpkg.readthedocs.io/en/latest/users/integration/#using-an-environment-variable-instead-of-a-command-line-option (bottom of the page) says you need to pass it as a -D option to CMake, but I would like to set it in my CMakeLists.txt.

I have tried the following two options, but both do not seem to work:

set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "") # doesn't work
set(VCPKG_TARGET_TRIPLET "x64-mingw-static") # also doesn't work

The reason I want to do this in CMakeLists.txt and not the command line is because of my current setup with VS Code and the CMakeTools extension.

How can I "simulate" the -D flag inside my CMakeLists?

I should also mention that my whole "project" consists of a top-level CMakeLists as a sort of "master project" which then includes a sub-folder with another CMakeLists and my "actual" project (the one with the find_package commands).

Gary Allen
  • 1,218
  • 1
  • 13
  • 28
  • You can pass `-D` arguments to the CMake command line via Visual Studio Code. Just open **Settings**, search for "*cmake configure args*" in the settings search bar, and under **CMake: Configure Args** click **Add Item** to append arguments to be passed to `cmake`. Not sure if you want to do this though... – Kevin Aug 05 '20 at 15:48
  • 1
    Unfortunately this doesn't work for me. What I need is the ability to set the triplet based on all the different kits I have setup. CMake Tools doesn't allow you to pas -D arguments from the kits directly, but does allow you to set CMake environment variables per kit. So I need to use those environment variables to "pass" a -D option.Thanks for the help though. – Gary Allen Aug 05 '20 at 15:52
  • Make sure your settings comes **before** the very first `project()` call, when vcpkg toolchain is actually executed. – Tsyvarev Aug 05 '20 at 16:31
  • @Tsyvarev they are before – Gary Allen Aug 05 '20 at 16:37

1 Answers1

2

Try with add_compile_definitions or target_compile_definitions

Like this

add_compile_definitions(VCPKG_TARGET_TRIPLET="x64-mingw-static") 

or

target_compile_definitions(targetname PUBLIC VCPKG_TARGET_TRIPLET="x64-mingw-static")

CMake Tutorial

Per Ghosh
  • 449
  • 5
  • 10