mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-19 08:23:07 +08:00
[vcpkg] Improve handling of external toolchains. Extract MSVC settings to a separate toolchain file.
This commit is contained in:
parent
9f3fd252bf
commit
ad7fa55bb0
@ -80,7 +80,7 @@ function(vcpkg_configure_cmake)
|
|||||||
set(GENERATOR ${_csc_GENERATOR})
|
set(GENERATOR ${_csc_GENERATOR})
|
||||||
elseif(_csc_PREFER_NINJA AND NINJA_CAN_BE_USED)
|
elseif(_csc_PREFER_NINJA AND NINJA_CAN_BE_USED)
|
||||||
set(GENERATOR "Ninja")
|
set(GENERATOR "Ninja")
|
||||||
elseif(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
|
elseif(VCPKG_CHAINLOAD_TOOLCHAIN_FILE OR (VCPKG_CMAKE_SYSTEM_NAME AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore"))
|
||||||
set(GENERATOR "Ninja")
|
set(GENERATOR "Ninja")
|
||||||
|
|
||||||
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120")
|
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120")
|
||||||
@ -152,39 +152,8 @@ function(vcpkg_configure_cmake)
|
|||||||
|
|
||||||
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
|
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
|
||||||
list(APPEND _csc_OPTIONS "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
|
list(APPEND _csc_OPTIONS "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
|
||||||
else()
|
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" OR NOT DEFINED VCPKG_CMAKE_SYSTEM_NAME)
|
||||||
set(VCPKG_CXX_FLAGS " /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP ${VCPKG_CXX_FLAGS}")
|
list(APPEND _csc_OPTIONS "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_ROOT_DIR}/scripts/toolchains/windows.cmake")
|
||||||
set(VCPKG_C_FLAGS " /DWIN32 /D_WINDOWS /W3 /utf-8 /MP ${VCPKG_C_FLAGS}")
|
|
||||||
if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
|
|
||||||
list(APPEND _csc_OPTIONS_DEBUG
|
|
||||||
"-DCMAKE_CXX_FLAGS_DEBUG=/D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1 ${VCPKG_CXX_FLAGS_DEBUG}"
|
|
||||||
"-DCMAKE_C_FLAGS_DEBUG=/D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1 ${VCPKG_C_FLAGS_DEBUG}"
|
|
||||||
)
|
|
||||||
list(APPEND _csc_OPTIONS_RELEASE
|
|
||||||
"-DCMAKE_CXX_FLAGS_RELEASE=/MD /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_CXX_FLAGS_RELEASE}"
|
|
||||||
"-DCMAKE_C_FLAGS_RELEASE=/MD /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_C_FLAGS_RELEASE}"
|
|
||||||
)
|
|
||||||
elseif(VCPKG_CRT_LINKAGE STREQUAL "static")
|
|
||||||
list(APPEND _csc_OPTIONS_DEBUG
|
|
||||||
"-DCMAKE_CXX_FLAGS_DEBUG=/D_DEBUG /MTd /Z7 /Ob0 /Od /RTC1 ${VCPKG_CXX_FLAGS_DEBUG}"
|
|
||||||
"-DCMAKE_C_FLAGS_DEBUG=/D_DEBUG /MTd /Z7 /Ob0 /Od /RTC1 ${VCPKG_C_FLAGS_DEBUG}"
|
|
||||||
)
|
|
||||||
list(APPEND _csc_OPTIONS_RELEASE
|
|
||||||
"-DCMAKE_CXX_FLAGS_RELEASE=/MT /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_CXX_FLAGS_RELEASE}"
|
|
||||||
"-DCMAKE_C_FLAGS_RELEASE=/MT /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_C_FLAGS_RELEASE}"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Invalid setting for VCPKG_CRT_LINKAGE: \"${VCPKG_CRT_LINKAGE}\". It must be \"static\" or \"dynamic\"")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
list(APPEND _csc_OPTIONS_RELEASE
|
|
||||||
"-DCMAKE_SHARED_LINKER_FLAGS_RELEASE=/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF ${VCPKG_LINKER_FLAGS}"
|
|
||||||
"-DCMAKE_EXE_LINKER_FLAGS_RELEASE=/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF ${VCPKG_LINKER_FLAGS}"
|
|
||||||
)
|
|
||||||
list(APPEND _csc_OPTIONS
|
|
||||||
"-DCMAKE_CXX_FLAGS=${VCPKG_CXX_FLAGS}"
|
|
||||||
"-DCMAKE_C_FLAGS=${VCPKG_C_FLAGS}"
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND _csc_OPTIONS
|
list(APPEND _csc_OPTIONS
|
||||||
@ -197,6 +166,14 @@ function(vcpkg_configure_cmake)
|
|||||||
"-DVCPKG_APPLOCAL_DEPS=OFF"
|
"-DVCPKG_APPLOCAL_DEPS=OFF"
|
||||||
"-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT_DIR}/scripts/buildsystems/vcpkg.cmake"
|
"-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT_DIR}/scripts/buildsystems/vcpkg.cmake"
|
||||||
"-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON"
|
"-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON"
|
||||||
|
"-DVCPKG_CXX_FLAGS=${VCPKG_CXX_FLAGS}"
|
||||||
|
"-DVCPKG_CXX_FLAGS_RELEASE=${VCPKG_CXX_FLAGS_RELEASE}"
|
||||||
|
"-DVCPKG_CXX_FLAGS_DEBUG=${VCPKG_CXX_FLAGS_DEBUG}"
|
||||||
|
"-DVCPKG_C_FLAGS=${VCPKG_C_FLAGS}"
|
||||||
|
"-DVCPKG_C_FLAGS_RELEASE=${VCPKG_C_FLAGS_RELEASE}"
|
||||||
|
"-DVCPKG_C_FLAGS_DEBUG=${VCPKG_C_FLAGS_DEBUG}"
|
||||||
|
"-DVCPKG_CRT_LINKAGE=${VCPKG_CRT_LINKAGE}"
|
||||||
|
"-DVCPKG_LINKER_FLAGS=${VCPKG_LINKER_FLAGS}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(DEFINED ARCH)
|
if(DEFINED ARCH)
|
||||||
|
23
scripts/toolchains/windows.cmake
Normal file
23
scripts/toolchains/windows.cmake
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
|
||||||
|
if(NOT _CMAKE_IN_TRY_COMPILE)
|
||||||
|
|
||||||
|
if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
|
||||||
|
set(VCPKG_CRT_LINK_FLAG_PREFIX "/MD")
|
||||||
|
elseif(VCPKG_CRT_LINKAGE STREQUAL "static")
|
||||||
|
set(VCPKG_CRT_LINK_FLAG_PREFIX "/MT")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Invalid setting for VCPKG_CRT_LINKAGE: \"${VCPKG_CRT_LINKAGE}\". It must be \"static\" or \"dynamic\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS " /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP ${VCPKG_CXX_FLAGS}" CACHE STRING "")
|
||||||
|
set(CMAKE_C_FLAGS " /DWIN32 /D_WINDOWS /W3 /utf-8 /MP ${VCPKG_C_FLAGS}" CACHE STRING "")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG ${VCPKG_CRT_LINK_FLAG_PREFIX}d /Z7 /Ob0 /Od /RTC1 ${VCPKG_CXX_FLAGS_DEBUG}" CACHE STRING "")
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG ${VCPKG_CRT_LINK_FLAG_PREFIX}d /Z7 /Ob0 /Od /RTC1 ${VCPKG_C_FLAGS_DEBUG}" CACHE STRING "")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_CXX_FLAGS_RELEASE}" CACHE STRING "")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_C_FLAGS_RELEASE}" CACHE STRING "")
|
||||||
|
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF ${VCPKG_LINKER_FLAGS}" CACHE STRING "")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF ${VCPKG_LINKER_FLAGS}" CACHE STRING "")
|
||||||
|
|
||||||
|
endif()
|
@ -209,6 +209,7 @@ namespace vcpkg::Build
|
|||||||
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset)
|
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()) return "";
|
||||||
|
if (!pre_build_info.cmake_system_name.empty() && pre_build_info.cmake_system_name != "WindowsStore") return "";
|
||||||
|
|
||||||
const char* tonull = " >nul";
|
const char* tonull = " >nul";
|
||||||
if (GlobalState::debugging)
|
if (GlobalState::debugging)
|
||||||
|
@ -622,7 +622,8 @@ namespace vcpkg
|
|||||||
|
|
||||||
const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const
|
const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const
|
||||||
{
|
{
|
||||||
if (prebuildinfo.external_toolchain_file)
|
if (prebuildinfo.external_toolchain_file ||
|
||||||
|
(!prebuildinfo.cmake_system_name.empty() && prebuildinfo.cmake_system_name != "WindowsStore"))
|
||||||
{
|
{
|
||||||
static Toolset external_toolset = []() -> Toolset {
|
static Toolset external_toolset = []() -> Toolset {
|
||||||
Toolset ret;
|
Toolset ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user