Provide helper .cmake file to avoid toolchain chainloads #19133
seanmiddleditch
started this conversation in
Ideas
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem? Please describe.
The documentation currently states:
This is not ideal. Likewise, passing
-DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake
or modifying build settings.A CMake project that relies on vcpkg should ideally be self-contained (requiring no external steps or configuration or manual build steps) and also should ideally not co-opt a key CMake ecosystem variable like
CMAKE_TOOLCHAIN_FILE
.Proposed solution
A few lines of CMake can do a two-step with cache variables to both enable standard
CMAKE_TOOLCHAIN_FILE
while injecting vcpkg's own toolchain. Something along the lines of:A few additional lines may be added for error checking, path searching to find the right vcpkg.cmake location, etc. It could also automatically acquire vcpkg if not present already (avoiding the grossness of git submodules) with minimal work thanks to the
FetchContent
module.I propose wrapping all that up into a function
vcpkg_enable()
, offering that as a simplevcpkg.cmake
file, and documenting that a CMake integration can be achieved by copying that file into its source repo,include
ing the file and adding thevcpkg_enable()
line beforeproject()
:Describe alternatives you've considered
The alternative is the status quo, which makes vcpkg feel "alien" in a CMake environment despite how minimal the existing integration is (due to the hijacking of the toolchain variable).
Additional context
Being able to add vcpkg to a CMake project in a way that Just Works(tm) for users when they checkout the repo (no need to set new CMake variables or IDE settings or anything) and in a way that continues working with existing CI and cross-compile infrastructure (which will already be using
CMAKE_TOOLCHAIN_FILE
) is possibly critical to gradual adoption of vcpkg in environments where a single developer does not easily control all the dev environments or CI environments.Beta Was this translation helpful? Give feedback.
All reactions