5

Lets say I'm using vcpkg and I want to install a package as static no matter the platform I know I can do it with a triple like wxwidgets:x86-windows-static however, how can I say "make it static for every platform"?

1 Answers1

3

You want to read https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md.

The triplet variable you are looking for is VCPKG_LIBRARY_LINKAGE. Setting it to static in a triplet makes every library/port - which supports it - build as a static library.

Alexander Neumann
  • 1,479
  • 8
  • 17
  • I have tried using `set(VCPKG_LIBRARY_LINKAGE static)` but it doesn't change the triplet. Any ideas? – Nick Strupat May 09 '22 at 16:05
  • What did work is `if(VCPKG_TARGET_TRIPLET MATCHES "windows") set(VCPKG_TARGET_TRIPLET "${VCPKG_TARGET_TRIPLET}-static") ENDIF()`. Still looking for a good setting to link properly with MSVC though. – Nick Strupat May 09 '22 at 17:57
  • 1
    You need to learn that your `CMakeLists.txt` and a vcpkg triplet are two different things. Changing `VCPKG_LIBRARY_LINKAGE` in your cmake project does nothing,it only has affect in a triplet. Your triplet setting should always be a preset setting or a cache variable so users are free to overwrite it and use something different. For example I have a triplet which is called `x64-windows-llvm`. Applying your code would thus break with an non-existant triplet. – Alexander Neumann May 10 '22 at 21:53
  • Yep, you're right. Lesson learned, haha. I've made a small `include()`d cmake file which overrides the triplet on windows to `...static-md`. Maybe a cleaner mechanism will be available in the future. This is what I did, in case anyone wants to see. https://gist.github.com/NickStrupat/630ba7bc1d4b3072c5279bff0adb4ba2 – Nick Strupat May 10 '22 at 23:38
  • Scratch that, it doesn't work. – Nick Strupat May 11 '22 at 04:44
  • > Scratch that, it doesn't work. a) always have `cmake_minimum_required(VERSION 3.21)` at the top of your toplevel `CMakeLists.txt` b) make sure it has been set before `project()` c) changing triplets in an already configured tree is not possible. You have to do a clean configure for it to work d) rather then forcing the triplet consider passing it via the cmd line or [cmake presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) – Alexander Neumann May 11 '22 at 14:17
  • Thanks for your expertise! Is there a decent way to have `vcpkg` use whatever compilation settings are being used by the consuming project? Ideally I wouldn't need to maintain two sets of compilation flags. – Nick Strupat May 11 '22 at 16:49
  • Ah, it seems cmake presets is likely the way to manage this. – Nick Strupat May 11 '22 at 17:52
  • > use whatever compilation settings are being used by the consuming project You will need a toolchain and a custom vcpkg triplet to use that toolchain. In the triplet you simply set `VCPKG_CHAINLOAD_TOOLCHAIN_FILE` to the path to your toolchain and you do the same on the command line for your project. – Alexander Neumann May 12 '22 at 08:35