diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 16f43a0..6da761b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,6 +38,7 @@ jobs: - windows-msvc-spectre-x64 - windows-msvc-x86 - windows-msvc-arm64 + - windows-msvc-host - windows-clang-x64 - windows-clangcl-x64 - windows-vs-x64 diff --git a/Windows.Clang.toolchain.cmake b/Windows.Clang.toolchain.cmake index 249d3b4..e26948b 100644 --- a/Windows.Clang.toolchain.cmake +++ b/Windows.Clang.toolchain.cmake @@ -43,7 +43,7 @@ # | CMAKE_CXX_COMPILER | The path to the C++ compiler to use. | # | CMAKE_MT | The path to the 'mt.exe' tool to use. | # | CMAKE_RC_COMPILER | The path tp the 'rc.exe' tool to use. | -# | CMAKE_SYSTEM_NAME | Windows | +# | CMAKE_SYSTEM_NAME | "Windows", when cross-compiling | # | WIN32 | 1 | # | CMAKE_CXX_CLANG_TIDY | The commandline clang-tidy is used if CLANG_TIDY_CHECKS was set. | # @@ -54,6 +54,7 @@ cmake_minimum_required(VERSION 3.20) include_guard() +# If `CMAKE_HOST_SYSTEM_NAME` is not 'Windows', there's nothing to do. if(NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)) return() endif() @@ -61,15 +62,20 @@ endif() option(TOOLCHAIN_UPDATE_PROGRAM_PATH "Whether the toolchain should update CMAKE_PROGRAM_PATH." ON) set(UNUSED ${CMAKE_TOOLCHAIN_FILE}) # Note: only to prevent cmake unused variable warninig -set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES "CMAKE_SYSTEM_PROCESSOR;CMAKE_CROSSCOMPILING") -set(CMAKE_CROSSCOMPILING TRUE) +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES "CMAKE_SYSTEM_PROCESSOR") set(WIN32 1) +# If `CMAKE_SYSTEM_PROCESSOR` isn't set, default to `CMAKE_HOST_SYSTEM_PROCESSOR` if(NOT CMAKE_SYSTEM_PROCESSOR) set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) endif() +# If `CMAKE_SYSTEM_PROCESSOR` is not equal to `CMAKE_HOST_SYSTEM_PROCESSOR`, this is cross-compilation. +# CMake expects `CMAKE_SYSTEM_NAME` to be set to reflect cross-compilation. +if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})) + set(CMAKE_SYSTEM_NAME Windows) +endif() + if(NOT CMAKE_VS_VERSION_RANGE) set(CMAKE_VS_VERSION_RANGE "[16.0,)") endif() diff --git a/Windows.EWDK.toolchain.cmake b/Windows.EWDK.toolchain.cmake index d05c71b..645562e 100644 --- a/Windows.EWDK.toolchain.cmake +++ b/Windows.EWDK.toolchain.cmake @@ -52,7 +52,7 @@ # | CMAKE_CXX_COMPILER | The path to the C++ compiler to use. | # | CMAKE_MT | The path to the 'mt.exe' tool to use. | # | CMAKE_RC_COMPILER | The path tp the 'rc.exe' tool to use. | -# | CMAKE_SYSTEM_NAME | 'Windows' | +# | CMAKE_SYSTEM_NAME | "Windows", when cross-compiling | # | CMAKE_SYSTEM_PROCESSOR | The architecture to build for (e.g. ARM64). | # | CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE | The architecture of the host tooling to use (e.g. x86). | # | CMAKE_VS_PLATFORM_TOOLSET_VERSION | The version of the MSVC platform toolset to use (e.g. 14.31.31103). | diff --git a/Windows.MSVC.toolchain.cmake b/Windows.MSVC.toolchain.cmake index 5df0065..ee43a50 100644 --- a/Windows.MSVC.toolchain.cmake +++ b/Windows.MSVC.toolchain.cmake @@ -51,7 +51,7 @@ # | CMAKE_CXX_COMPILER | The path to the C++ compiler to use. | # | CMAKE_MT | The path to the 'mt.exe' tool to use. | # | CMAKE_RC_COMPILER | The path tp the 'rc.exe' tool to use. | -# | CMAKE_SYSTEM_NAME | Windows | +# | CMAKE_SYSTEM_NAME | "Windows", when cross-compiling | # | CMAKE_VS_PLATFORM_TOOLSET_VERSION | The version of the MSVC toolset being used - e.g. 14.29.30133. | # | WIN32 | 1 | # | MSVC | 1 | @@ -69,6 +69,7 @@ cmake_minimum_required(VERSION 3.20) include_guard() +# If `CMAKE_HOST_SYSTEM_NAME` is not 'Windows', there's nothing to do. if(NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)) return() endif() @@ -76,9 +77,7 @@ endif() option(TOOLCHAIN_UPDATE_PROGRAM_PATH "Whether the toolchain should update CMAKE_PROGRAM_PATH." ON) set(UNUSED ${CMAKE_TOOLCHAIN_FILE}) # Note: only to prevent cmake unused variable warninig -set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES - CMAKE_CROSSCOMPILING CMAKE_SYSTEM_PROCESSOR CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE CMAKE_VS_PRODUCTS @@ -88,16 +87,22 @@ set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES VS_INSTALLATION_VERSION VS_PLATFORM_TOOLSET_VERSION ) -set(CMAKE_CROSSCOMPILING TRUE) set(WIN32 1) set(MSVC 1) include("${CMAKE_CURRENT_LIST_DIR}/VSWhere.cmake") +# If `CMAKE_SYSTEM_PROCESSOR` isn't set, default to `CMAKE_HOST_SYSTEM_PROCESSOR` if(NOT CMAKE_SYSTEM_PROCESSOR) set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) endif() +# If `CMAKE_SYSTEM_PROCESSOR` is not equal to `CMAKE_HOST_SYSTEM_PROCESSOR`, this is cross-compilation. +# CMake expects `CMAKE_SYSTEM_NAME` to be set to reflect cross-compilation. +if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})) + set(CMAKE_SYSTEM_NAME Windows) +endif() + if(NOT CMAKE_VS_VERSION_RANGE) set(CMAKE_VS_VERSION_RANGE "[16.0,)") endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 65de252..5826b8c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -11,9 +11,11 @@ project(WindowsToolchainExample) # Write properties that are influenced by the toolchain # +message(STATUS "CMAKE_CROSSCOMPILING = ${CMAKE_CROSSCOMPILING}") +message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}") message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}") -message(STATUS "MSVC_VERSION = ${MSVC_VERSION}") message(STATUS "MSVC_TOOLSET_VERSION = ${MSVC_TOOLSET_VERSION}") +message(STATUS "MSVC_VERSION = ${MSVC_VERSION}") # Demonstrate that toolchain-related tooling can be found # diff --git a/example/CMakePresets.json b/example/CMakePresets.json index 171696b..9daf7f1 100644 --- a/example/CMakePresets.json +++ b/example/CMakePresets.json @@ -100,6 +100,12 @@ "CMAKE_SYSTEM_PROCESSOR": "ARM64" } }, + { + "name": "windows-msvc-host", + "inherits": "windows-msvc", + "displayName": "Configure for 'windows-msvc-host'", + "binaryDir": "${sourceDir}/__output/${presetName}" + }, { "name": "windows-clang-x64", "inherits": "windows-clang", @@ -184,6 +190,10 @@ "name": "windows-msvc-arm64", "configurePreset": "windows-msvc-arm64" }, + { + "name": "windows-msvc-host", + "configurePreset": "windows-msvc-host" + }, { "name": "windows-clang-x64", "configurePreset": "windows-clang-x64"