[vcpkg] Add the possibility to load vcvars.bat with external toolchain.
* Add VCPKG_LOAD_VCVARS_ENV
allow loading vcvars.bat if an external toolchain file is used.
* add documentation
MODIFY
include/vcpkg/build.h
include/vcpkg/build.h
@@ -153,6 +153,7 @@ namespace vcpkg::Build
Triplet triplet,
const std::unordered_map<std::string, std::string>& 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<std::string, VcpkgTripletVar> 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

MODIFY
src/vcpkg/build.cpp
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<std::string>{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;
}
}

MODIFY
src/vcpkg/vcpkgpaths.cpp
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 {

[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