feature: suggest `git submodule update` if CMAKE_TOOLCHAIN_FILE referes to a file in uninitialized submodule
One of the ways of using vcpkg in project is adding it as a submodule and setting CMAKE_TOOLCHAIN_FILE
to "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
.
In that case vcpkg manages to install all dependencies specified in vcpkg.json
file.
Some users forget to checkout submodules and I use this quality-of-life fix for them:
if(NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
set(msg "${CMAKE_TOOLCHAIN_FILE} doesn't exist. It seems that vcpkg submodule is not initialized.")
set(msg "${msg}\nUse commands below to initialize:")
set(msg "${msg}\n git submodule init")
set(msg "${msg}\n git submodule update")
message(FATAL_ERROR "${msg}")
endif()
I suggest to make this behavior standard.
Without that users would see just Could not find toolchain file
which is confusing, especially since the toolchain files are originally for cross-compiling, not for package managers, etc.
All we need to add some extra logic to CMakeDetermineSystem.cmake
P.S. It will not hardcode references to vcpkg into cmake. It will just work with any toolchain files from submodules instead.