Skip to content

Commit 7874a92

Browse files
Merge pull request swiftlang#429 from compnerd/image
build improvements
2 parents 5bcd598 + ea2a03d commit 7874a92

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
166166
endif()
167167
install(TARGETS
168168
BlocksRuntime
169-
DESTINATION
170-
${INSTALL_TARGET_DIR})
169+
ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
170+
LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
171+
RUNTIME DESTINATION bin)
171172
endif()
172173

173174
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)

cmake/modules/SwiftSupport.cmake

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include(CMakeParseArguments)
44
function(add_swift_target target)
55
set(options LIBRARY;SHARED;STATIC)
66
set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET)
7-
set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;SOURCES;SWIFT_FLAGS)
7+
set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;RESOURCES;SOURCES;SWIFT_FLAGS)
88

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

@@ -70,6 +70,11 @@ function(add_swift_target target)
7070
set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}${CMAKE_EXECUTABLE_SUFFIX})
7171
endif()
7272
endif()
73+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
74+
if(AST_SHARED OR BUILD_SHARED_LIBS)
75+
set(IMPORT_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_IMPORT_LIBRARY_PREFIX}${target}${CMAKE_IMPORT_LIBRARY_SUFFIX})
76+
endif()
77+
endif()
7378

7479
set(sources)
7580
foreach(source ${AST_SOURCES})
@@ -132,16 +137,14 @@ function(add_swift_target target)
132137
if(AST_LIBRARY)
133138
set(emit_library -emit-library)
134139
endif()
135-
if(library_kind STREQUAL SHARED)
140+
if(NOT AST_LIBRARY OR library_kind STREQUAL SHARED)
136141
add_custom_command(OUTPUT
137142
${AST_OUTPUT}
138143
DEPENDS
139144
${objs}
140145
${AST_DEPENDS}
141146
COMMAND
142-
${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs}
143-
COMMAND
144-
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR})
147+
${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs})
145148
add_custom_target(${target}
146149
ALL
147150
DEPENDS
@@ -150,6 +153,7 @@ function(add_swift_target target)
150153
${documentation})
151154
else()
152155
add_library(${target}-static STATIC ${objs})
156+
add_dependencies(${target}-static ${AST_DEPENDS})
153157
get_filename_component(ast_output_bn ${AST_OUTPUT} NAME)
154158
get_filename_component(ast_output_dn ${AST_OUTPUT} DIRECTORY)
155159
set_target_properties(${target}-static
@@ -164,6 +168,35 @@ function(add_swift_target target)
164168
${module}
165169
${documentation})
166170
endif()
171+
172+
if(AST_RESOURCES)
173+
add_custom_command(TARGET
174+
${target}
175+
POST_BUILD
176+
COMMAND
177+
${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target}
178+
COMMAND
179+
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${target}
180+
COMMAND
181+
${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources
182+
COMMAND
183+
${CMAKE_COMMAND} -E copy ${AST_RESOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources)
184+
else()
185+
add_custom_command(TARGET
186+
${target}
187+
POST_BUILD
188+
COMMAND
189+
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR})
190+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
191+
if(AST_SHARED OR BUILD_SHARED_LIBS)
192+
add_custom_command(TARGET
193+
${target}
194+
POST_BUILD
195+
COMMAND
196+
${CMAKE_COMMAND} -E copy ${IMPORT_LIBRARY} ${CMAKE_CURRENT_BINARY_DIR})
197+
endif()
198+
endif()
199+
endif()
167200
endfunction()
168201

169202
function(add_swift_library library)

os/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
install(FILES
66
object.h
77
generic_unix_base.h
8+
generic_win_base.h
89
DESTINATION
910
"${INSTALL_OS_HEADERS_DIR}")
1011

src/CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ if(WIN32)
174174
PRIVATE
175175
_CRT_NONSTDC_NO_WARNINGS)
176176
endif()
177-
if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
177+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
178+
target_compile_options(dispatch PRIVATE /EHs-c-)
179+
else()
178180
target_compile_options(dispatch PRIVATE -fno-exceptions)
179181
endif()
180182
if(DISPATCH_ENABLE_ASSERTS)
@@ -247,8 +249,10 @@ dispatch_set_linker(dispatch)
247249

248250
install(TARGETS
249251
dispatch
250-
DESTINATION
251-
"${INSTALL_TARGET_DIR}")
252+
ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
253+
LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
254+
RUNTIME DESTINATION bin)
255+
252256
if(ENABLE_SWIFT)
253257
install(FILES
254258
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
@@ -267,5 +271,13 @@ if(ENABLE_SWIFT)
267271
${swiftDispatch_OUTPUT_FILE}
268272
DESTINATION
269273
${INSTALL_TARGET_DIR})
274+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
275+
if(BUILD_SHARED_LIBS)
276+
install(FILES
277+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}swiftDispatch${CMAKE_IMPORT_LIBRARY_SUFFIX}
278+
DESTINATION
279+
${INSTALL_TARGET_DIR})
280+
endif()
281+
endif()
270282
endif()
271283

0 commit comments

Comments
 (0)