forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
410 lines (381 loc) · 10.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Special case package namespace for tools/ -> "" (empty string)
# For example, tools/iree-compile -> iree-compile (no namespace)
set(IREE_PACKAGE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
# Tools IREE provides for compiling, executing, and benchmarking programs, as
# well as other utilities.
#
# Only binary targets and their associated main files should go in this
# directory. Library targets and header files should be placed in the
# appropriate subtree, e.g. `compiler/src/iree/compiler/Tools/`.
#
# Compiler tools are designed to run on host platforms (Linux, macOS, Windows),
# so they are only built when IREE_BUILD_COMPILER is set and are tagged
# "hostonly". When cross-compiling (or generally wanting to use already-built
# compiler tools), set the IREE_HOST_BIN_DIR CMake option.
#
# This file does not use bazel_to_cmake because of special logic throughout.
# Write some important CMake options to a file for convenient use from scripts.
configure_file(build_config_template.txt.in build_config.txt)
# If cross-compiling and not building the compiler, then attempt to find
# the compiler tools.
# This is actual broken because the situation is tri-state:
# 1. Cross-compiling with no built compiler: Should work the same as
# IREE_BUILD_COMPILER=OFF in a host build (i.e. nothing depending
# on the compiler should be built).
# 2. Cross-compiling with a compiler built for the target: Anything
# on the host which needs the compiler, still must have host tools.
# 3. Normal host build.
# This simplistic setup makes #2 impossible and it overloads #1 to
# also support building things that depend on the compiler. The targets
# need to be aliased/forked for host variants to fully support. For now
# we just make all of these as OPTIONAL and let things break if not set up
# right.
if(IREE_HOST_BIN_DIR AND NOT IREE_BUILD_COMPILER)
iree_import_binary(NAME iree-tblgen OPTIONAL)
iree_import_binary(NAME iree-compile OPTIONAL)
iree_import_binary(NAME iree-opt OPTIONAL)
iree_import_binary(NAME iree-run-mlir OPTIONAL)
iree_import_binary(NAME FileCheck OPTIONAL)
iree_import_binary(NAME not OPTIONAL)
iree_import_binary(NAME clang OPTIONAL)
iree_import_binary(NAME llvm-link OPTIONAL)
endif()
# For sub-directories, we want targets fully qualified relative to the
# root. But after, we want those in *this* directory to be unqualified
# (i.e. 'iree-compile').
set(IREE_PACKAGE_ROOT_PREFIX "iree/tools")
iree_add_all_subdirs()
set(IREE_PACKAGE_ROOT_PREFIX "")
# TODO(#6353): Tools has thread dependencies in gtest, benchmark, yaml, etc.
# This should be split between runtime/compiler with optional threading support.
if(NOT IREE_ENABLE_THREADING)
return()
endif()
iree_cc_binary(
NAME
iree-benchmark-executable
SRCS
"iree-benchmark-executable-main.c"
DEPS
iree::base
iree::base::internal::flags
iree::hal
iree::modules::hal::types
iree::testing::benchmark
iree::tooling::device_util
iree::tooling::function_io
iree::vm
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-benchmark-module
SRCS
"iree-benchmark-module-main.cc"
DEPS
benchmark
iree::base
iree::base::internal::flags
iree::hal
iree::modules::hal::types
iree::tooling::context_util
iree::tooling::device_util
iree::tooling::function_io
iree::vm
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-check-module
SRCS
"iree-check-module-main.cc"
DEPS
iree::base
iree::base::internal::file_io
iree::base::internal::flags
iree::hal
iree::modules::check
iree::testing::gtest
iree::tooling::context_util
iree::tooling::device_util
iree::vm
iree::vm::bytecode::module
TESTONLY
)
iree_cc_binary(
NAME
iree-convert-parameters
SRCS
"iree-convert-parameters-main.c"
DEPS
iree::base
iree::base::internal::file_io
iree::base::internal::flags
iree::hal
iree::io::formats::irpa
iree::io::parameter_index
iree::io::scope_map
iree::tooling::parameter_util
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-cpuinfo
SRCS
"iree-cpuinfo.c"
DEPS
iree::base
iree::base::internal::cpu
iree::schemas::cpu_data
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-create-parameters
SRCS
"iree-create-parameters-main.c"
DEPS
iree::base
iree::base::internal::file_io
iree::base::internal::flags
iree::hal
iree::io::formats::irpa
iree::io::parameter_index
iree::io::scope_map
iree::io::stream
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-dump-instruments
SRCS
"iree-dump-instruments-main.c"
DEPS
flatcc::runtime
iree::base
iree::base::internal::file_io
iree::base::internal::flatcc::parsing
iree::schemas::instruments
iree::schemas::instruments::dispatch_def_c_fbs
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-dump-module
SRCS
"iree-dump-module-main.c"
DEPS
flatcc::runtime
iree::base
iree::base::internal::file_io
iree::base::internal::flags
iree::base::internal::flatcc::debugging
iree::base::internal::flatcc::parsing
iree::schemas::bytecode_module_def_c_fbs
iree::vm::bytecode::module
INSTALL_COMPONENT IREETools-Runtime
)
iree_cc_binary(
NAME
iree-dump-parameters
SRCS
"iree-dump-parameters-main.c"
DEPS
iree::base
iree::base::internal::file_io
iree::base::internal::flags
iree::io::parameter_index
iree::io::scope_map
iree::tooling::parameter_util
INSTALL_COMPONENT IREETools-Runtime
)
# Only enable fatelf tool when we're compiling it in.
# Currently it requires that the host and target both support embedded ELFs as
# the ELF implementation is only compiled when the target supports it.
if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF OR
IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF)
iree_cc_binary(
NAME
iree-fatelf
SRCS
"iree-fatelf.c"
DEPS
iree::base
iree::base::internal::file_io
iree::base::internal::path
iree::hal::local::elf::elf_module
INSTALL_COMPONENT IREETools-Runtime
)
endif() # IREE_HAL_EXECUTABLE_*_EMBEDDED_ELF
iree_cc_binary(
NAME
iree-run-module
SRCS
"iree-run-module-main.c"
DEPS
iree::base
iree::base::internal::flags
iree::hal
iree::tooling::context_util
iree::tooling::run_module
iree::vm
INSTALL_COMPONENT IREETools-Runtime
)
if(IREE_BUILD_COMPILER)
if(IREE_LLVM_LINK_TARGET)
install(
TARGETS llvm-link
COMPONENT IREETools-CompilerExtra
RUNTIME DESTINATION bin
)
endif()
if(IREE_CLANG_TARGET)
install(
TARGETS clang
COMPONENT IREETools-CompilerExtra
RUNTIME DESTINATION bin
)
endif()
if(IREE_FILECHECK_TARGET)
install(
TARGETS FileCheck
COMPONENT IREETools-CompilerDev
RUNTIME DESTINATION bin
)
endif()
if(IREE_NOT_TARGET)
install(
TARGETS not
COMPONENT IREETools-CompilerDev
RUNTIME DESTINATION bin
)
endif()
# Tablegen binaries are special snowflakes among special snowflakes.
# They must be statically linked against internal LLVM libraries, and they
# therefore must not depend on anything outside of the upstream tablegen
# libraries. These targets are specially set up to link in the correct
# way. This is a necessary diversion from how Bazel deals with it (which
# must deep-link to everything to satisfy its checks).
iree_cc_binary(
NAME
iree-tblgen
SRCS
"iree-tblgen.cpp"
"${IREE_SOURCE_DIR}/compiler/src/iree/compiler/Dialect/VM/Tools/VMOpEncoderGen.cpp"
"${IREE_SOURCE_DIR}/compiler/src/iree/compiler/Dialect/VM/Tools/VMOpTableGen.cpp"
DEPS
LLVMSupport
MLIRTblgenLib
HOSTONLY
DISABLE_LLVM_LINK_LLVM_DYLIB
INSTALL_COMPONENT IREETools-CompilerDev
)
iree_cc_binary(
NAME
iree-compile
SRCS
"iree-compile-main.cc"
DEPS
iree::compiler::bindings::c::headers
iree::compiler::API::Impl
DATA
${IREE_LLD_TARGET}
HOSTONLY
SETUP_INSTALL_RPATH
INSTALL_COMPONENT IREETools-Compiler
)
iree_cc_binary(
NAME
iree-reduce
SRCS
"iree-reduce.cc"
DEPS
iree::compiler::bindings::c::headers
iree::compiler::API::Impl
DATA
${IREE_LLD_TARGET}
HOSTONLY
SETUP_INSTALL_RPATH
INSTALL_COMPONENT IREETools-Compiler
)
# Only build IREE's busybox lld if the backing LLVM has LLD enabled.
# Otherwise, it will build but fail at runtime saying that it is not
# supported, and this fouls up tools search heuristics.
if(IREE_LLD_TARGET)
iree_cc_binary(
NAME
iree-lld
SRCS
"iree-lld-main.cc"
DEPS
iree::compiler::bindings::c::headers
iree::compiler::API::Impl
HOSTONLY
SETUP_INSTALL_RPATH
INSTALL_COMPONENT IREETools-Compiler
)
endif()
iree_cc_binary(
NAME
iree-opt
SRCS
"iree-opt-main.cc"
DEPS
iree::compiler::bindings::c::headers
iree::compiler::API::Impl
DATA
${IREE_LLD_TARGET}
HOSTONLY
SETUP_INSTALL_RPATH
INSTALL_COMPONENT IREETools-Compiler
)
iree_cc_binary(
NAME
iree-mlir-lsp-server
SRCS
"iree-mlir-lsp-server.cc"
DEPS
iree::compiler::bindings::c::headers
iree::compiler::API::Impl
SETUP_INSTALL_RPATH
INSTALL_COMPONENT IREETools-Compiler
)
iree_cc_binary(
NAME
iree-run-mlir
SRCS
"iree-run-mlir-main.cc"
DEPS
iree::base
iree::base::internal::flags
iree::compiler::bindings::c::headers
iree::compiler::API::Impl
iree::hal
iree::tooling::context_util
iree::tooling::device_util
iree::tooling::run_module
iree::vm
DATA
${IREE_LLD_TARGET}
HOSTONLY
SETUP_INSTALL_RPATH
INSTALL_COMPONENT IREETools-Compiler
)
# Ensure FileCheck and associated binaries get built. Tests don't have
# dependencies in CMake because they aren't targets. So until we fix that, we
# just force this to get built.
# Limiting this to when IREE_BUILD_TESTS is set prevents the installation
# below, which we use for cross-platform testing.
set_target_properties(FileCheck PROPERTIES EXCLUDE_FROM_ALL OFF)
set_target_properties(not PROPERTIES EXCLUDE_FROM_ALL OFF)
elseif(NOT IREE_HOST_BIN_DIR)
message(STATUS
"*Not* building or importing IREE's compiler tools.\n "
"Set IREE_BUILD_COMPILER to build them or IREE_HOST_BIN_DIR to "
"import them.")
endif()