From fee011946e4fe0fc20f2f6bf016851402241d554 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 12 Apr 2017 10:53:36 -0400 Subject: VS: Add an environment variable for the Windows 10 kits directory Define a `CMAKE_WINDOWS_KITS_10_DIR` environment variable to allow users to tell CMake about a custom Windows 10 SDK directory. We choose to make this an environment variable rather than a CMake variable or cache entry because: * Using a custom directory also requires custom external MSBuild configuration. Therefore users are already configuring a custom environment. * The custom directory must be set consistently in all parts of a build including nested projects. An environment variable avoids requiring users to thread the setting into nested builds. Fixes: #16743 --- Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst | 5 +++++ Modules/InstallRequiredSystemLibraries.cmake | 6 ++++++ Source/cmGlobalVisualStudio14Generator.cxx | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst b/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst index e0be3a4..83b9bc1 100644 --- a/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst +++ b/Help/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.rst @@ -10,3 +10,8 @@ version. Otherwise CMake computes a default version based on the Windows SDK versions available. The chosen Windows target version number is provided in ``CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION``. If no Windows 10 SDK is available this value will be empty. + +One may set a ``CMAKE_WINDOWS_KITS_10_DIR`` *environment variable* +to an absolute path to tell CMake to look for Windows 10 SDKs in +a custom location. The specified directory is expected to contain +``Include/10.0.*`` directories. diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake index a3478a3..6d33fc6 100644 --- a/Modules/InstallRequiredSystemLibraries.cmake +++ b/Modules/InstallRequiredSystemLibraries.cmake @@ -31,6 +31,11 @@ # app-local deployment (e.g. to Windows XP). This is meaningful # only with MSVC from Visual Studio 2015 or higher. # +# One may set a ``CMAKE_WINDOWS_KITS_10_DIR`` *environment variable* +# to an absolute path to tell CMake to look for Windows 10 SDKs in +# a custom location. The specified directory is expected to contain +# ``Redist/ucrt/DLLs/*`` directories. +# # ``CMAKE_INSTALL_MFC_LIBRARIES`` # Set to TRUE to install the MSVC MFC runtime libraries. # @@ -258,6 +263,7 @@ if(MSVC) set(programfilesx86 "ProgramFiles(x86)") find_path(WINDOWS_KITS_DIR NAMES Redist/ucrt/DLLs/${CMAKE_MSVC_ARCH}/ucrtbase.dll PATHS + $ENV{CMAKE_WINDOWS_KITS_10_DIR} "${windows_kits_dir}" "$ENV{ProgramFiles}/Windows Kits/10" "$ENV{${programfilesx86}}/Windows Kits/10" diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 4602d93..df086d3 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -220,6 +220,14 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() std::vector win10Roots; { + std::string win10Root; + if (cmSystemTools::GetEnv("CMAKE_WINDOWS_KITS_10_DIR", win10Root)) { + cmSystemTools::ConvertToUnixSlashes(win10Root); + win10Roots.push_back(win10Root); + } + } + + { // This logic is taken from the vcvarsqueryregistry.bat file from VS2015 // Try HKLM and then HKCU. std::string win10Root; -- cgit v0.12