@@ -8,34 +8,35 @@ function(add_swift_target target)
8
8
9
9
cmake_parse_arguments (AST "${options} " "${single_value_options} " "${multiple_value_options} " ${ARGN} )
10
10
11
- set (flags ${CMAKE_SWIFT_FLAGS} )
11
+ set (compile_flags ${CMAKE_SWIFT_FLAGS} )
12
12
set (link_flags )
13
13
14
14
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} )
16
17
endif ()
17
18
if (AST_MODULE_NAME )
18
- list (APPEND flags -module-name;${AST_MODULE_NAME} )
19
+ list (APPEND compile_flags -module-name;${AST_MODULE_NAME} )
19
20
else ()
20
- list (APPEND flags -module-name;${target} )
21
+ list (APPEND compile_flags -module-name;${target} )
21
22
endif ()
22
23
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} )
24
25
endif ()
25
26
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} )
27
28
endif ()
28
29
if (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo )
29
- list (APPEND flags -g )
30
+ list (APPEND compile_flags -g )
30
31
endif ()
31
32
if (AST_SWIFT_FLAGS )
32
33
foreach (flag ${AST_SWIFT_FLAGS} )
33
- list (APPEND flags ${flag} )
34
+ list (APPEND compile_flags ${flag} )
34
35
endforeach ()
35
36
endif ()
36
37
if (AST_CFLAGS )
37
38
foreach (flag ${AST_CFLAGS} )
38
- list (APPEND flags -Xcc;${flag} )
39
+ list (APPEND compile_flags -Xcc;${flag} )
39
40
endforeach ()
40
41
endif ()
41
42
if (AST_LINK_FLAGS )
@@ -83,7 +84,7 @@ function(add_swift_target target)
83
84
${source}
84
85
${AST_DEPENDS}
85
86
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} )
87
88
88
89
list (APPEND objs ${obj} )
89
90
list (APPEND mods ${mod} )
@@ -106,7 +107,7 @@ function(add_swift_target target)
106
107
${docs}
107
108
${AST_DEPENDS}
108
109
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} )
110
111
endif ()
111
112
112
113
if (AST_LIBRARY )
@@ -155,3 +156,35 @@ function(add_swift_executable executable)
155
156
add_swift_target (${executable} ${ARGN} )
156
157
endfunction ()
157
158
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