1
1
2
2
include (CMakeParseArguments )
3
+ include (ProcessorCount )
4
+
5
+ # Creates an output file map give a target and its list of sources at
6
+ # output_path
7
+ #
8
+ # Usage:
9
+ # create_output_file_map(target sources output_path)
10
+ function (create_output_file_map target sources output_path )
11
+ set (output_list )
12
+ set (output_file_map "{\n " )
13
+ foreach (source ${sources} )
14
+ get_filename_component (name ${source} NAME )
15
+
16
+ set (obj ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}${CMAKE_C_OUTPUT_EXTENSION} )
17
+ set (deps ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}.d )
18
+ set (swiftdeps ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}.swiftdeps )
19
+ set (dia ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}.dia )
20
+ set (output_entry "\" ${source} \" : {\n\
21
+ \" object\" : \" ${obj} \" ,\n\
22
+ \" dependencies\" : \" ${deps} \" ,\n\
23
+ \" swift-dependencies\" : \" ${swiftdeps} \" ,\n\
24
+ \" diagnostics\" : \" ${dia} \"\n\
25
+ },\n " )
26
+ string (APPEND output_file_map ${output_entry} )
27
+ endforeach ()
28
+ set (master_deps ${CMAKE_CURRENT_BINARY_DIR} /${target}.swiftdeps )
29
+ string (APPEND output_file_map "\"\" : {\n\
30
+ \" swift-dependencies\" : \" ${master_deps} \"\n\
31
+ }\n " )
32
+ string (APPEND output_file_map "}\n " )
33
+ file (WRITE ${output_path} ${output_file_map} )
34
+ endfunction ()
3
35
4
36
function (add_swift_target target )
5
37
set (options LIBRARY;SHARED;STATIC )
@@ -9,8 +41,13 @@ function(add_swift_target target)
9
41
cmake_parse_arguments (AST "${options} " "${single_value_options} " "${multiple_value_options} " ${ARGN} )
10
42
11
43
set (compile_flags ${CMAKE_SWIFT_FLAGS} )
12
- set (link_flags )
44
+ set (link_flags ${CMAKE_SWIFT_LINK_FLAGS} )
13
45
46
+ list (APPEND compile_flags -incremental )
47
+ ProcessorCount (CPU_COUNT )
48
+ if (NOT CPU_COUNT EQUAL 0 )
49
+ list (APPEND compile_flags -j;${CPU_COUNT} )
50
+ endif ()
14
51
if (AST_TARGET )
15
52
list (APPEND compile_flags -target;${AST_TARGET} )
16
53
list (APPEND link_flags -target;${AST_TARGET} )
@@ -26,6 +63,11 @@ function(add_swift_target target)
26
63
if (AST_MODULE_CACHE_PATH )
27
64
list (APPEND compile_flags -module-cache-path;${AST_MODULE_CACHE_PATH} )
28
65
endif ()
66
+ if (AST_MODULE_PATH )
67
+ get_filename_component (module_location ${AST_MODULE_PATH} PATH )
68
+ file (MAKE_DIRECTORY "${module_location} " )
69
+ list (APPEND compile_flags "-emit-module-path;${AST_MODULE_PATH} " )
70
+ endif ()
29
71
if (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo )
30
72
list (APPEND compile_flags -g )
31
73
endif ()
@@ -75,82 +117,45 @@ function(add_swift_target target)
75
117
endif ()
76
118
77
119
set (sources )
120
+ set (rsp_text )
78
121
foreach (source ${AST_SOURCES} )
79
122
get_filename_component (location ${source} PATH )
80
123
if (IS_ABSOLUTE ${location} )
81
124
list (APPEND sources ${source} )
125
+ string (APPEND rsp_text "${source} " )
82
126
else ()
83
127
list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR} /${source} )
128
+ string (APPEND rsp_text "${CMAKE_CURRENT_SOURCE_DIR} /${source} " )
84
129
endif ()
85
130
endforeach ()
86
131
87
- set (objs )
88
- set (mods )
89
- set (docs )
90
- set (i 0 )
91
- foreach (source ${sources} )
92
- get_filename_component (name ${source} NAME )
93
-
94
- set (obj ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}${CMAKE_C_OUTPUT_EXTENSION} )
95
- set (mod ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}.swiftmodule )
96
- set (doc ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${name}.swiftdoc )
97
-
98
- set (all_sources ${sources} )
99
- list (INSERT all_sources ${i} -primary-file )
100
-
101
- add_custom_command (OUTPUT
102
- ${obj}
103
- ${mod}
104
- ${doc}
105
- DEPENDS
106
- ${source}
107
- ${AST_DEPENDS}
108
- COMMAND
109
- ${CMAKE_SWIFT_COMPILER} -frontend ${compile_flags} -emit-module-path ${mod} -emit-module-doc-path ${doc} -o ${obj} -c ${all_sources} )
110
-
111
- list (APPEND objs ${obj} )
112
- list (APPEND mods ${mod} )
113
- list (APPEND docs ${doc} )
132
+ set (output_map_path ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/output-file-map.json )
133
+ create_output_file_map (${target} "${sources} " ${output_map_path} )
134
+ list (APPEND compile_flags -output-file-map;${output_map_path} )
114
135
115
- math (EXPR i "${i} +1" )
116
- endforeach ()
136
+ string (LENGTH sources source_length )
137
+ set (rsp_file ${CMAKE_CURRENT_BINARY_DIR} /${target}.dir/${target}.rsp )
138
+ file (WRITE ${rsp_file} ${rsp_text} )
117
139
118
140
if (AST_LIBRARY )
119
- get_filename_component (module_directory ${AST_MODULE_PATH} DIRECTORY )
120
-
121
- set (module ${AST_MODULE_PATH} )
122
- set (documentation ${module_directory} /${AST_MODULE_NAME}.swiftdoc )
123
-
124
- add_custom_command (OUTPUT
125
- ${module}
126
- ${documentation}
127
- DEPENDS
128
- ${mods}
129
- ${docs}
130
- ${AST_DEPENDS}
131
- COMMAND
132
- ${CMAKE_SWIFT_COMPILER} -frontend ${compile_flags} -sil-merge-partial-modules -emit-module ${mods} -o ${module} -emit-module-doc-path ${documentation} )
133
- endif ()
134
-
135
- if (AST_LIBRARY )
136
- set (emit_library -emit-library )
141
+ set (emit_library -emit-library )
137
142
endif ()
138
143
if (NOT AST_LIBRARY OR library_kind STREQUAL SHARED )
139
144
add_custom_command (OUTPUT
140
145
${AST_OUTPUT}
141
146
DEPENDS
142
- ${objs }
147
+ ${sources }
143
148
${AST_DEPENDS}
144
149
COMMAND
145
- ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs } )
150
+ ${CMAKE_SWIFT_COMPILER} ${emit_library} ${compile_flags} ${ link_flags} -o ${AST_OUTPUT} @${rsp_file } )
146
151
add_custom_target (${target}
147
152
ALL
148
153
DEPENDS
149
154
${AST_OUTPUT}
150
155
${module}
151
156
${documentation} )
152
157
else ()
153
- add_library (${target} -static STATIC ${objs } )
158
+ add_library (${target} -static STATIC ${sources } )
154
159
if (AST_DEPENDS )
155
160
add_dependencies (${target} -static ${AST_DEPENDS} )
156
161
endif ()
@@ -177,6 +182,11 @@ function(add_swift_target target)
177
182
endif ()
178
183
179
184
if (AST_RESOURCES )
185
+ if (CMAKE_SYSTEM_NAME STREQUAL Windows )
186
+ set (resources_dir ${target} .resources )
187
+ else ()
188
+ set (resources_dir Resources )
189
+ endif ()
180
190
add_custom_command (TARGET
181
191
${target}
182
192
POST_BUILD
@@ -185,13 +195,22 @@ function(add_swift_target target)
185
195
COMMAND
186
196
${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR} /${target}
187
197
COMMAND
188
- ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /${target}/Resources )
198
+ ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /${target}/${resources_dir} )
189
199
foreach (resource ${AST_RESOURCES} )
190
- add_custom_command (TARGET
191
- ${target}
192
- POST_BUILD
193
- COMMAND
194
- ${CMAKE_COMMAND} -E copy ${resource} ${CMAKE_CURRENT_BINARY_DIR} /${target}/Resources/ )
200
+ if (IS_DIRECTORY ${resource} )
201
+ get_filename_component (resource_basename ${resource} NAME )
202
+ add_custom_command (TARGET
203
+ ${target}
204
+ POST_BUILD
205
+ COMMAND
206
+ ${CMAKE_COMMAND} -E copy_directory ${resource} ${CMAKE_CURRENT_BINARY_DIR} /${target}/${resources_dir}/${resource_basename} )
207
+ else ()
208
+ add_custom_command (TARGET
209
+ ${target}
210
+ POST_BUILD
211
+ COMMAND
212
+ ${CMAKE_COMMAND} -E copy ${resource} ${CMAKE_CURRENT_BINARY_DIR} /${target}/${resources_dir}/ )
213
+ endif ()
195
214
endforeach ()
196
215
else ()
197
216
add_custom_command (TARGET
@@ -219,7 +238,7 @@ function(add_swift_executable executable)
219
238
add_swift_target (${executable} ${ARGN} )
220
239
endfunction ()
221
240
222
- # Returns the current achitecture name in a variable
241
+ # Returns the current architecture name in a variable
223
242
#
224
243
# Usage:
225
244
# get_swift_host_arch(result_var_name)
@@ -241,6 +260,8 @@ function(get_swift_host_arch result_var_name)
241
260
set ("${result_var_name} " "armv6" PARENT_SCOPE )
242
261
elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "armv7l" )
243
262
set ("${result_var_name} " "armv7" PARENT_SCOPE )
263
+ elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "armv7-a" )
264
+ set ("${result_var_name} " "armv7" PARENT_SCOPE )
244
265
elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "AMD64" )
245
266
set ("${result_var_name} " "x86_64" PARENT_SCOPE )
246
267
elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "IA64" )
0 commit comments