Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2019 The IREE Authors |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 2 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 6 | |
Geoffrey Martin-Noble | d89a5af | 2021-10-26 19:38:21 -0700 | [diff] [blame] | 7 | cmake_minimum_required(VERSION 3.16.3...3.21) |
Ben Vanik | 552c5f4 | 2021-06-21 17:39:14 -0700 | [diff] [blame] | 8 | |
| 9 | # LLVM requires CMP0116 for tblgen: https://reviews.llvm.org/D101083 |
| 10 | # CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` |
| 11 | # New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html |
| 12 | set(CMAKE_POLICY_DEFAULT_CMP0116 OLD) |
| 13 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 14 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 15 | |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 16 | project(IREE ASM C CXX) |
Lei Zhang | 6c5907b | 2020-06-02 09:06:08 -0700 | [diff] [blame] | 17 | set(CMAKE_C_STANDARD 11) |
| 18 | set(CMAKE_CXX_STANDARD 14) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 19 | set(IREE_IDE_FOLDER IREE) |
| 20 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 21 | |
Ben Vanik | 96fd277 | 2021-04-19 20:30:56 -0700 | [diff] [blame] | 22 | if(${MSVC}) |
| 23 | enable_language(ASM_MASM) |
| 24 | else() |
| 25 | enable_language(ASM) |
| 26 | endif() |
| 27 | |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 28 | #------------------------------------------------------------------------------- |
| 29 | # Project component configuration |
| 30 | #------------------------------------------------------------------------------- |
| 31 | |
Ben Vanik | 56d44bf | 2020-05-15 13:20:50 -0700 | [diff] [blame] | 32 | option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF) |
Scott Todd | 1cd9f0a | 2021-07-29 10:05:44 -0700 | [diff] [blame] | 33 | option(IREE_ENABLE_COMPILER_TRACING "Enables instrumented compiler tracing." OFF) |
Geoffrey Martin-Noble | fe74bd4 | 2021-10-27 22:17:13 -0700 | [diff] [blame] | 34 | option(IREE_ENABLE_THREADING "Builds IREE in with thread library support." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 35 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 36 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 37 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Lei Zhang | fe4403e | 2021-06-01 15:09:43 -0400 | [diff] [blame] | 38 | option(IREE_BUILD_BENCHMARKS "Builds IREE benchmark suites." OFF) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 39 | option(IREE_BUILD_DOCS "Builds IREE docs." OFF) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 40 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 41 | option(IREE_BUILD_TRACY "Builds tracy server tools." OFF) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 42 | |
Stella Laurenzo | 6a0313b | 2021-05-04 22:45:59 +0000 | [diff] [blame] | 43 | option(IREE_BUILD_TENSORFLOW_ALL "Builds all TensorFlow compiler frontends." OFF) |
Geoffrey Martin-Noble | fe74bd4 | 2021-10-27 22:17:13 -0700 | [diff] [blame] | 44 | option(IREE_BUILD_TENSORFLOW_COMPILER "Builds TensorFlow compiler frontend." "${IREE_BUILD_TENSORFLOW_ALL}") |
| 45 | option(IREE_BUILD_TFLITE_COMPILER "Builds the TFLite compiler frontend." "${IREE_BUILD_TENSORFLOW_ALL}") |
| 46 | option(IREE_BUILD_XLA_COMPILER "Builds TensorFlow XLA compiler frontend." "${IREE_BUILD_TENSORFLOW_ALL}") |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 47 | |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 48 | set(IREE_HAL_DRIVERS_TO_BUILD "default" |
| 49 | CACHE STRING "Semicolon-separated list of HAL drivers to build, or \"default\"") |
| 50 | set(IREE_TARGET_BACKENDS_TO_BUILD "default" |
| 51 | CACHE STRING "Semicolon-separated list of target backends to build, or \"default\"") |
Stella Laurenzo | 04b7c37 | 2020-12-10 00:05:31 +0000 | [diff] [blame] | 52 | |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 53 | # Properties controlling version and naming of release artifacts. |
| 54 | set(IREE_RELEASE_PACKAGE_SUFFIX "-dev" CACHE STRING "Suffix to append to distributed package names") |
| 55 | set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages") |
| 56 | set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages") |
| 57 | |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame] | 58 | # Master enable for tensorflow build support. |
| 59 | # Note that this is a normal CMake variable used to gate build features (not |
| 60 | # a cache variable that is user-settable). |
| 61 | set(IREE_ENABLE_TENSORFLOW OFF) |
Stella Laurenzo | 6a0313b | 2021-05-04 22:45:59 +0000 | [diff] [blame] | 62 | if(${IREE_BUILD_TENSORFLOW_ALL} OR |
| 63 | ${IREE_BUILD_TENSORFLOW_COMPILER} OR |
Stella Laurenzo | 55fcfab | 2020-12-10 13:17:25 -0800 | [diff] [blame] | 64 | ${IREE_BUILD_TFLITE_COMPILER} OR |
| 65 | ${IREE_BUILD_XLA_COMPILER}) |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame] | 66 | set(IREE_ENABLE_TENSORFLOW ON) |
| 67 | endif() |
| 68 | |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 69 | option(IREE_BUILD_BINDINGS_TFLITE "Builds the IREE TFLite C API compatibility shim" ON) |
Kojo Acquah | 5bf3994 | 2021-04-22 16:01:28 -0700 | [diff] [blame] | 70 | option(IREE_BUILD_BINDINGS_TFLITE_JAVA "Builds the IREE TFLite Java bindings with the C API compatibility shim" ON) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 71 | |
Stella Laurenzo | 04b7c37 | 2020-12-10 00:05:31 +0000 | [diff] [blame] | 72 | # Default python bindings to enabled for some features. |
Geoffrey Martin-Noble | fe74bd4 | 2021-10-27 22:17:13 -0700 | [diff] [blame] | 73 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" "${IREE_ENABLE_TENSORFLOW}") |
Stella Laurenzo | 04b7c37 | 2020-12-10 00:05:31 +0000 | [diff] [blame] | 74 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 75 | #------------------------------------------------------------------------------- |
| 76 | # Experimental project flags |
| 77 | #------------------------------------------------------------------------------- |
| 78 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 79 | option(IREE_BUILD_EXPERIMENTAL_REMOTING "Builds experimental remoting support." OFF) |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 80 | option(IREE_BUILD_EXPERIMENTAL_ROCM "Builds the experimental ROCm Backend." OFF) |
Stella Laurenzo | 0a8a944 | 2021-06-14 22:42:37 -0700 | [diff] [blame] | 81 | option(IREE_ENABLE_NEW_INTEGRATION_TESTS "Enables new integration tests and disables old." OFF) |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 82 | |
| 83 | #------------------------------------------------------------------------------- |
| 84 | # Derived flags based on primary options |
| 85 | #------------------------------------------------------------------------------- |
| 86 | |
Marius Brehler | 5400f0f | 2021-08-11 01:41:34 +0200 | [diff] [blame] | 87 | option(IREE_ENABLE_EMITC "Enables MLIR EmitC dependencies." ${IREE_BUILD_COMPILER}) |
Marius Brehler | fd8be7f | 2020-06-18 15:59:28 -0700 | [diff] [blame] | 88 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 89 | #------------------------------------------------------------------------------- |
Lei Zhang | 8bea2e8 | 2020-06-04 10:17:56 -0400 | [diff] [blame] | 90 | # Target and backend configuration |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 91 | #------------------------------------------------------------------------------- |
| 92 | |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 93 | # List of all runtime HAL drivers included in the project: |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 94 | set(IREE_ALL_HAL_DRIVERS |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 95 | CUDA |
| 96 | Dylib |
CindyLiu | a547965 | 2021-09-29 16:32:18 +0000 | [diff] [blame] | 97 | Dylib_Sync |
Ben Vanik | 0f14db0 | 2021-04-19 23:29:29 -0700 | [diff] [blame] | 98 | VMVX |
CindyLiu | a547965 | 2021-09-29 16:32:18 +0000 | [diff] [blame] | 99 | VMVX_Sync |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 100 | Vulkan |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 101 | ) |
| 102 | |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 103 | if(IREE_HAL_DRIVERS_TO_BUILD STREQUAL "default") |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 104 | set(IREE_HAL_DRIVERS_TO_BUILD ${IREE_ALL_HAL_DRIVERS}) |
Lei Zhang | 6171a98 | 2020-09-08 12:48:25 -0400 | [diff] [blame] | 105 | |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 106 | # Vulkan is not natively supported on Apple platforms. |
| 107 | # Metal should generally be used instead, though MoltenVK may also work. |
Lei Zhang | 6171a98 | 2020-09-08 12:48:25 -0400 | [diff] [blame] | 108 | if(APPLE) |
| 109 | list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD Vulkan) |
Lei Zhang | 6171a98 | 2020-09-08 12:48:25 -0400 | [diff] [blame] | 110 | endif() |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 111 | |
| 112 | # CUDA is not natively supported on Android or Apple platforms. |
Thomas | a98c3c0 | 2021-02-16 09:56:03 -0800 | [diff] [blame] | 113 | if(ANDROID OR APPLE) |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 114 | list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD CUDA) |
Thomas | a98c3c0 | 2021-02-16 09:56:03 -0800 | [diff] [blame] | 115 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 116 | endif() |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 117 | message(STATUS "Building runtime HAL drivers: ${IREE_HAL_DRIVERS_TO_BUILD}") |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 118 | |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 119 | # Start each IREE_HAL_DRIVER_* OFF, then enable from IREE_HAL_DRIVERS_TO_BUILD. |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 120 | foreach(_backend ${IREE_ALL_HAL_DRIVERS}) |
| 121 | string(TOUPPER "${_backend}" uppercase_backend) |
| 122 | set(IREE_HAL_DRIVER_${uppercase_backend} OFF CACHE BOOL "" FORCE) |
| 123 | endforeach() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 124 | foreach(_backend ${IREE_HAL_DRIVERS_TO_BUILD}) |
| 125 | string(TOUPPER "${_backend}" uppercase_backend) |
Marius Brehler | 30f06a0 | 2020-12-18 13:39:26 +0000 | [diff] [blame] | 126 | string(REPLACE "\"" "" uppercase_backend ${uppercase_backend}) |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 127 | set(IREE_HAL_DRIVER_${uppercase_backend} ON CACHE BOOL "" FORCE) |
| 128 | endforeach() |
| 129 | |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 130 | # List of all compiler target backends included in the project: |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 131 | set(IREE_ALL_TARGET_BACKENDS |
Thomas | d85738e | 2021-02-23 11:02:55 -0800 | [diff] [blame] | 132 | CUDA |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 133 | Dylib-LLVM-AOT |
Scott Todd | 9f0148f | 2021-03-17 15:14:07 -0700 | [diff] [blame] | 134 | WASM-LLVM-AOT |
Lei Zhang | 3cbb28e | 2020-09-22 15:30:27 -0400 | [diff] [blame] | 135 | Metal-SPIRV |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 136 | ROCm |
Lei Zhang | 7d90e0e | 2020-07-23 16:01:13 -0400 | [diff] [blame] | 137 | Vulkan-SPIRV |
Ben Vanik | 907f353 | 2021-04-20 13:27:00 -0700 | [diff] [blame] | 138 | VMVX |
Scott Todd | f8519ca | 2021-12-16 16:01:49 -0800 | [diff] [blame] | 139 | WebGPU |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 140 | ) |
| 141 | |
Scott Todd | 28cacaa | 2021-06-29 09:31:46 -0700 | [diff] [blame] | 142 | if(${IREE_BUILD_COMPILER}) |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 143 | if(IREE_TARGET_BACKENDS_TO_BUILD STREQUAL "default") |
Scott Todd | 28cacaa | 2021-06-29 09:31:46 -0700 | [diff] [blame] | 144 | set(IREE_TARGET_BACKENDS_TO_BUILD ${IREE_ALL_TARGET_BACKENDS}) |
Scott Todd | f8519ca | 2021-12-16 16:01:49 -0800 | [diff] [blame] | 145 | |
| 146 | # Disable the WebGPU backend by default, as it has complex dependencies and |
| 147 | # is still early in its development. |
| 148 | list(REMOVE_ITEM IREE_TARGET_BACKENDS_TO_BUILD WebGPU) |
Scott Todd | 28cacaa | 2021-06-29 09:31:46 -0700 | [diff] [blame] | 149 | endif() |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 150 | message(STATUS "Building compiler target backends: ${IREE_TARGET_BACKENDS_TO_BUILD}") |
Scott Todd | 28cacaa | 2021-06-29 09:31:46 -0700 | [diff] [blame] | 151 | else() |
| 152 | set(IREE_TARGET_BACKENDS_TO_BUILD "" CACHE STRING "" FORCE) |
| 153 | message(STATUS "Compiler is disabled, building no target backends") |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 154 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 155 | |
| 156 | # Default every IREE_TARGET_BACKEND_* to OFF |
| 157 | foreach(_backend ${IREE_ALL_TARGET_BACKENDS}) |
| 158 | string(TOUPPER "${_backend}" uppercase_backend) |
| 159 | set(IREE_TARGET_BACKEND_${uppercase_backend} OFF CACHE BOOL "" FORCE) |
| 160 | endforeach() |
| 161 | |
| 162 | # Set IREE_TARGET_BACKEND_* based on configuration |
| 163 | foreach(_backend ${IREE_TARGET_BACKENDS_TO_BUILD}) |
| 164 | string(TOUPPER "${_backend}" uppercase_backend) |
Marius Brehler | 30f06a0 | 2020-12-18 13:39:26 +0000 | [diff] [blame] | 165 | string(REPLACE "\"" "" uppercase_backend ${uppercase_backend}) |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 166 | set(IREE_TARGET_BACKEND_${uppercase_backend} ON CACHE BOOL "" FORCE) |
| 167 | endforeach() |
| 168 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 169 | list(APPEND CMAKE_MODULE_PATH |
| 170 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 171 | ${CMAKE_CURRENT_LIST_DIR}/bindings/python/build_tools/cmake/ |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 172 | ) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 173 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 174 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 175 | # IREE compilation toolchain configuration |
| 176 | #------------------------------------------------------------------------------- |
| 177 | |
| 178 | # Enable using lld as the linker for C/C++ targets. This affects IREE and all |
| 179 | # dependency projects. |
| 180 | option(IREE_ENABLE_LLD "Use lld when linking" OFF) |
| 181 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 182 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 183 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 184 | option(IREE_ENABLE_CCACHE "Use ccache if installed to speed up rebuilds." OFF) |
| 185 | |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 186 | if(${IREE_ENABLE_CCACHE}) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 187 | find_program(CCACHE_PROGRAM ccache) |
| 188 | if(CCACHE_PROGRAM) |
| 189 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
| 190 | endif() |
| 191 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 192 | |
Geoffrey Martin-Noble | 3fa4f8d | 2021-09-10 09:25:27 -0700 | [diff] [blame] | 193 | option(IREE_DEV_MODE "Configure settings to optimize for IREE development (as opposed to CI or release)" OFF) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 194 | |
| 195 | #------------------------------------------------------------------------------- |
| 196 | # IREE assertions |
| 197 | # We don't love the way this is done, but we have to line it up with how LLVM |
| 198 | # does it and not diverge, since all implementations and all header users must |
| 199 | # have the same definition of NDEBUG. |
| 200 | # |
| 201 | # LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then |
| 202 | # conditions itself to only update flags if not building Debug. We just let |
| 203 | # IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the |
| 204 | # flags in appropriate build types. |
| 205 | # |
| 206 | # If IREE_ENABLE_ASSERTIONS is set ON manually, then |
| 207 | # - NDEBUG must be undefined |
| 208 | # - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties |
| 209 | # from mucking with globals. |
| 210 | # |
| 211 | # Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done |
| 212 | # at the top level to avoid divergence. |
| 213 | #------------------------------------------------------------------------------- |
| 214 | |
| 215 | option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF) |
| 216 | |
| 217 | # Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if |
| 218 | # CMAKE_BUILD_TYPE is not Debug). |
| 219 | function(iree_fix_ndebug) |
| 220 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 221 | if(IREE_ENABLE_ASSERTIONS AND NOT "${uppercase_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") |
| 222 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
| 223 | foreach (flags_var_to_scrub |
| 224 | CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} |
| 225 | CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}) |
| 226 | set(original_flags "${${flags_var_to_scrub}}") |
| 227 | string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " |
| 228 | altered_flags "${original_flags}") |
| 229 | if(NOT "${original_flags}" STREQUAL "${altered_flags}") |
| 230 | message(STATUS |
| 231 | "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${flags_var_to_scrub}: '${original_flags}' -> '${altered_flags}'") |
| 232 | set(${flags_var_to_scrub} "${altered_flags}" PARENT_SCOPE) |
| 233 | endif() |
| 234 | endforeach() |
| 235 | |
| 236 | # Make sure that LLVM doesn't add its own logic for assertion disabling. |
| 237 | # We'd like to make sure that we are not dueling over globals. |
| 238 | set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE) |
| 239 | endif() |
| 240 | endfunction() |
| 241 | iree_fix_ndebug() |
| 242 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 243 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 244 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 245 | #------------------------------------------------------------------------------- |
| 246 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 247 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 248 | include(iree_copts) |
bjacob | c12ba3b | 2020-11-03 10:32:00 -0500 | [diff] [blame] | 249 | include(sanitizers) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 250 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 251 | include(iree_cc_library) |
| 252 | include(iree_cc_test) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 253 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 254 | include(iree_tablegen_doc) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 255 | include(iree_third_party_cmake_options) |
CindyLiu | 40ed02d | 2021-04-22 16:16:28 +0000 | [diff] [blame] | 256 | include(iree_c_embed_data) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 257 | include(iree_bytecode_module) |
Marius Brehler | 46e8331 | 2021-03-25 00:11:39 +0100 | [diff] [blame] | 258 | include(iree_c_module) |
Stella Laurenzo | 94363e2 | 2020-12-15 13:46:14 -0800 | [diff] [blame] | 259 | include(iree_python) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 260 | include(iree_lit_test) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 261 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 262 | include(iree_check_test) |
bjacob | 5feef48 | 2021-10-21 16:53:58 -0400 | [diff] [blame] | 263 | include(iree_trace_runner_test) |
Geoffrey Martin-Noble | 4889612 | 2021-01-05 21:04:18 -0800 | [diff] [blame] | 264 | include(iree_run_binary_test) |
Geoffrey Martin-Noble | 66d4889 | 2021-10-29 12:24:58 -0700 | [diff] [blame] | 265 | include(iree_benchmark_suite) |
Scott Todd | 434ff0e | 2021-12-21 10:38:36 -0800 | [diff] [blame] | 266 | include(iree_hal_cts_test_suite) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 267 | |
Marius Brehler | c4b6b91 | 2020-01-15 08:44:23 -0800 | [diff] [blame] | 268 | set(DEFAULT_CMAKE_BUILD_TYPE "Release") |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 269 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
Marius Brehler | c4b6b91 | 2020-01-15 08:44:23 -0800 | [diff] [blame] | 270 | message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}") |
| 271 | set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
| 272 | endif() |
| 273 | |
Marius Brehler | 06ac36e | 2020-01-10 14:44:11 -0800 | [diff] [blame] | 274 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 275 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 276 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 277 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 278 | #------------------------------------------------------------------------------- |
| 279 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 280 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 281 | iree_append_list_to_string(CMAKE_CXX_FLAGS_DEBUG ${IREE_CXX_FLAGS_DEBUG_LIST}) |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 282 | |
| 283 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 284 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 285 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 286 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 287 | mark_as_advanced( |
| 288 | CMAKE_CXX_FLAGS_FASTBUILD |
| 289 | CMAKE_C_FLAGS_FASTBUILD |
| 290 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 291 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 292 | ) |
| 293 | |
| 294 | include(iree_setup_toolchain) |
| 295 | |
| 296 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 297 | # Python |
| 298 | # If building features that require Python development, find them early in |
| 299 | # one invocation (some CMake versions are sensitive to resolving out of order). |
| 300 | # Otherwise, for features that just require the interpreter, find that alone. |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 301 | #------------------------------------------------------------------------------- |
| 302 | |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 303 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 304 | # After CMake 3.18, we are able to limit the scope of the search to just |
| 305 | # Development.Module. Searching for Development will fail in situations where |
| 306 | # the Python libraries are not available. When possible, limit to just |
| 307 | # Development.Module. |
| 308 | # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode |
| 309 | if(CMAKE_VERSION VERSION_LESS "3.18.0") |
| 310 | message(WARNING |
| 311 | "This version of CMake is not compatible with statically built Python " |
| 312 | "installations. If Python fails to detect below this may apply to you. " |
| 313 | "Recommend upgrading to at least CMake 3.18. " |
| 314 | "Detected current version: ${CMAKE_VERSION}" |
| 315 | ) |
| 316 | find_package(Python3 COMPONENTS Interpreter Development REQUIRED) |
| 317 | else() |
| 318 | find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) |
| 319 | endif() |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 320 | elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 321 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
| 322 | endif() |
| 323 | |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 324 | # Extended Python environment checks. |
| 325 | if(Python3_FOUND) |
| 326 | iree_detect_pyyaml() |
| 327 | endif() |
| 328 | |
| 329 | if(IREE_BUILD_TESTS AND NOT IREE_PYYAML_FOUND) |
| 330 | message(WARNING "IREE's regression test suite requires PyYAML to run all tests. It is not installed, so some tests will be disabled.") |
| 331 | endif() |
| 332 | |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 333 | #------------------------------------------------------------------------------- |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 334 | # Check if git submodules have been initialized. |
| 335 | # This will only run if python3 is available. |
| 336 | #------------------------------------------------------------------------------- |
| 337 | |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame^] | 338 | option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON) |
| 339 | |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 340 | find_package(Python3 COMPONENTS Interpreter QUIET) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 341 | find_package(Git) |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame^] | 342 | if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 343 | # Only check submodule status when the git commit changes. |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 344 | execute_process( |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 345 | COMMAND git rev-parse --short HEAD |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 346 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 347 | RESULT_VARIABLE SHORT_HASH_RESULT |
| 348 | OUTPUT_VARIABLE SHORT_HASH) |
| 349 | string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}") |
Scott Todd | 2a8cd3b | 2021-12-13 11:58:44 -0800 | [diff] [blame] | 350 | if(SHORT_HASH_RESULT EQUAL "0" AND NOT "${IREE_GIT_SHORT_HASH}" STREQUAL "${SHORT_HASH}") |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 351 | execute_process( |
| 352 | COMMAND ${Python3_EXECUTABLE} scripts/git/check_submodule_init.py |
| 353 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 354 | RESULT_VARIABLE SUBMODULE_INIT_RESULT |
| 355 | ) |
| 356 | if(NOT SUBMODULE_INIT_RESULT EQUAL "0") |
| 357 | message(FATAL_ERROR "check_submodule_init.py failed, see the logs above") |
| 358 | else() |
| 359 | set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE) |
| 360 | endif() |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 361 | endif() |
| 362 | endif() |
| 363 | |
| 364 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 365 | # MLIR/LLVM Dependency |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 366 | #------------------------------------------------------------------------------- |
| 367 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 368 | if(NOT IREE_BUILD_COMPILER) |
| 369 | message(STATUS "Not adding LLVM/MLIR because the configuration does not require it") |
| 370 | elseif(TARGET LLVMSupport) |
| 371 | message(STATUS "Not adding IREE bundled LLVM because it has already been included") |
| 372 | if(NOT TARGET MLIRIR) |
| 373 | message(FATAL_ERROR "Detected externally provided LLVM project but could not find MLIR projects (is it enabled/installed?)") |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 374 | endif() |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 375 | else() |
| 376 | message(STATUS "Adding bundled LLVM source dependency") |
| 377 | iree_set_llvm_cmake_options() |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 378 | |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 379 | # Enable MLIR Python bindings if IREE Python bindings enabled. |
| 380 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 381 | set(MLIR_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "" FORCE) |
| 382 | set(MHLO_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "" FORCE) |
| 383 | endif() |
| 384 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 385 | # Disable LLVM's warnings. |
| 386 | set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "don't use global flags /facepalm") |
| 387 | |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 388 | # Stash cmake build type in case LLVM messes with it. |
| 389 | set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}") |
| 390 | |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 391 | # Add default external projects. |
Stella Laurenzo | 02230c1 | 2021-08-10 03:58:42 +0000 | [diff] [blame] | 392 | iree_add_llvm_external_project(mlir-iree-dialects MLIR_IREE_DIALECTS ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects) |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 393 | iree_add_llvm_external_project(mlir-hlo MLIR_HLO ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mlir-hlo) |
| 394 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 395 | add_subdirectory("third_party/llvm-project/llvm" EXCLUDE_FROM_ALL) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 396 | |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 397 | # Reset CMAKE_BUILD_TYPE to its previous setting. |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 398 | set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 399 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 400 | # Extend module path to allow submodules to use LLVM and MLIR CMake modules. |
| 401 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/mlir") |
| 402 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/lib/cmake/llvm/") |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 403 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 404 | # Add the bundled include directories for cmake files looking for them. |
| 405 | list(APPEND LLVM_INCLUDE_DIRS |
| 406 | ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/llvm/include |
| 407 | ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/include |
| 408 | ) |
| 409 | list(APPEND MLIR_INCLUDE_DIRS |
| 410 | ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/mlir/include |
| 411 | ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include |
| 412 | ) |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 413 | |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 414 | function(_hack_llvm_include_paths) |
| 415 | set(_common_include_dirs |
| 416 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/llvm/include> |
| 417 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/include> |
| 418 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/mlir/include> |
| 419 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include> |
| 420 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir-hlo/include> |
| 421 | ) |
| 422 | # Avoid globally modifying paths by instead adding the include paths to the |
| 423 | # rules that really should have them in the first place. |
| 424 | target_include_directories(LLVMSupport PUBLIC ${_common_include_dirs}) |
| 425 | target_include_directories(MLIRSupport PUBLIC ${_common_include_dirs}) |
| 426 | endfunction() |
| 427 | _hack_llvm_include_paths() |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 428 | endif() |
| 429 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 430 | #------------------------------------------------------------------------------- |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 431 | # Other dependencies |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 432 | #------------------------------------------------------------------------------- |
| 433 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 434 | include(external_cc_library) |
Ben Vanik | 2d1808b | 2020-07-17 19:02:16 -0700 | [diff] [blame] | 435 | include(flatbuffer_c_library) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 436 | |
Thomas | 3079fb1 | 2021-05-12 20:31:20 -0700 | [diff] [blame] | 437 | add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL) |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 438 | add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL) |
CindyLiu | 807f457 | 2021-05-12 23:41:41 +0000 | [diff] [blame] | 439 | add_subdirectory(build_tools/third_party/stblib EXCLUDE_FROM_ALL) |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 440 | add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 441 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 442 | iree_set_googletest_cmake_options() |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 443 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 444 | |
| 445 | if(IREE_ENABLE_THREADING) |
| 446 | iree_set_benchmark_cmake_options() |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 447 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 448 | iree_set_cpuinfo_cmake_options() |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 449 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 450 | endif() |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 451 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 452 | add_subdirectory(build_tools/third_party/flatcc EXCLUDE_FROM_ALL) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 453 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 454 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 455 | |
Scott Todd | 4e1a69b | 2021-01-25 15:29:49 -0800 | [diff] [blame] | 456 | # TODO(scotttodd): Iterate some more and find a better place for this. |
| 457 | if (NOT CMAKE_CROSSCOMPILING) |
Ben Vanik | 6874719 | 2021-10-26 20:38:45 -0700 | [diff] [blame] | 458 | install( |
| 459 | TARGETS iree-flatcc-cli |
| 460 | COMPONENT iree-flatcc-cli |
| 461 | RUNTIME DESTINATION bin |
| 462 | ) |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 463 | endif() |
| 464 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 465 | if(IREE_BUILD_COMPILER) |
Marius Brehler | 3eaf444 | 2021-01-13 18:22:08 +0100 | [diff] [blame] | 466 | add_subdirectory(build_tools/third_party/mlir-hlo EXCLUDE_FROM_ALL) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 467 | endif() |
| 468 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 469 | if(IREE_BUILD_TESTS) |
Marius Brehler | 575b63a | 2020-01-07 09:39:24 -0800 | [diff] [blame] | 470 | enable_testing(iree) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 471 | endif() |
| 472 | |
MaheshRavishankar | 1547ac2 | 2021-09-23 15:22:46 -0700 | [diff] [blame] | 473 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 95ad84c | 2021-09-24 14:56:01 -0700 | [diff] [blame] | 474 | if(NOT TARGET pybind11::module) |
| 475 | message(STATUS "Using bundled pybind11") |
| 476 | add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL) |
| 477 | else() |
| 478 | message(STATUS "Not including bundled pybind11 (already configured)") |
| 479 | endif() |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 480 | endif() |
| 481 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 482 | if(IREE_TARGET_BACKEND_METAL-SPIRV) |
| 483 | iree_set_spirv_cross_cmake_options() |
Lei Zhang | 3cbb28e | 2020-09-22 15:30:27 -0400 | [diff] [blame] | 484 | # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code. |
| 485 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 486 | endif() |
| 487 | |
Scott Todd | f8519ca | 2021-12-16 16:01:49 -0800 | [diff] [blame] | 488 | if(IREE_TARGET_BACKEND_WEBGPU) |
| 489 | # Tint is needed to compile SPIR-V into WGSL source code. |
| 490 | # Tint also requires SPIRV-Tools, which requires SPIRV-Headers. |
| 491 | iree_set_spirv_headers_cmake_options() |
| 492 | add_subdirectory(third_party/spirv_headers EXCLUDE_FROM_ALL) |
| 493 | add_subdirectory(build_tools/third_party/spirv-tools EXCLUDE_FROM_ALL) |
| 494 | add_subdirectory(build_tools/third_party/tint EXCLUDE_FROM_ALL) |
| 495 | endif() |
| 496 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 497 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 498 | # IREE top-level targets |
| 499 | #------------------------------------------------------------------------------- |
| 500 | |
Lei Zhang | fe4403e | 2021-06-01 15:09:43 -0400 | [diff] [blame] | 501 | if(${IREE_BUILD_BENCHMARKS}) |
| 502 | # Add a top-level custom target to drive generating benchmark suites. |
| 503 | add_custom_target(iree-benchmark-suites) |
| 504 | endif() |
| 505 | |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 506 | if(${IREE_BUILD_DOCS}) |
| 507 | # Add a top-level custom target to drive generating all documentation. |
| 508 | # Register it to the default target given that IREE_BUILD_DOCS is explicitly |
| 509 | # requested. |
| 510 | add_custom_target(iree-doc ALL) |
| 511 | endif() |
| 512 | |
| 513 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 514 | # IREE top-level libraries |
| 515 | #------------------------------------------------------------------------------- |
| 516 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 517 | add_subdirectory(build_tools/embed_data/) |
| 518 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 519 | add_subdirectory(iree/base) |
Ben Vanik | 658cf6c | 2021-11-22 10:35:41 -0800 | [diff] [blame] | 520 | add_subdirectory(iree/builtins) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 521 | add_subdirectory(iree/hal) |
Marius Brehler | 9317d1f | 2020-01-08 10:34:11 -0800 | [diff] [blame] | 522 | add_subdirectory(iree/modules) |
Ben Vanik | b69d0cc | 2021-05-05 18:16:22 -0700 | [diff] [blame] | 523 | add_subdirectory(iree/runtime) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 524 | add_subdirectory(iree/schemas) |
Ben Vanik | 01600a5 | 2020-12-15 17:18:04 -0800 | [diff] [blame] | 525 | add_subdirectory(iree/task) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 526 | add_subdirectory(iree/testing) |
Marius Brehler | 476031a | 2020-03-24 16:14:30 -0700 | [diff] [blame] | 527 | add_subdirectory(iree/test) |
not-jenni | bd3610e | 2020-12-23 17:00:22 -0800 | [diff] [blame] | 528 | add_subdirectory(iree/vm) |
Lei Zhang | ff38a68 | 2021-06-08 21:12:24 -0400 | [diff] [blame] | 529 | |
| 530 | if(${IREE_BUILD_BENCHMARKS}) |
Lei Zhang | 08cea04 | 2021-07-20 12:44:01 -0400 | [diff] [blame] | 531 | add_subdirectory(benchmarks) |
Lei Zhang | ff38a68 | 2021-06-08 21:12:24 -0400 | [diff] [blame] | 532 | endif() |
| 533 | |
raikonenfnu | 4b31bd9 | 2021-05-18 18:20:25 -0700 | [diff] [blame] | 534 | if(${IREE_BUILD_EXPERIMENTAL_ROCM}) |
| 535 | add_subdirectory(build_tools/third_party/rocm EXCLUDE_FROM_ALL) |
| 536 | add_subdirectory(experimental/rocm) |
raikonenfnu | 4b31bd9 | 2021-05-18 18:20:25 -0700 | [diff] [blame] | 537 | endif() |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 538 | |
| 539 | if(${IREE_BUILD_COMPILER}) |
| 540 | add_subdirectory(iree/compiler) |
| 541 | endif() |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 542 | |
| 543 | add_subdirectory(iree/tools) |
| 544 | |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 545 | if(IREE_BUILD_TRACY) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 546 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux") |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 547 | message(WARNING "Building Tracy (IREE_BUILD_TRACY) on non-Linux is unsupported and may fail below.") |
| 548 | endif() |
| 549 | add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy) |
| 550 | if(NOT TARGET IREETracyCaptureServer) |
| 551 | message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.") |
| 552 | endif() |
| 553 | endif() |
| 554 | |
Stella Laurenzo | 77a63cd | 2021-01-04 17:29:54 -0800 | [diff] [blame] | 555 | # Order constraint: The python bindings install tools targets from iree/tools |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 556 | # and tracy, and must come after it. |
Stella Laurenzo | 77a63cd | 2021-01-04 17:29:54 -0800 | [diff] [blame] | 557 | if(${IREE_BUILD_PYTHON_BINDINGS}) |
| 558 | add_subdirectory(bindings/python) |
| 559 | endif() |
| 560 | |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 561 | if(${IREE_BUILD_BINDINGS_TFLITE}) |
| 562 | add_subdirectory(bindings/tflite) |
| 563 | endif() |
| 564 | |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 565 | if(${IREE_BUILD_SAMPLES}) |
| 566 | add_subdirectory(iree/samples) |
| 567 | endif() |
Ben Vanik | b64e918 | 2020-01-30 15:19:37 -0800 | [diff] [blame] | 568 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 569 | if(${IREE_BUILD_EXPERIMENTAL_REMOTING}) |
| 570 | # NOTE: Currently liburing is only used by the experimental remoting |
| 571 | # support, so keeping it scoped here. If this broadens, then include along |
| 572 | # with other dependencies as normal. |
| 573 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") |
| 574 | message(STATUS "Enabling liburing") |
| 575 | add_subdirectory(build_tools/third_party/liburing EXCLUDE_FROM_ALL) |
| 576 | endif() |
| 577 | add_subdirectory(experimental/remoting) |
Ben Vanik | b64e918 | 2020-01-30 15:19:37 -0800 | [diff] [blame] | 578 | endif() |
Scott Todd | ee30e1b | 2020-02-03 16:44:15 -0800 | [diff] [blame] | 579 | |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame] | 580 | if(${IREE_ENABLE_TENSORFLOW}) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 581 | add_subdirectory(integrations/tensorflow) |
| 582 | endif() |
| 583 | |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 584 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 585 | CACHE INTERNAL "IREE: Include Directories" FORCE) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 586 | |
| 587 | # Include the iree-compiler-api sub-project. We do this for development |
| 588 | # and CI so that developers have access to the API and tools it provides |
| 589 | # (otherwise, they would need to build multiple top-level projects). |
| 590 | # However, logically, iree-compiler-api depends on iree, and for deployment |
| 591 | # is always built standalone, taking responsibility to include iree and LLVM |
| 592 | # as sub-projects. |
| 593 | # The dependency mode is controlled by the variables |
| 594 | # IREE_COMPILER_API_STANDALONE, which will be set if iree-compiler-api is |
| 595 | # top-level. Otherwise, we set IREE_COMPILER_API_SUB_PROJECT, indicating it |
| 596 | # is being embedded as a sub project. |
| 597 | if(IREE_BUILD_COMPILER AND IREE_BUILD_PYTHON_BINDINGS) |
| 598 | if(NOT IREE_COMPILER_API_STANDALONE) |
| 599 | message(STATUS "Including iree-compiler-api as a sub-project") |
| 600 | set(IREE_COMPILER_API_SUB_PROJECT ON) |
| 601 | add_subdirectory(llvm-external-projects/iree-compiler-api |
| 602 | "${CMAKE_CURRENT_BINARY_DIR}/compiler-api") |
Stella Laurenzo | 48a4330 | 2021-09-28 17:49:33 -0700 | [diff] [blame] | 603 | |
| 604 | # Write out a .env file to make IDEs and developers happy. |
| 605 | # Yes, we are writing this to the source dir. It is only for IDEs and if |
| 606 | # it gets clobbered, it is fine. |
| 607 | set(_pythonpath_env "PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler-api/python_package;${CMAKE_CURRENT_BINARY_DIR}/bindings/python>\n") |
| 608 | file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" |
| 609 | CONTENT "${_pythonpath_env}" |
| 610 | ) |
| 611 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" |
| 612 | CONTENT "${_pythonpath_env}" |
| 613 | ) |
| 614 | |
| 615 | # TODO: Remove this after about Dec-2021 |
| 616 | if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/bindings/python/iree/compiler") |
| 617 | message(FATAL_ERROR "You are running in a build directory which needs some manual cleanup. Please delete the directory ${CMAKE_CURRENT_BINARY_DIR}/bindings/python/iree/compiler") |
| 618 | endif() |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 619 | endif() |
| 620 | endif() |