[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
This commit is contained in:
Alexander Neumann 2020-03-28 04:19:53 +01:00 committed by GitHub
parent cd4c066116
commit aeffa625e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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;
}
}

View File

@ -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 {