Skip to content

Commit 52d876b

Browse files
authored
Merge pull request #229 from apple/build
Build Fixes
2 parents 033a5d1 + 286c113 commit 52d876b

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
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: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,35 @@ function(add_swift_target target)
88

99
cmake_parse_arguments(AST "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN})
1010

11-
set(flags ${CMAKE_SWIFT_FLAGS})
11+
set(compile_flags ${CMAKE_SWIFT_FLAGS})
1212
set(link_flags)
1313

1414
if(AST_TARGET)
15-
list(APPEND flags -target;${AST_TARGET})
15+
list(APPEND compile_flags -target;${AST_TARGET})
16+
list(APPEND link_flags -target;${AST_TARGET})
1617
endif()
1718
if(AST_MODULE_NAME)
18-
list(APPEND flags -module-name;${AST_MODULE_NAME})
19+
list(APPEND compile_flags -module-name;${AST_MODULE_NAME})
1920
else()
20-
list(APPEND flags -module-name;${target})
21+
list(APPEND compile_flags -module-name;${target})
2122
endif()
2223
if(AST_MODULE_LINK_NAME)
23-
list(APPEND flags -module-link-name;${AST_MODULE_LINK_NAME})
24+
list(APPEND compile_flags -module-link-name;${AST_MODULE_LINK_NAME})
2425
endif()
2526
if(AST_MODULE_CACHE_PATH)
26-
list(APPEND flags -module-cache-path;${AST_MODULE_CACHE_PATH})
27+
list(APPEND compile_flags -module-cache-path;${AST_MODULE_CACHE_PATH})
2728
endif()
2829
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
29-
list(APPEND flags -g)
30+
list(APPEND compile_flags -g)
3031
endif()
3132
if(AST_SWIFT_FLAGS)
3233
foreach(flag ${AST_SWIFT_FLAGS})
33-
list(APPEND flags ${flag})
34+
list(APPEND compile_flags ${flag})
3435
endforeach()
3536
endif()
3637
if(AST_CFLAGS)
3738
foreach(flag ${AST_CFLAGS})
38-
list(APPEND flags -Xcc;${flag})
39+
list(APPEND compile_flags -Xcc;${flag})
3940
endforeach()
4041
endif()
4142
if(AST_LINK_FLAGS)
@@ -83,7 +84,7 @@ function(add_swift_target target)
8384
${source}
8485
${AST_DEPENDS}
8586
COMMAND
86-
${CMAKE_SWIFT_COMPILER} -frontend ${flags} -emit-module-path ${mod} -emit-module-doc-path ${doc} -o ${obj} -c ${all_sources})
87+
${CMAKE_SWIFT_COMPILER} -frontend ${compile_flags} -emit-module-path ${mod} -emit-module-doc-path ${doc} -o ${obj} -c ${all_sources})
8788

8889
list(APPEND objs ${obj})
8990
list(APPEND mods ${mod})
@@ -106,7 +107,7 @@ function(add_swift_target target)
106107
${docs}
107108
${AST_DEPENDS}
108109
COMMAND
109-
${CMAKE_SWIFT_COMPILER} -frontend ${flags} -sil-merge-partial-modules -emit-module ${mods} -o ${module} -emit-module-doc-path ${documentation})
110+
${CMAKE_SWIFT_COMPILER} -frontend ${compile_flags} -sil-merge-partial-modules -emit-module ${mods} -o ${module} -emit-module-doc-path ${documentation})
110111
endif()
111112

112113
if(AST_LIBRARY)
@@ -155,3 +156,35 @@ function(add_swift_executable executable)
155156
add_swift_target(${executable} ${ARGN})
156157
endfunction()
157158

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)