Initialize default CMAKE_TOOLCHAIN_FILE from environment variable
I currently manage my library dependencies with Vcpkg. Vcpkg comes with a custom CMake toolchain file which needs to be set during first configuration. Hence, when I configure a new project, I always call CMake like this:
cmake -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" <other args>
This is a bit tedious, so I wondered if it would make sense to allow setting a default toolchain file as an environment variable, i.e.:
# Put this line in ~/.bashrc.
export CMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"
# This call will automatically pick up the toolchain file from the `CMAKE_TOOLCHAIN_FILE` environment variable.
cmake <other args>
# This call will use "/foo/bar.cmake" as toolchain file.
cmake -DCMAKE_TOOLCHAIN_FILE=/foo/bar.cmake <other args>
# This call will use no toolchain file.
cmake -DCMAKE_TOOLCHAIN_FILE= <other args>
This seems to be a fairly simple change, too. In https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/CMakeDetermineSystem.cmake#L88:
...
# if a toolchain file is used, the user wants to cross compile.
# in this case read the toolchain file and keep the CMAKE_HOST_SYSTEM_*
# variables around so they can be used in CMakeLists.txt.
# In all other cases, the host and target platform are the same.
+ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{CMAKE_TOOLCHAIN_FILE})
+ set(CMAKE_TOOLCHAIN_FILE $ENV{CMAKE_TOOLCHAIN_FILE})
+ endif()
if(CMAKE_TOOLCHAIN_FILE)
..
Am I missing something? I'd be happy to provide a PR if this is considered a reasonable request.