1
1
2
2
include (CMakeParseArguments )
3
+ include (SwiftBenchmarkUtils )
3
4
4
5
# Run a shell command and assign output to a variable or fail with an error.
5
6
# Example usage:
@@ -20,7 +21,7 @@ function(runcmd)
20
21
endfunction (runcmd )
21
22
22
23
function (add_swift_benchmark_library objfile_out sibfile_out )
23
- cmake_parse_arguments (BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS" ${ARGN} )
24
+ cmake_parse_arguments (BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS;DEPENDS " ${ARGN} )
24
25
25
26
precondition (BENCHLIB_MODULE_PATH )
26
27
precondition (BENCHLIB_SOURCE_DIR )
@@ -39,7 +40,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
39
40
precondition (objfile_out )
40
41
add_custom_command (
41
42
OUTPUT "${objfile} "
42
- DEPENDS ${stdlib_dependencies} ${sources}
43
+ DEPENDS ${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
43
44
COMMAND "${SWIFT_EXEC} "
44
45
${BENCHLIB_LIBRARY_FLAGS}
45
46
"-force-single-frontend-invocation"
@@ -58,7 +59,7 @@ function (add_swift_benchmark_library objfile_out sibfile_out)
58
59
add_custom_command (
59
60
OUTPUT "${sibfile} "
60
61
DEPENDS
61
- ${stdlib_dependencies} ${sources}
62
+ ${stdlib_dependencies} ${sources} ${BENCHLIB_DEPENDS}
62
63
COMMAND "${SWIFT_EXEC} "
63
64
${BENCHLIB_LIBRARY_FLAGS}
64
65
"-force-single-frontend-invocation"
@@ -120,89 +121,47 @@ function (swift_benchmark_compile_archopts)
120
121
set (bench_library_sibfiles )
121
122
# Build libraries used by the driver and benchmarks.
122
123
foreach (module_name_path ${BENCH_LIBRARY_MODULES} )
123
- get_filename_component (module_name "${module_name_path} " NAME )
124
-
125
- set (objfile "${objdir} /${module_name} .o" )
126
- set (swiftmodule "${objdir} /${module_name} .swiftmodule" )
127
- set (source "${srcdir} /${module_name_path} .swift" )
128
- list (APPEND bench_library_objects "${objfile} " )
129
- add_custom_command (
130
- OUTPUT "${objfile} "
131
- DEPENDS
132
- ${stdlib_dependencies} "${source} " ${extra_sources}
133
- COMMAND "${SWIFT_EXEC} "
134
- ${common_options}
135
- "-force-single-frontend-invocation"
136
- "-parse-as-library"
137
- "-module-name" "${module_name} "
138
- "-emit-module" "-emit-module-path" "${swiftmodule} "
139
- "-o" "${objfile} "
140
- "${source} " ${extra_sources} )
124
+ set (sources "${srcdir} /${module_name_path} .swift" )
125
+
126
+ add_swift_benchmark_library (objfile_out sibfile_out
127
+ MODULE_PATH "${module_name_path} "
128
+ SOURCE_DIR "${srcdir} "
129
+ OBJECT_DIR "${objdir} "
130
+ SOURCES ${sources}
131
+ LIBRARY_FLAGS ${common_options} )
132
+ precondition (objfile_out )
133
+ list (APPEND bench_library_objects "${objfile_out} " )
141
134
if (SWIFT_BENCHMARK_EMIT_SIB )
142
- set (sibfile "${objdir} /${module_name} .sib" )
143
- list (APPEND bench_library_sibfiles "${sibfile} " )
144
- add_custom_command (
145
- OUTPUT "${sibfile} "
146
- DEPENDS
147
- ${stdlib_dependencies} "${srcdir} /${module_name_path} .swift"
148
- ${extra_sources}
149
- COMMAND "${SWIFT_EXEC} "
150
- ${common_options}
151
- "-force-single-frontend-invocation"
152
- "-parse-as-library"
153
- "-module-name" "${module_name} "
154
- "-emit-sib"
155
- "-o" "${sibfile} "
156
- "${source} " ${extra_sources} )
135
+ precondition (sibfile_out )
136
+ list (APPEND bench_library_sibfiles "${sibfile_out} " )
157
137
endif ()
158
138
endforeach ()
139
+ precondition (bench_library_objects )
159
140
160
141
set (bench_driver_objects )
161
142
set (bench_driver_sibfiles )
162
143
foreach (module_name_path ${BENCH_DRIVER_LIBRARY_MODULES} )
163
- get_filename_component ( module_name "${module_name_path} " NAME )
144
+ set ( sources "${srcdir} / ${ module_name_path}.swift" )
164
145
146
+ get_filename_component (module_name "${module_name_path} " NAME )
165
147
if ("${module_name} " STREQUAL "DriverUtils" )
166
- set ( extra_sources "${srcdir} /utils/ArgParse.swift" )
148
+ list ( APPEND sources "${srcdir} /utils/ArgParse.swift" )
167
149
endif ()
168
150
169
- set (objfile "${objdir} /${module_name} .o" )
170
- set (swiftmodule "${objdir} /${module_name} .swiftmodule" )
171
- list (APPEND bench_driver_objects "${objfile} " )
172
- set (source "${srcdir} /${module_name_path} .swift" )
173
- add_custom_command (
174
- OUTPUT "${objfile} "
175
- DEPENDS
176
- ${stdlib_dependencies} ${bench_library_objects} ${source}
177
- ${extra_sources}
178
- COMMAND "${SWIFT_EXEC} "
179
- ${common_options_driver}
180
- ${BENCH_DRIVER_LIBRARY_FLAGS}
181
- "-force-single-frontend-invocation"
182
- "-parse-as-library"
183
- "-module-name" "${module_name} "
184
- "-emit-module" "-emit-module-path" "${swiftmodule} "
185
- "-I" "${objdir} "
186
- "-o" "${objfile} "
187
- "${source} " ${extra_sources} )
188
- if (SWIFT_BENCHMARK_EMIT_SIB )
189
- set (sibfile "${objdir} /${module_name} .sib" )
190
- list (APPEND bench_driver_sibfiles "${sibfile} " )
191
- add_custom_command (
192
- OUTPUT "${sibfile} "
193
- DEPENDS
194
- ${stdlib_dependencies} ${bench_library_objects} ${source}
195
- ${extra_sources}
196
- COMMAND "${SWIFT_EXEC} "
197
- ${common_options_driver}
198
- ${BENCH_DRIVER_LIBRARY_FLAGS}
199
- "-force-single-frontend-invocation"
200
- "-parse-as-library"
201
- "-module-name" "${module_name} "
202
- "-emit-sib"
203
- "-I" "${objdir} "
204
- "-o" "${sibfile} "
205
- "${source} " ${extra_sources} )
151
+ set (objfile_out )
152
+ set (sibfile_out )
153
+ add_swift_benchmark_library (objfile_out sibfile_out
154
+ MODULE_PATH "${module_name_path} "
155
+ SOURCE_DIR "${srcdir} "
156
+ OBJECT_DIR "${objdir} "
157
+ SOURCES ${sources}
158
+ LIBRARY_FLAGS ${common_options_driver} ${BENCH_DRIVER_LIBRARY_FLAGS}
159
+ DEPENDS ${bench_library_objects} )
160
+ precondition (objfile_out )
161
+ list (APPEND bench_driver_objects "${objfile_out} " )
162
+ if (SWIFT_BENCHMARK_EMIT_SIB )
163
+ precondition (sibfile_out )
164
+ list (APPEND bench_driver_sibfiles "${sibfile_out} " )
206
165
endif ()
207
166
endforeach ()
208
167
0 commit comments