2
2
include (CMakeParseArguments )
3
3
4
4
function (add_swift_target target )
5
- set (options LIBRARY )
5
+ set (options LIBRARY;SHARED;STATIC )
6
6
set (single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET )
7
7
set (multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;RESOURCES;SOURCES;SWIFT_FLAGS )
8
8
@@ -44,13 +44,35 @@ function(add_swift_target target)
44
44
list (APPEND link_flags ${flag} )
45
45
endforeach ()
46
46
endif ()
47
+ if (AST_LIBRARY )
48
+ if (AST_STATIC AND AST_SHARED )
49
+ message (SEND_ERROR "add_swift_target asked to create library as STATIC and SHARED" )
50
+ elseif (AST_STATIC OR NOT BUILD_SHARED_LIBS )
51
+ set (library_kind STATIC )
52
+ elseif (AST_SHARED OR BUILD_SHARED_LIBS )
53
+ set (library_kind SHARED )
54
+ endif ()
55
+ else ()
56
+ if (AST_STATIC OR AST_SHARED )
57
+ message (SEND_ERROR "add_swift_target asked to create executable as STATIC or SHARED" )
58
+ endif ()
59
+ endif ()
47
60
if (NOT AST_OUTPUT )
48
61
if (AST_LIBRARY )
49
- set (AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${CMAKE_SHARED_LIBRARY_PREFIX}${target}${CMAKE_SHARED_LIBRARY_SUFFIX} )
62
+ if (AST_SHARED OR BUILD_SHARED_LIBS )
63
+ set (AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${CMAKE_SHARED_LIBRARY_PREFIX}${target}${CMAKE_SHARED_LIBRARY_SUFFIX} )
64
+ else ()
65
+ set (AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${CMAKE_STATIC_LIBRARY_PREFIX}${target}${CMAKE_STATIC_LIBRARY_SUFFIX} )
66
+ endif ()
50
67
else ()
51
68
set (AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${target}${CMAKE_EXECUTABLE_SUFFIX} )
52
69
endif ()
53
70
endif ()
71
+ if (CMAKE_SYSTEM_NAME STREQUAL Windows )
72
+ if (AST_SHARED OR BUILD_SHARED_LIBS )
73
+ set (IMPORT_LIBRARY ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${CMAKE_IMPORT_LIBRARY_PREFIX}${target}${CMAKE_IMPORT_LIBRARY_SUFFIX} )
74
+ endif ()
75
+ endif ()
54
76
55
77
set (sources )
56
78
foreach (source ${AST_SOURCES} )
@@ -113,19 +135,42 @@ function(add_swift_target target)
113
135
if (AST_LIBRARY )
114
136
set (emit_library -emit-library )
115
137
endif ()
116
- add_custom_command (OUTPUT
117
- ${AST_OUTPUT}
118
- DEPENDS
119
- ${objs}
120
- ${AST_DEPENDS}
121
- COMMAND
122
- ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs} )
123
- add_custom_target (${target}
124
- ALL
125
- DEPENDS
126
- ${AST_OUTPUT}
127
- ${module}
128
- ${documentation} )
138
+ if (NOT AST_LIBRARY OR library_kind STREQUAL SHARED )
139
+ add_custom_command (OUTPUT
140
+ ${AST_OUTPUT}
141
+ DEPENDS
142
+ ${objs}
143
+ ${AST_DEPENDS}
144
+ COMMAND
145
+ ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs} )
146
+ add_custom_target (${target}
147
+ ALL
148
+ DEPENDS
149
+ ${AST_OUTPUT}
150
+ ${module}
151
+ ${documentation} )
152
+ else ()
153
+ add_library (${target} -static STATIC ${objs} )
154
+ if (AST_DEPENDS )
155
+ add_dependencies (${target} -static ${AST_DEPENDS} )
156
+ endif ()
157
+ get_filename_component (ast_output_bn ${AST_OUTPUT} NAME )
158
+ string (REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX} " "" ast_output_bn ${ast_output_bn} )
159
+ string (REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX} $" "" ast_output_bn ${ast_output_bn} )
160
+ get_filename_component (ast_output_dn ${AST_OUTPUT} DIRECTORY )
161
+ set_target_properties (${target} -static
162
+ PROPERTIES
163
+ LINKER_LANGUAGE C
164
+ ARCHIVE_OUTPUT_DIRECTORY ${ast_output_dn}
165
+ OUTPUT_DIRECTORY ${ast_output_dn}
166
+ OUTPUT_NAME ${ast_output_bn} )
167
+ add_custom_target (${target}
168
+ ALL
169
+ DEPENDS
170
+ ${target} -static
171
+ ${module}
172
+ ${documentation} )
173
+ endif ()
129
174
130
175
if (AST_RESOURCES )
131
176
add_custom_command (TARGET
@@ -150,6 +195,15 @@ function(add_swift_target target)
150
195
POST_BUILD
151
196
COMMAND
152
197
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR} )
198
+ if (CMAKE_SYSTEM_NAME STREQUAL Windows )
199
+ if (AST_SHARED OR BUILD_SHARED_LIBS )
200
+ add_custom_command (TARGET
201
+ ${target}
202
+ POST_BUILD
203
+ COMMAND
204
+ ${CMAKE_COMMAND} -E copy ${IMPORT_LIBRARY} ${CMAKE_CURRENT_BINARY_DIR} )
205
+ endif ()
206
+ endif ()
153
207
endif ()
154
208
endfunction ()
155
209
@@ -189,6 +243,8 @@ function(get_swift_host_arch result_var_name)
189
243
set ("${result_var_name} " "itanium" PARENT_SCOPE )
190
244
elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86" )
191
245
set ("${result_var_name} " "i686" PARENT_SCOPE )
246
+ elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i686" )
247
+ set ("${result_var_name} " "i686" PARENT_SCOPE )
192
248
else ()
193
249
message (FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR} " )
194
250
endif ()
0 commit comments