Skip to content

Commit 286c113

Browse files
committed
build: install to the right architecture location
This ensures that we install to the right architecture subdirectory when building with CMake. This is particularly useful when cross-compiling.
1 parent b2b38a4 commit 286c113

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,14 @@ add_custom_target(check-xctest
131131
XCTest
132132
USES_TERMINAL)
133133

134-
string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
134+
string(TOLOWER ${CMAKE_SYSTEM_NAME} swift_os)
135+
get_swift_host_arch(swift_host_arch)
135136

136137
install(FILES
137138
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftdoc
138139
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
139140
DESTINATION
140-
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR})
141+
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${swift_os}/${swift_host_arch})
141142
install(FILES
142143
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}XCTest${CMAKE_SHARED_LIBRARY_SUFFIX}
143144
DESTINATION
@@ -146,5 +147,5 @@ install(FILES
146147
install(FILES
147148
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}XCTest${CMAKE_SHARED_LIBRARY_SUFFIX}
148149
DESTINATION
149-
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${SWIFT_OS})
150+
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${swift_os})
150151

cmake/modules/SwiftSupport.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,35 @@ function(add_swift_executable executable)
156156
add_swift_target(${executable} ${ARGN})
157157
endfunction()
158158

159+
# Returns the current achitecture name in a variable
160+
#
161+
# Usage:
162+
# get_swift_host_arch(result_var_name)
163+
#
164+
# If the current architecture is supported by Swift, sets ${result_var_name}
165+
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
166+
function(get_swift_host_arch result_var_name)
167+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
168+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
169+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
170+
set("${result_var_name}" "aarch64" PARENT_SCOPE)
171+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
172+
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
173+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
174+
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
175+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
176+
set("${result_var_name}" "s390x" PARENT_SCOPE)
177+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
178+
set("${result_var_name}" "armv6" PARENT_SCOPE)
179+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
180+
set("${result_var_name}" "armv7" PARENT_SCOPE)
181+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
182+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
183+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
184+
set("${result_var_name}" "itanium" PARENT_SCOPE)
185+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
186+
set("${result_var_name}" "i686" PARENT_SCOPE)
187+
else()
188+
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
189+
endif()
190+
endfunction()

0 commit comments

Comments
 (0)