Skip to content

Commit 10140f4

Browse files
authored
Merge pull request #250 from compnerd/synchrony
build: synchronise SwiftSupport.cmake from Foundation
2 parents f87d304 + 364eca3 commit 10140f4

File tree

2 files changed

+79
-20
lines changed

2 files changed

+79
-20
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ add_swift_library(XCTest
5656
XCTest
5757
MODULE_PATH
5858
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
59-
OUTPUT
60-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}XCTest${CMAKE_SHARED_LIBRARY_SUFFIX}
6159
LINK_FLAGS
6260
-L${XCTEST_PATH_TO_LIBDISPATCH_BUILD}
6361
-L${XCTEST_PATH_TO_LIBDISPATCH_BUILD}/src -ldispatch

cmake/modules/SwiftSupport.cmake

+79-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
include(CMakeParseArguments)
33

44
function(add_swift_target target)
5-
set(options LIBRARY)
5+
set(options LIBRARY;SHARED;STATIC)
66
set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET)
77
set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;RESOURCES;SOURCES;SWIFT_FLAGS)
88

@@ -44,13 +44,35 @@ function(add_swift_target target)
4444
list(APPEND link_flags ${flag})
4545
endforeach()
4646
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()
4760
if(NOT AST_OUTPUT)
4861
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()
5067
else()
5168
set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}${CMAKE_EXECUTABLE_SUFFIX})
5269
endif()
5370
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()
5476

5577
set(sources)
5678
foreach(source ${AST_SOURCES})
@@ -113,19 +135,42 @@ function(add_swift_target target)
113135
if(AST_LIBRARY)
114136
set(emit_library -emit-library)
115137
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()
129174

130175
if(AST_RESOURCES)
131176
add_custom_command(TARGET
@@ -136,15 +181,29 @@ function(add_swift_target target)
136181
COMMAND
137182
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${target}
138183
COMMAND
139-
${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources
140-
COMMAND
141-
${CMAKE_COMMAND} -E copy ${AST_RESOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources)
184+
${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources)
185+
foreach(resource ${AST_RESOURCES})
186+
add_custom_command(TARGET
187+
${target}
188+
POST_BUILD
189+
COMMAND
190+
${CMAKE_COMMAND} -E copy ${resource} ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources/)
191+
endforeach()
142192
else()
143193
add_custom_command(TARGET
144194
${target}
145195
POST_BUILD
146196
COMMAND
147197
${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()
148207
endif()
149208
endfunction()
150209

@@ -184,6 +243,8 @@ function(get_swift_host_arch result_var_name)
184243
set("${result_var_name}" "itanium" PARENT_SCOPE)
185244
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
186245
set("${result_var_name}" "i686" PARENT_SCOPE)
246+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
247+
set("${result_var_name}" "i686" PARENT_SCOPE)
187248
else()
188249
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
189250
endif()

0 commit comments

Comments
 (0)