summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorShoaib Meenai <smeenai@fb.com>2017-12-13 23:12:38 +0000
committerShoaib Meenai <smeenai@fb.com>2017-12-13 23:12:38 +0000
commitf04a54fea944da9d6fbb0f9498a9570233eb2bad (patch)
tree2f91d5a3c388f120a487fdfb1fc56b21bbb6f329 /cmake
parent078619235a265ee16cacdf01c69ef41b1b34fc15 (diff)
[cmake] Support host architectures other than x64
Allow building for other architectures when cross-compiling for Windows. Differential Revision: https://reviews.llvm.org/D41158 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/platforms/WinMsvc.cmake33
1 files changed, 28 insertions, 5 deletions
diff --git a/cmake/platforms/WinMsvc.cmake b/cmake/platforms/WinMsvc.cmake
index 34e6bbb9f9b..05c78648f17 100644
--- a/cmake/platforms/WinMsvc.cmake
+++ b/cmake/platforms/WinMsvc.cmake
@@ -4,11 +4,15 @@
# Usage:
# cmake -G Ninja
# -DCMAKE_TOOLCHAIN_FILE=/path/to/this/file
+# -DHOST_ARCH=[aarch64|arm64|armv7|arm|i686|x86|x86_64|x64]
# -DLLVM_NATIVE_TOOLCHAIN=/path/to/llvm/installation
# -DMSVC_BASE=/path/to/MSVC/system/libraries/and/includes
# -DWINSDK_BASE=/path/to/windows-sdk
# -DWINSDK_VER=windows sdk version folder name
#
+# HOST_ARCH:
+# The architecture to build for.
+#
# LLVM_NATIVE_TOOLCHAIN:
# *Absolute path* to a folder containing the toolchain which will be used to
# build. At a minimum, this folder should have a bin directory with a
@@ -106,16 +110,35 @@ function(init_user_prop prop)
endif()
endfunction()
-# FIXME: We should support target architectures other than x64
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10.0)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
+init_user_prop(HOST_ARCH)
init_user_prop(LLVM_NATIVE_TOOLCHAIN)
init_user_prop(MSVC_BASE)
init_user_prop(WINSDK_BASE)
init_user_prop(WINSDK_VER)
+if(NOT HOST_ARCH)
+ set(HOST_ARCH x86_64)
+endif()
+if(HOST_ARCH STREQUAL "aarch64" OR HOST_ARCH STREQUAL "arm64")
+ set(TRIPLE_ARCH "aarch64")
+ set(WINSDK_ARCH "arm64")
+elseif(HOST_ARCH STREQUAL "armv7" OR HOST_ARCH STREQUAL "arm")
+ set(TRIPLE_ARCH "armv7")
+ set(WINSDK_ARCH "arm")
+elseif(HOST_ARCH STREQUAL "i686" OR HOST_ARCH STREQUAL "x86")
+ set(TRIPLE_ARCH "i686")
+ set(WINSDK_ARCH "x86")
+elseif(HOST_ARCH STREQUAL "x86_64" OR HOST_ARCH STREQUAL "x64")
+ set(TRIPLE_ARCH "x86_64")
+ set(WINSDK_ARCH "x64")
+else()
+ message(SEND_ERROR "Unknown host architecture ${HOST_ARCH}. Must be aarch64 (or arm64), armv7 (or arm), i686 (or x86), or x86_64 (or x64).")
+endif()
+
set(MSVC_INCLUDE "${MSVC_BASE}/include")
set(MSVC_LIB "${MSVC_BASE}/lib")
set(WINSDK_INCLUDE "${WINSDK_BASE}/Include/${WINSDK_VER}")
@@ -164,6 +187,7 @@ set(CROSS_TOOLCHAIN_FLAGS_NATIVE "${_CTF_NATIVE_DEFAULT}" CACHE STRING "")
set(COMPILE_FLAGS
-D_CRT_SECURE_NO_WARNINGS
+ --target=${TRIPLE_ARCH}-windows-msvc
-fms-compatibility-version=19.11
-imsvc "${MSVC_INCLUDE}"
-imsvc "${WINSDK_INCLUDE}/ucrt"
@@ -189,10 +213,9 @@ set(LINK_FLAGS
# Prevent CMake from attempting to invoke mt.exe. It only recognizes the slashed form and not the dashed form.
/manifest:no
- # FIXME: We should support target architectures other than x64.
- -libpath:"${MSVC_LIB}/x64"
- -libpath:"${WINSDK_LIB}/ucrt/x64"
- -libpath:"${WINSDK_LIB}/um/x64")
+ -libpath:"${MSVC_LIB}/${WINSDK_ARCH}"
+ -libpath:"${WINSDK_LIB}/ucrt/${WINSDK_ARCH}"
+ -libpath:"${WINSDK_LIB}/um/${WINSDK_ARCH}")
string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}")