blob: 77dfa1d4715f371041525c08df6411bea853a49b [file] [log] [blame] [view]
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -07001# CMake Options and Variables
2
3## Frequently-used CMake Variables
4
5#### `CMAKE_BUILD_TYPE`:STRING
6
7Sets the build type. Possible values are `Release`, `Debug`,
8`RelWithDebInfo`/`FastBuild` and `MinSizeRel`. If unset, build type is set to
9`Release`.
10
11#### `CMAKE_<LANG>_COMPILER`:STRING
12
13This is the command that will be used as the `<LANG>` compiler, which are `C`
14and `CXX` in IREE. These variables are set to compile IREE with `clang` or
15rather `clang++`. Once set, these variables can not be changed.
16
17## IREE-specific CMake Options and Variables
Marius Brehlerc3e93912020-06-18 16:06:24 -070018
19This gives a brief explanation of IREE specific CMake options and variables.
20
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070021#### `IREE_ENABLE_RUNTIME_TRACING`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070022
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070023Enables instrumented runtime tracing. Defaults to `OFF`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070024
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070025#### `IREE_ENABLE_MLIR`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070026
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070027Enables MLIR/LLVM dependencies. Defaults to `ON`. MLIR/LLVM dependencies are
28required when building the IREE compiler components. Therefore, the option is
29automatically set to `ON` if `IREE_BUILD_COMPILER` is set to `ON`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070030
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070031#### `IREE_ENABLE_EMITC`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070032
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070033Enables the build of the out-of-tree MLIR dialect EmitC. Defaults to `OFF`. To
34build the EmitC dialect, `IREE_ENABLE_MLIR` must be set to `ON`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070035
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070036#### `IREE_BUILD_COMPILER`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070037
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070038Builds the IREE compiler. Defaults to `ON`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070039
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070040#### `IREE_BUILD_TESTS`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070041
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070042Builds IREE unit tests. Defaults to `ON`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070043
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070044#### `IREE_BUILD_DOCS`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070045
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070046Builds IREE documentation. Defaults to `OFF`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070047
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070048#### `IREE_BUILD_SAMPLES`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070049
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070050Builds IREE sample projects. Defaults to `ON`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070051
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070052#### `IREE_BUILD_DEBUGGER`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070053
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070054Builds the IREE debugger app. Defaults to `OFF`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070055
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070056#### `IREE_BUILD_PYTHON_BINDINGS`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070057
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070058Builds the IREE python bindings. Defaults to `OFF`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070059
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070060#### `IREE_BUILD_EXPERIMENTAL`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070061
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070062Builds experimental projects. Defaults to `OFF`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070063
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070064#### `IREE_HAL_DRIVERS_TO_BUILD`:STRING
Marius Brehlerc3e93912020-06-18 16:06:24 -070065
Lei Zhang7d90e0e2020-07-23 16:01:13 -040066Semicolon-separated list of HAL drivers to build, or `all` for building all HAL
Scott Todd6132bb32020-08-11 12:04:40 -070067drivers. Case-insensitive. If an empty list is provided, will build no HAL
68drivers. Defaults to `all`. Example: `-DIREE_HAL_DRIVERS_TO_BUILD=Vulkan;VMLA`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070069
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070070#### `IREE_TARGET_BACKENDS_TO_BUILD`:STRING
Marius Brehlerc3e93912020-06-18 16:06:24 -070071
Scott Todd6132bb32020-08-11 12:04:40 -070072Semicolon-separated list of target backend to build, or `all` for building all
73compiler target backends. Case-insensitive. If an empty list is provided, will
74build no target backends. Defaults to `all`. Example:
75`-DIREE_TARGET_BACKENDS_TO_BUILD=Vulkan-SPIRV;VMLA`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070076
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070077#### `IREE_ENABLE_LLD`:BOOL
Marius Brehlerc3e93912020-06-18 16:06:24 -070078
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070079Use lld when linking. Defaults to `OFF`. This option is equivalent to
80`-DIREE_USE_LINKER=lld`. The option `IREE_ENABLE_LLD` and `IREE_USE_LINKER` can
81not be set at the same time.
Marius Brehlerc3e93912020-06-18 16:06:24 -070082
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070083#### `IREE_MLIR_DEP_MODE`:STRING
Marius Brehlerc3e93912020-06-18 16:06:24 -070084
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070085Defines the MLIR dependency mode. Case-sensitive. Can be `BUNDLED`, `DISABLED`
86or `INSTALLED`. Defaults to `BUNDLED`. If set to `INSTALLED`, the variable
87`MLIR_DIR` needs to be passed and that LLVM needs to be compiled with
88`LLVM_ENABLE_RTTI` set to `ON`.
Marius Brehlerc3e93912020-06-18 16:06:24 -070089
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070090## MLIR-specific CMake Options and Variables
Marius Brehlerc3e93912020-06-18 16:06:24 -070091
Marius Brehlerc5c8b7c2020-06-22 14:38:05 -070092#### `MLIR_DIR`:STRING
93
94Specifies the path where to look for the installed MLIR/LLVM packages. Required
95if `IREE_MLIR_DEP_MODE` is set to `INSTALLED`.
Lei Zhang515c9222020-06-24 21:10:02 -040096
97## Cross-compilation
98
Copybara-Servicec8dc96d2020-07-01 09:18:06 -070099[TODO(#2111): The following explanation is developer oriented. Move it to the
100developer build doc once we've created that.]
Lei Zhang0c417da2020-06-29 19:36:00 -0400101
Lei Zhang515c9222020-06-24 21:10:02 -0400102Cross-compilation involves both a *host* platform and a *target* platform. One
103invokes compiler toolchains on the host platform to generate libraries and
104executables that can be run on the target platform.
105
106IREE uses tools to programmatically generate C/C++ source code from some
107domain-specific descriptions. For example, `flatc` is used to generate C/C++
108code from FlatBuffer schemas. These tools should be compiled for the host
109platform so that we can invoke them during build process. This requires
110cross-compilation for IREE to (conceptually) happen in two stages: first compile
111build tools under host platform, and then use these host tools together with
112cross-compiling toolchains to generate artifacts for the target platform. (The
113build system dependency graph may not have such clear two-stage separation.)
114
Copybara-Service09f2c562020-06-26 09:07:30 -0700115CMake cannot handle multiple compiler toolchains in one CMake invocation. So the
116above conceptual two-stage compilation happens in two separate CMake
Lei Zhang515c9222020-06-24 21:10:02 -0400117invocations.
118
Lei Zhang0c417da2020-06-29 19:36:00 -0400119When CMake is invoked with a toolchain file, e.g.,
120[`android.toolchain.cmake`](https://android.googlesource.com/platform/ndk/+/master/build/cmake/android.toolchain.cmake),
121we get the compiler toolchain for the target platform from the toolchain file.
Copybara-Servicec8dc96d2020-07-01 09:18:06 -0700122IREE under the hood will
123[create another CMake invocation](https://github.com/google/iree/blob/main/build_tools/cmake/iree_cross_compile.cmake)
Lei Zhang0c417da2020-06-29 19:36:00 -0400124using host platform's compiler toolchain. The inner CMake invocation will be
125placed under `IREE_HOST_BINARY_ROOT`.
126
127The tricky part is to set up target artifacts' dependencies on host executables.
128Normally in CMake we define targets and `target_link_libraries` to express the
Copybara-Servicec8dc96d2020-07-01 09:18:06 -0700129dependency relationship between targets. The optimal way is to
130[`export`](https://cmake.org/cmake/help/latest/command/export.html) targets
131under host configuration and then
132[`import`](https://cmake.org/cmake/help/latest/command/add_executable.html?highlight=import#imported-executables)
Lei Zhang0c417da2020-06-29 19:36:00 -0400133into target configuration. But that is not playing well with LLVM's TableGen
Copybara-Servicec8dc96d2020-07-01 09:18:06 -0700134configurations. LLVM's cross-compilation uses on files for dependencies. So here
135we need to do the same. This results in reverting the relationship between IREE
136artifact output names (e.g., `iree-translate`) and IREE package-prefixed CMake
137target names (e.g., `iree_tools_iree-translate`).
Lei Zhang0c417da2020-06-29 19:36:00 -0400138
139When not cross-compiling, IREE uses the CMake target names as the real unique
140identification inside CMake for defining the object and expressing dependencies;
141the artifact output names are just used for naming the build artifacts. When
142cross-compiling, it's the artifact names being load-bearing. The artifact names
143are used to express dependencies across CMake invocation boundary (remember that
Copybara-Servicec8dc96d2020-07-01 09:18:06 -0700144we cannot access targets defined in another CMake invocation); the
Copybara-Service0c0e2ba2020-07-13 12:03:53 -0700145package-prefixed CMake target names are just custom targets depending on the
146host artifact.
Lei Zhang0c417da2020-06-29 19:36:00 -0400147
Lei Zhang515c9222020-06-24 21:10:02 -0400148#### `IREE_HOST_BINARY_ROOT`:FILEPATH
149
150Specifies the root directory for containing all host CMake invocation artifacts.
151This defaults to `CMAKE_BINARY_DIR/host` if missing.
152
153#### `IREE_HOST_C_COMPILER`:STRING
154
155Specifies the C compiler for host compilation.
156
157#### `IREE_HOST_CXX_COMPILER`:STRING
158
159Specifies the C++ compiler for host compilation.
160
161#### `IREE_HOST_<option>`:BOOL
162
163For each option described in "IREE-specific CMake Options and Variables", you
164can use the `IREE_HOST_<option>` counterpart to control the feature when
165compiling under host configuration. For example, `IREE_HOST_BUILD_TESTS` will
166enables all tests for the host configuration.