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,40 @@ 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
+ add_dependencies (${target} -static ${AST_DEPENDS} )
155
+ get_filename_component (ast_output_bn ${AST_OUTPUT} NAME )
156
+ string (REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX} " "" ast_output_bn ${ast_output_bn} )
157
+ string (REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX} $" "" ast_output_bn ${ast_output_bn} )
158
+ get_filename_component (ast_output_dn ${AST_OUTPUT} DIRECTORY )
159
+ set_target_properties (${target} -static
160
+ PROPERTIES
161
+ LINKER_LANGUAGE C
162
+ ARCHIVE_OUTPUT_DIRECTORY ${ast_output_dn}
163
+ OUTPUT_DIRECTORY ${ast_output_dn}
164
+ OUTPUT_NAME ${ast_output_bn} )
165
+ add_custom_target (${target}
166
+ ALL
167
+ DEPENDS
168
+ ${target} -static
169
+ ${module}
170
+ ${documentation} )
171
+ endif ()
129
172
130
173
if (AST_RESOURCES)
131
174
add_custom_command (TARGET
@@ -150,6 +193,15 @@ function(add_swift_target target)
150
193
POST_BUILD
151
194
COMMAND
152
195
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR} )
196
+ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
197
+ if (AST_SHARED OR BUILD_SHARED_LIBS )
198
+ add_custom_command (TARGET
199
+ ${target}
200
+ POST_BUILD
201
+ COMMAND
202
+ ${CMAKE_COMMAND} -E copy ${IMPORT_LIBRARY} ${CMAKE_CURRENT_BINARY_DIR} )
203
+ endif ()
204
+ endif ()
153
205
endif ()
154
206
endfunction ()
155
207
@@ -189,6 +241,8 @@ function(get_swift_host_arch result_var_name)
189
241
set ("${result_var_name} " "itanium" PARENT_SCOPE)
190
242
elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86" )
191
243
set ("${result_var_name} " "i686" PARENT_SCOPE)
244
+ elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i686" )
245
+ set ("${result_var_name} " "i686" PARENT_SCOPE)
192
246
else ()
193
247
message (FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR} " )
194
248
endif ()
0 commit comments