llvm.org GIT mirror llvm / f04a54f
[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 Shoaib Meenai 1 year, 10 months ago
1 changed file(s) with 28 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
33 # Usage:
44 # cmake -G Ninja
55 # -DCMAKE_TOOLCHAIN_FILE=/path/to/this/file
6 # -DHOST_ARCH=[aarch64|arm64|armv7|arm|i686|x86|x86_64|x64]
67 # -DLLVM_NATIVE_TOOLCHAIN=/path/to/llvm/installation
78 # -DMSVC_BASE=/path/to/MSVC/system/libraries/and/includes
89 # -DWINSDK_BASE=/path/to/windows-sdk
910 # -DWINSDK_VER=windows sdk version folder name
11 #
12 # HOST_ARCH:
13 # The architecture to build for.
1014 #
1115 # LLVM_NATIVE_TOOLCHAIN:
1216 # *Absolute path* to a folder containing the toolchain which will be used to
105109 endif()
106110 endfunction()
107111
108 # FIXME: We should support target architectures other than x64
109112 set(CMAKE_SYSTEM_NAME Windows)
110113 set(CMAKE_SYSTEM_VERSION 10.0)
111114 set(CMAKE_SYSTEM_PROCESSOR AMD64)
112115
116 init_user_prop(HOST_ARCH)
113117 init_user_prop(LLVM_NATIVE_TOOLCHAIN)
114118 init_user_prop(MSVC_BASE)
115119 init_user_prop(WINSDK_BASE)
116120 init_user_prop(WINSDK_VER)
121
122 if(NOT HOST_ARCH)
123 set(HOST_ARCH x86_64)
124 endif()
125 if(HOST_ARCH STREQUAL "aarch64" OR HOST_ARCH STREQUAL "arm64")
126 set(TRIPLE_ARCH "aarch64")
127 set(WINSDK_ARCH "arm64")
128 elseif(HOST_ARCH STREQUAL "armv7" OR HOST_ARCH STREQUAL "arm")
129 set(TRIPLE_ARCH "armv7")
130 set(WINSDK_ARCH "arm")
131 elseif(HOST_ARCH STREQUAL "i686" OR HOST_ARCH STREQUAL "x86")
132 set(TRIPLE_ARCH "i686")
133 set(WINSDK_ARCH "x86")
134 elseif(HOST_ARCH STREQUAL "x86_64" OR HOST_ARCH STREQUAL "x64")
135 set(TRIPLE_ARCH "x86_64")
136 set(WINSDK_ARCH "x64")
137 else()
138 message(SEND_ERROR "Unknown host architecture ${HOST_ARCH}. Must be aarch64 (or arm64), armv7 (or arm), i686 (or x86), or x86_64 (or x64).")
139 endif()
117140
118141 set(MSVC_INCLUDE "${MSVC_BASE}/include")
119142 set(MSVC_LIB "${MSVC_BASE}/lib")
163186
164187 set(COMPILE_FLAGS
165188 -D_CRT_SECURE_NO_WARNINGS
189 --target=${TRIPLE_ARCH}-windows-msvc
166190 -fms-compatibility-version=19.11
167191 -imsvc "${MSVC_INCLUDE}"
168192 -imsvc "${WINSDK_INCLUDE}/ucrt"
188212 # Prevent CMake from attempting to invoke mt.exe. It only recognizes the slashed form and not the dashed form.
189213 /manifest:no
190214
191 # FIXME: We should support target architectures other than x64.
192 -libpath:"${MSVC_LIB}/x64"
193 -libpath:"${WINSDK_LIB}/ucrt/x64"
194 -libpath:"${WINSDK_LIB}/um/x64")
215 -libpath:"${MSVC_LIB}/${WINSDK_ARCH}"
216 -libpath:"${WINSDK_LIB}/ucrt/${WINSDK_ARCH}"
217 -libpath:"${WINSDK_LIB}/um/${WINSDK_ARCH}")
195218
196219 string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}")
197220