1
1
2
2
include (CMakeParseArguments)
3
3
4
+ # Creates an output file map give a target and its list of sources at
5
+ # output_path
6
+ #
7
+ # Usage:
8
+ # create_output_file_map(target sources output_path)
9
+ function (create_output_file_map target sources output_path)
10
+ set (output_list)
11
+ set (output_file_map "{\n " )
12
+ foreach (source ${sources} )
13
+ get_filename_component (name ${source} NAME )
14
+
15
+ set (obj ${CMAKE_CURRENT_BINARY_DIR} /${target} .dir/${name}${CMAKE_C_OUTPUT_EXTENSION} )
16
+ set (deps ${CMAKE_CURRENT_BINARY_DIR} /${target} .dir/${name} .d)
17
+ set (swiftdeps ${CMAKE_CURRENT_BINARY_DIR} /${target} .dir/${name} .swiftdeps)
18
+ set (dia ${CMAKE_CURRENT_BINARY_DIR} /${target} .dir/${name} .dia)
19
+ set (output_entry "\" ${source} \" : {\n\
20
+ \" object\" : \" ${obj} \" ,\n\
21
+ \" dependencies\" : \" ${deps} \" ,\n\
22
+ \" swift-dependencies\" : \" ${swiftdeps} \" ,\n\
23
+ \" diagnostics\" : \" ${dia} \"\n\
24
+ },\n " )
25
+ string (APPEND output_file_map ${output_entry} )
26
+ endforeach ()
27
+ set (master_deps ${CMAKE_CURRENT_BINARY_DIR} /${target} .swiftdeps)
28
+ string (APPEND output_file_map "\"\" : {\n\
29
+ \" swift-dependencies\" : \" ${master_deps} \"\n\
30
+ }\n " )
31
+ string (APPEND output_file_map "}\n " )
32
+ file (WRITE ${output_path} ${output_file_map} )
33
+ endfunction ()
34
+
4
35
function (add_swift_target target )
5
36
set (options LIBRARY;SHARED;STATIC )
6
37
set (single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH ;MODULE_CACHE_PATH;OUTPUT ;TARGET )
@@ -11,6 +42,7 @@ function(add_swift_target target)
11
42
set (compile_flags ${CMAKE_SWIFT_FLAGS} )
12
43
set (link_flags )
13
44
45
+ list (APPEND compile_flags -incremental)
14
46
if (AST_TARGET)
15
47
list (APPEND compile_flags -target ;${AST_TARGET} )
16
48
list (APPEND link_flags -target ;${AST_TARGET} )
@@ -26,6 +58,11 @@ function(add_swift_target target)
26
58
if (AST_MODULE_CACHE_PATH)
27
59
list (APPEND compile_flags -module-cache -path ;${AST_MODULE_CACHE_PATH} )
28
60
endif ()
61
+ if (AST_MODULE_PATH)
62
+ get_filename_component (module_location ${AST_MODULE_PATH} PATH )
63
+ file (MAKE_DIRECTORY "${module_location} " )
64
+ list (APPEND compile_flags "-emit-module-path;${AST_MODULE_PATH} " )
65
+ endif ()
29
66
if (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
30
67
list (APPEND compile_flags -g)
31
68
endif ()
@@ -75,82 +112,45 @@ function(add_swift_target target)
75
112
endif ()
76
113
77
114
set (sources )
115
+ set (rsp_text)
78
116
foreach (source ${AST_SOURCES} )
79
117
get_filename_component (location ${source} PATH )
80
118
if (IS_ABSOLUTE ${location} )
81
119
list (APPEND sources ${source} )
120
+ string (APPEND rsp_text "${source} " )
82
121
else ()
83
122
list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR} /${source} )
123
+ string (APPEND rsp_text "${CMAKE_CURRENT_SOURCE_DIR} /${source} " )
84
124
endif ()
85
125
endforeach ()
86
126
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} )
114
-
115
- math (EXPR i "${i} +1" )
116
- endforeach ()
117
-
118
- 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)
127
+ set (output_map_path ${CMAKE_CURRENT_BINARY_DIR} /${target} .dir/output -file-map.json)
128
+ create_output_file_map(${target} "${sources} " ${output_map_path} )
129
+ list (APPEND compile_flags -output -file-map;${output_map_path} )
123
130
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 ()
131
+ string (LENGTH sources source_length)
132
+ set (rsp_file ${CMAKE_CURRENT_BINARY_DIR} /${target} .dir/${target} .rsp)
133
+ file (WRITE ${rsp_file} ${rsp_text} )
134
134
135
135
if (AST_LIBRARY)
136
- set (emit_library -emit-library)
136
+ set (emit_library -emit-library)
137
137
endif ()
138
138
if (NOT AST_LIBRARY OR library_kind STREQUAL SHARED)
139
139
add_custom_command (OUTPUT
140
140
${AST_OUTPUT}
141
141
DEPENDS
142
- ${objs }
142
+ ${sources }
143
143
${AST_DEPENDS}
144
144
COMMAND
145
- ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs } )
145
+ ${CMAKE_SWIFT_COMPILER} ${emit_library} ${compile_flags} ${ link_flags} -o ${AST_OUTPUT} @ ${rsp_file } )
146
146
add_custom_target (${target}
147
147
ALL
148
148
DEPENDS
149
149
${AST_OUTPUT}
150
150
${module}
151
151
${documentation} )
152
152
else ()
153
- add_library (${target} -static STATIC ${objs } )
153
+ add_library (${target} -static STATIC ${sources } )
154
154
if (AST_DEPENDS)
155
155
add_dependencies (${target} -static ${AST_DEPENDS} )
156
156
endif ()
0 commit comments