From aeffa625e55eea41a86a728c14a95d05bc3de0e9 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Sat, 28 Mar 2020 04:19:53 +0100 Subject: [PATCH] [vcpkg] Add the possibility to load vcvars.bat with external toolchain. (#10399) * Add VCPKG_LOAD_VCVARS_ENV allow loading vcvars.bat if an external toolchain file is used. * add documentation --- docs/users/triplets.md | 4 ++++ scripts/vcpkg_get_tags.cmake | 1 + toolsrc/include/vcpkg/build.h | 3 +++ toolsrc/src/vcpkg/build.cpp | 21 ++++++++++++++++++++- toolsrc/src/vcpkg/vcpkgpaths.cpp | 2 +- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/users/triplets.md b/docs/users/triplets.md index 21dea5c316..0804756519 100644 --- a/docs/users/triplets.md +++ b/docs/users/triplets.md @@ -125,6 +125,10 @@ Valid settings: * The Visual Studio 2017 platform toolset is `v141`. * The Visual Studio 2015 platform toolset is `v140`. +### VCPKG_LOAD_VCVARS_ENV +If `VCPKG_CHAINLOAD_TOOLCHAIN_FILE` is used, VCPKG will not setup the Visual Studio environment. +Setting `VCPKG_LOAD_VCVARS_ENV` to (true|1|on) changes this behavior so that the Visual Studio environment is setup following the same rules as if `VCPKG_CHAINLOAD_TOOLCHAIN_FILE` was not set. + ## MacOS Variables ### VCPKG_INSTALL_NAME_DIR diff --git a/scripts/vcpkg_get_tags.cmake b/scripts/vcpkg_get_tags.cmake index ccdc4fea62..35e89149ba 100644 --- a/scripts/vcpkg_get_tags.cmake +++ b/scripts/vcpkg_get_tags.cmake @@ -23,6 +23,7 @@ e1e74b5c-18cb-4474-a6bd-5c1c8bc81f3f") message("c35112b6-d1ba-415b-aa5d-81de856ef8eb VCPKG_PUBLIC_ABI_OVERRIDE=${VCPKG_PUBLIC_ABI_OVERRIDE} VCPKG_ENV_PASSTHROUGH=${VCPKG_ENV_PASSTHROUGH} +VCPKG_LOAD_VCVARS_ENV=${VCPKG_LOAD_VCVARS_ENV} e1e74b5c-18cb-4474-a6bd-5c1c8bc81f3f 8c504940-be29-4cba-9f8f-6cd83e9d87b7") endfunction() diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index d36b641430..892fb23707 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -153,6 +153,7 @@ namespace vcpkg::Build Triplet triplet, const std::unordered_map& cmakevars); + bool load_vcvars_env; std::string triplet_abi_tag; std::string target_architecture; std::string cmake_system_name; @@ -179,6 +180,7 @@ namespace vcpkg::Build BUILD_TYPE, ENV_PASSTHROUGH, PUBLIC_ABI_OVERRIDE, + LOAD_VCVARS_ENV, }; const std::unordered_map VCPKG_OPTIONS = { @@ -191,6 +193,7 @@ namespace vcpkg::Build {"VCPKG_BUILD_TYPE", VcpkgTripletVar::BUILD_TYPE}, {"VCPKG_ENV_PASSTHROUGH", VcpkgTripletVar::ENV_PASSTHROUGH}, {"VCPKG_PUBLIC_ABI_OVERRIDE", VcpkgTripletVar::PUBLIC_ABI_OVERRIDE}, + {"VCPKG_LOAD_VCVARS_ENV", VcpkgTripletVar::LOAD_VCVARS_ENV}, }; struct ExtendedBuildResult diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 81997e79c9..c1e91adf95 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -274,7 +274,7 @@ namespace vcpkg::Build std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset) { - if (pre_build_info.external_toolchain_file.has_value()) return ""; + if (pre_build_info.external_toolchain_file.has_value() && !pre_build_info.load_vcvars_env) return ""; if (!pre_build_info.cmake_system_name.empty() && pre_build_info.cmake_system_name != "WindowsStore") return ""; const char* tonull = " >nul"; @@ -1052,6 +1052,25 @@ namespace vcpkg::Build case VcpkgTripletVar::PUBLIC_ABI_OVERRIDE: public_abi_override = variable_value.empty() ? nullopt : Optional{variable_value}; break; + case VcpkgTripletVar::LOAD_VCVARS_ENV: + if (variable_value.empty()) + { + load_vcvars_env = true; + if(external_toolchain_file) + load_vcvars_env = false; + } + else if (Strings::case_insensitive_ascii_equals(variable_value, "1") || + Strings::case_insensitive_ascii_equals(variable_value, "on") || + Strings::case_insensitive_ascii_equals(variable_value, "true")) + load_vcvars_env = true; + else if (Strings::case_insensitive_ascii_equals(variable_value, "0") || + Strings::case_insensitive_ascii_equals(variable_value, "off") || + Strings::case_insensitive_ascii_equals(variable_value, "false")) + load_vcvars_env = false; + else + Checks::exit_with_message( + VCPKG_LINE_INFO, "Unknown boolean setting for VCPKG_LOAD_VCVARS_ENV: %s", variable_value); + break; } } diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp index 98be491e38..bf16f09f3f 100644 --- a/toolsrc/src/vcpkg/vcpkgpaths.cpp +++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp @@ -193,7 +193,7 @@ namespace vcpkg const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const { - if (prebuildinfo.external_toolchain_file || + if ((prebuildinfo.external_toolchain_file && !prebuildinfo.load_vcvars_env) || (!prebuildinfo.cmake_system_name.empty() && prebuildinfo.cmake_system_name != "WindowsStore")) { static Toolset external_toolset = []() -> Toolset {