Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 1 | # CMake Options and Variables |
| 2 | |
| 3 | ## Frequently-used CMake Variables |
| 4 | |
| 5 | #### `CMAKE_BUILD_TYPE`:STRING |
| 6 | |
| 7 | Sets 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 | |
| 13 | This is the command that will be used as the `<LANG>` compiler, which are `C` |
| 14 | and `CXX` in IREE. These variables are set to compile IREE with `clang` or |
| 15 | rather `clang++`. Once set, these variables can not be changed. |
| 16 | |
| 17 | ## IREE-specific CMake Options and Variables |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 18 | |
| 19 | This gives a brief explanation of IREE specific CMake options and variables. |
| 20 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 21 | #### `IREE_ENABLE_RUNTIME_TRACING`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 22 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 23 | Enables instrumented runtime tracing. Defaults to `OFF`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 24 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 25 | #### `IREE_ENABLE_MLIR`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 26 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 27 | Enables MLIR/LLVM dependencies. Defaults to `ON`. MLIR/LLVM dependencies are |
| 28 | required when building the IREE compiler components. Therefore, the option is |
| 29 | automatically set to `ON` if `IREE_BUILD_COMPILER` is set to `ON`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 30 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 31 | #### `IREE_ENABLE_EMITC`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 32 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 33 | Enables the build of the out-of-tree MLIR dialect EmitC. Defaults to `OFF`. To |
| 34 | build the EmitC dialect, `IREE_ENABLE_MLIR` must be set to `ON`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 35 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 36 | #### `IREE_BUILD_COMPILER`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 37 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 38 | Builds the IREE compiler. Defaults to `ON`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 39 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 40 | #### `IREE_BUILD_TESTS`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 41 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 42 | Builds IREE unit tests. Defaults to `ON`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 43 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 44 | #### `IREE_BUILD_DOCS`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 45 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 46 | Builds IREE documentation. Defaults to `OFF`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 47 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 48 | #### `IREE_BUILD_SAMPLES`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 49 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 50 | Builds IREE sample projects. Defaults to `ON`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 51 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 52 | #### `IREE_BUILD_DEBUGGER`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 53 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 54 | Builds the IREE debugger app. Defaults to `OFF`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 55 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 56 | #### `IREE_BUILD_PYTHON_BINDINGS`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 57 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 58 | Builds the IREE python bindings. Defaults to `OFF`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 59 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 60 | #### `IREE_BUILD_EXPERIMENTAL`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 61 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 62 | Builds experimental projects. Defaults to `OFF`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 63 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 64 | #### `IREE_HAL_DRIVERS_TO_BUILD`:STRING |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 65 | |
Lei Zhang | 7d90e0e | 2020-07-23 16:01:13 -0400 | [diff] [blame] | 66 | Semicolon-separated list of HAL drivers to build, or `all` for building all HAL |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 67 | drivers. Case-insensitive. If an empty list is provided, will build no HAL |
| 68 | drivers. Defaults to `all`. Example: `-DIREE_HAL_DRIVERS_TO_BUILD=Vulkan;VMLA`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 69 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 70 | #### `IREE_TARGET_BACKENDS_TO_BUILD`:STRING |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 71 | |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 72 | Semicolon-separated list of target backend to build, or `all` for building all |
| 73 | compiler target backends. Case-insensitive. If an empty list is provided, will |
| 74 | build no target backends. Defaults to `all`. Example: |
| 75 | `-DIREE_TARGET_BACKENDS_TO_BUILD=Vulkan-SPIRV;VMLA`. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 76 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 77 | #### `IREE_ENABLE_LLD`:BOOL |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 78 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 79 | Use 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 |
| 81 | not be set at the same time. |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 82 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 83 | #### `IREE_MLIR_DEP_MODE`:STRING |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 84 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 85 | Defines the MLIR dependency mode. Case-sensitive. Can be `BUNDLED`, `DISABLED` |
| 86 | or `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 Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 89 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 90 | ## MLIR-specific CMake Options and Variables |
Marius Brehler | c3e9391 | 2020-06-18 16:06:24 -0700 | [diff] [blame] | 91 | |
Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 92 | #### `MLIR_DIR`:STRING |
| 93 | |
| 94 | Specifies the path where to look for the installed MLIR/LLVM packages. Required |
| 95 | if `IREE_MLIR_DEP_MODE` is set to `INSTALLED`. |
Lei Zhang | 515c922 | 2020-06-24 21:10:02 -0400 | [diff] [blame] | 96 | |
| 97 | ## Cross-compilation |
| 98 | |
Copybara-Service | c8dc96d | 2020-07-01 09:18:06 -0700 | [diff] [blame] | 99 | [TODO(#2111): The following explanation is developer oriented. Move it to the |
| 100 | developer build doc once we've created that.] |
Lei Zhang | 0c417da | 2020-06-29 19:36:00 -0400 | [diff] [blame] | 101 | |
Lei Zhang | 515c922 | 2020-06-24 21:10:02 -0400 | [diff] [blame] | 102 | Cross-compilation involves both a *host* platform and a *target* platform. One |
| 103 | invokes compiler toolchains on the host platform to generate libraries and |
| 104 | executables that can be run on the target platform. |
| 105 | |
| 106 | IREE uses tools to programmatically generate C/C++ source code from some |
| 107 | domain-specific descriptions. For example, `flatc` is used to generate C/C++ |
| 108 | code from FlatBuffer schemas. These tools should be compiled for the host |
| 109 | platform so that we can invoke them during build process. This requires |
| 110 | cross-compilation for IREE to (conceptually) happen in two stages: first compile |
| 111 | build tools under host platform, and then use these host tools together with |
| 112 | cross-compiling toolchains to generate artifacts for the target platform. (The |
| 113 | build system dependency graph may not have such clear two-stage separation.) |
| 114 | |
Copybara-Service | 09f2c56 | 2020-06-26 09:07:30 -0700 | [diff] [blame] | 115 | CMake cannot handle multiple compiler toolchains in one CMake invocation. So the |
| 116 | above conceptual two-stage compilation happens in two separate CMake |
Lei Zhang | 515c922 | 2020-06-24 21:10:02 -0400 | [diff] [blame] | 117 | invocations. |
| 118 | |
Lei Zhang | 0c417da | 2020-06-29 19:36:00 -0400 | [diff] [blame] | 119 | When 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), |
| 121 | we get the compiler toolchain for the target platform from the toolchain file. |
Copybara-Service | c8dc96d | 2020-07-01 09:18:06 -0700 | [diff] [blame] | 122 | IREE under the hood will |
| 123 | [create another CMake invocation](https://github.com/google/iree/blob/main/build_tools/cmake/iree_cross_compile.cmake) |
Lei Zhang | 0c417da | 2020-06-29 19:36:00 -0400 | [diff] [blame] | 124 | using host platform's compiler toolchain. The inner CMake invocation will be |
| 125 | placed under `IREE_HOST_BINARY_ROOT`. |
| 126 | |
| 127 | The tricky part is to set up target artifacts' dependencies on host executables. |
| 128 | Normally in CMake we define targets and `target_link_libraries` to express the |
Copybara-Service | c8dc96d | 2020-07-01 09:18:06 -0700 | [diff] [blame] | 129 | dependency relationship between targets. The optimal way is to |
| 130 | [`export`](https://cmake.org/cmake/help/latest/command/export.html) targets |
| 131 | under host configuration and then |
| 132 | [`import`](https://cmake.org/cmake/help/latest/command/add_executable.html?highlight=import#imported-executables) |
Lei Zhang | 0c417da | 2020-06-29 19:36:00 -0400 | [diff] [blame] | 133 | into target configuration. But that is not playing well with LLVM's TableGen |
Copybara-Service | c8dc96d | 2020-07-01 09:18:06 -0700 | [diff] [blame] | 134 | configurations. LLVM's cross-compilation uses on files for dependencies. So here |
| 135 | we need to do the same. This results in reverting the relationship between IREE |
| 136 | artifact output names (e.g., `iree-translate`) and IREE package-prefixed CMake |
| 137 | target names (e.g., `iree_tools_iree-translate`). |
Lei Zhang | 0c417da | 2020-06-29 19:36:00 -0400 | [diff] [blame] | 138 | |
| 139 | When not cross-compiling, IREE uses the CMake target names as the real unique |
| 140 | identification inside CMake for defining the object and expressing dependencies; |
| 141 | the artifact output names are just used for naming the build artifacts. When |
| 142 | cross-compiling, it's the artifact names being load-bearing. The artifact names |
| 143 | are used to express dependencies across CMake invocation boundary (remember that |
Copybara-Service | c8dc96d | 2020-07-01 09:18:06 -0700 | [diff] [blame] | 144 | we cannot access targets defined in another CMake invocation); the |
Copybara-Service | 0c0e2ba | 2020-07-13 12:03:53 -0700 | [diff] [blame] | 145 | package-prefixed CMake target names are just custom targets depending on the |
| 146 | host artifact. |
Lei Zhang | 0c417da | 2020-06-29 19:36:00 -0400 | [diff] [blame] | 147 | |
Lei Zhang | 515c922 | 2020-06-24 21:10:02 -0400 | [diff] [blame] | 148 | #### `IREE_HOST_BINARY_ROOT`:FILEPATH |
| 149 | |
| 150 | Specifies the root directory for containing all host CMake invocation artifacts. |
| 151 | This defaults to `CMAKE_BINARY_DIR/host` if missing. |
| 152 | |
| 153 | #### `IREE_HOST_C_COMPILER`:STRING |
| 154 | |
| 155 | Specifies the C compiler for host compilation. |
| 156 | |
| 157 | #### `IREE_HOST_CXX_COMPILER`:STRING |
| 158 | |
| 159 | Specifies the C++ compiler for host compilation. |
| 160 | |
| 161 | #### `IREE_HOST_<option>`:BOOL |
| 162 | |
| 163 | For each option described in "IREE-specific CMake Options and Variables", you |
| 164 | can use the `IREE_HOST_<option>` counterpart to control the feature when |
| 165 | compiling under host configuration. For example, `IREE_HOST_BUILD_TESTS` will |
| 166 | enables all tests for the host configuration. |