Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 1 | # Copyright 2019 Google LLC |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Scott Todd | ee30e1b | 2020-02-03 16:44:15 -0800 | [diff] [blame] | 15 | cmake_minimum_required(VERSION 3.13) |
Geoffrey Martin-Noble | 98bbd96 | 2019-11-21 07:27:39 -0800 | [diff] [blame] | 16 | if(POLICY CMP0077) |
| 17 | cmake_policy(SET CMP0077 NEW) |
| 18 | endif() |
Scott Todd | ee30e1b | 2020-02-03 16:44:15 -0800 | [diff] [blame] | 19 | # Allow target_link_libraries() from other directories (since 3.13): |
| 20 | # https://cmake.org/cmake/help/v3.13/policy/CMP0079.html |
| 21 | if(POLICY CMP0079) |
| 22 | cmake_policy(SET CMP0079 NEW) |
| 23 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 24 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 25 | |
Marius Brehler | 178c82a | 2019-12-27 15:00:04 -0800 | [diff] [blame] | 26 | project(iree CXX C) |
Lei Zhang | 6c5907b | 2020-06-02 09:06:08 -0700 | [diff] [blame] | 27 | set(CMAKE_C_STANDARD 11) |
| 28 | set(CMAKE_CXX_STANDARD 14) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 29 | set(IREE_IDE_FOLDER IREE) |
| 30 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 31 | |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 32 | #------------------------------------------------------------------------------- |
| 33 | # Project component configuration |
| 34 | #------------------------------------------------------------------------------- |
| 35 | |
Lei Zhang | e996799 | 2020-06-03 11:13:00 -0400 | [diff] [blame] | 36 | # LINT.IfChange(iree_options) |
Ben Vanik | 56d44bf | 2020-05-15 13:20:50 -0700 | [diff] [blame] | 37 | option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 38 | option(IREE_ENABLE_MLIR "Enables MLIR/LLVM dependencies." ON) |
Marius Brehler | 4e45a77 | 2020-06-02 14:04:18 -0700 | [diff] [blame] | 39 | option(IREE_ENABLE_EMITC "Enables MLIR EmitC dependencies." OFF) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 40 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 41 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 42 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 43 | option(IREE_BUILD_DOCS "Builds IREE docs." OFF) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 44 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 45 | option(IREE_BUILD_DEBUGGER "Builds the IREE debugger app." OFF) |
Jenni Kilduff | 0d09cf3 | 2020-10-19 10:23:34 -0700 | [diff] [blame] | 46 | option(IREE_BUILD_JAVA_BINDINGS "Builds the IREE java bindings." OFF) |
Ben Vanik | b64e918 | 2020-01-30 15:19:37 -0800 | [diff] [blame] | 47 | option(IREE_BUILD_EXPERIMENTAL "Builds experimental projects." OFF) |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame^] | 48 | option(IREE_BUILD_TENSORFLOW_COMPILER "Builds TensorFlow compiler frontend." OFF) |
| 49 | option(IREE_BUILD_XLA_COMPILER "Builds TensorFlow XLA compiler frontend." OFF) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 50 | |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 51 | set(IREE_HAL_DRIVERS_TO_BUILD "all" |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 52 | CACHE STRING "Semicolon-separated list of HAL drivers to build, or \"all\".") |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 53 | set(IREE_TARGET_BACKENDS_TO_BUILD "all" |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 54 | CACHE STRING "Semicolon-separated list of target backends to build, or \"all\".") |
Stella Laurenzo | 04b7c37 | 2020-12-10 00:05:31 +0000 | [diff] [blame] | 55 | |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame^] | 56 | # Master enable for tensorflow build support. |
| 57 | # Note that this is a normal CMake variable used to gate build features (not |
| 58 | # a cache variable that is user-settable). |
| 59 | set(IREE_ENABLE_TENSORFLOW OFF) |
| 60 | if(${IREE_BUILD_TENSORFLOW_COMPILER} OR ${IREE_BUILD_XLA_COMPILER}) |
| 61 | set(IREE_ENABLE_TENSORFLOW ON) |
| 62 | endif() |
| 63 | |
Stella Laurenzo | 04b7c37 | 2020-12-10 00:05:31 +0000 | [diff] [blame] | 64 | # Default python bindings to enabled for some features. |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame^] | 65 | if(${IREE_ENABLE_TENSORFLOW}) |
Stella Laurenzo | 04b7c37 | 2020-12-10 00:05:31 +0000 | [diff] [blame] | 66 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" ON) |
| 67 | else() |
| 68 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF) |
| 69 | endif() |
| 70 | |
Lei Zhang | e71d973 | 2020-06-23 10:21:09 -0400 | [diff] [blame] | 71 | # LINT.ThenChange( |
Scott Todd | 4e5167d | 2020-06-29 09:30:35 -0700 | [diff] [blame] | 72 | # https://github.com/google/iree/tree/main/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_options, |
| 73 | # https://github.com/google/iree/tree/main/build_tools/cmake/iree_cross_compile.cmake:iree_cross_compile_invoke |
Lei Zhang | e71d973 | 2020-06-23 10:21:09 -0400 | [diff] [blame] | 74 | # ) |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 75 | |
Ben Vanik | b64e918 | 2020-01-30 15:19:37 -0800 | [diff] [blame] | 76 | if(${IREE_BUILD_SAMPLES} OR ${IREE_BUILD_EXPERIMENTAL}) |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 77 | set(IREE_BUILD_COMPILER ON CACHE BOOL "Build the IREE compiler for sample projects." FORCE) |
| 78 | endif() |
| 79 | |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 80 | if(${IREE_BUILD_COMPILER}) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 81 | set(IREE_ENABLE_MLIR ON CACHE BOOL "Enable LLVM dependencies if the IREE compiler is build." FORCE) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 82 | endif() |
| 83 | |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 84 | if(${IREE_ENABLE_MLIR}) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 85 | set(IREE_MLIR_DEP_MODE "BUNDLED" CACHE STRING "One of BUNDLED (default), DISABLED, INSTALLED") |
Marius Brehler | 4e45a77 | 2020-06-02 14:04:18 -0700 | [diff] [blame] | 86 | endif() |
| 87 | |
Marius Brehler | fd8be7f | 2020-06-18 15:59:28 -0700 | [diff] [blame] | 88 | if(${IREE_ENABLE_EMITC}) |
| 89 | if(NOT ${IREE_ENABLE_MLIR}) |
| 90 | message(FATAL_ERROR "Enabling EmitC requires setting IREE_ENABLE_MLIR to ON.") |
| 91 | endif() |
| 92 | |
| 93 | string(TOUPPER "${IREE_MLIR_DEP_MODE}" uppercase_IREE_MLIR_DEP_MODE) |
| 94 | if(NOT uppercase_IREE_MLIR_DEP_MODE MATCHES "^(BUNDLED|INSTALLED)$") |
| 95 | message(FATAL_ERROR "Enabling EmitC requires IREE_MLIR_DEP_MODE set to BUNDELED or INSTALLED.") |
| 96 | endif() |
| 97 | endif() |
| 98 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 99 | #------------------------------------------------------------------------------- |
Lei Zhang | 8bea2e8 | 2020-06-04 10:17:56 -0400 | [diff] [blame] | 100 | # Target and backend configuration |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 101 | #------------------------------------------------------------------------------- |
| 102 | |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 103 | # List of all HAL drivers to be built by default: |
| 104 | set(IREE_ALL_HAL_DRIVERS |
Scott Todd | 217904d | 2020-06-04 13:38:32 -0700 | [diff] [blame] | 105 | DyLib |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 106 | LLVM |
Lei Zhang | 6171a98 | 2020-09-08 12:48:25 -0400 | [diff] [blame] | 107 | Metal |
Geoffrey Martin-Noble | dfb7633 | 2020-08-07 11:22:39 -0700 | [diff] [blame] | 108 | VMLA |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 109 | Vulkan |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 110 | ) |
| 111 | |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 112 | if(IREE_HAL_DRIVERS_TO_BUILD STREQUAL "all") |
| 113 | set(IREE_HAL_DRIVERS_TO_BUILD ${IREE_ALL_HAL_DRIVERS}) |
Ben Vanik | 0135343 | 2020-11-17 03:15:40 -0800 | [diff] [blame] | 114 | # For cross compilation towards Android, we don't want LLVM JIT HAL driver. |
Lei Zhang | 7d90e0e | 2020-07-23 16:01:13 -0400 | [diff] [blame] | 115 | if(ANDROID) |
Han-Chung Wang | 8cc22a3 | 2020-10-20 08:45:33 -0700 | [diff] [blame] | 116 | list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD LLVM) |
Lei Zhang | 7d90e0e | 2020-07-23 16:01:13 -0400 | [diff] [blame] | 117 | endif() |
Lei Zhang | 6171a98 | 2020-09-08 12:48:25 -0400 | [diff] [blame] | 118 | |
| 119 | # For Apple platforms we need to use Metal instead of Vulkan. |
| 120 | if(APPLE) |
| 121 | list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD Vulkan) |
| 122 | else() |
| 123 | # And Metal isn't available on non-Apple platforms for sure. |
| 124 | list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD Metal) |
| 125 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 126 | endif() |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 127 | message(STATUS "Building HAL drivers: ${IREE_HAL_DRIVERS_TO_BUILD}") |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 128 | |
| 129 | # Default every IREE_HAL_DRIVER_* to OFF |
| 130 | foreach(_backend ${IREE_ALL_HAL_DRIVERS}) |
| 131 | string(TOUPPER "${_backend}" uppercase_backend) |
| 132 | set(IREE_HAL_DRIVER_${uppercase_backend} OFF CACHE BOOL "" FORCE) |
| 133 | endforeach() |
| 134 | |
| 135 | # Set IREE_HAL_DRIVER_* based on configuration |
| 136 | foreach(_backend ${IREE_HAL_DRIVERS_TO_BUILD}) |
| 137 | string(TOUPPER "${_backend}" uppercase_backend) |
| 138 | set(IREE_HAL_DRIVER_${uppercase_backend} ON CACHE BOOL "" FORCE) |
| 139 | endforeach() |
| 140 | |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 141 | # List of all target backends to be built by default: |
| 142 | set(IREE_ALL_TARGET_BACKENDS |
Scott Todd | aaa08b1 | 2020-12-09 11:00:11 -0800 | [diff] [blame] | 143 | DYLIB-LLVM-AOT |
Lei Zhang | 7d90e0e | 2020-07-23 16:01:13 -0400 | [diff] [blame] | 144 | LLVM-IR |
Lei Zhang | 3cbb28e | 2020-09-22 15:30:27 -0400 | [diff] [blame] | 145 | Metal-SPIRV |
Lei Zhang | 7d90e0e | 2020-07-23 16:01:13 -0400 | [diff] [blame] | 146 | Vulkan-SPIRV |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 147 | VMLA |
| 148 | ) |
| 149 | |
| 150 | if( IREE_TARGET_BACKENDS_TO_BUILD STREQUAL "all" ) |
| 151 | set( IREE_TARGET_BACKENDS_TO_BUILD ${IREE_ALL_TARGET_BACKENDS} ) |
| 152 | endif() |
Scott Todd | 6132bb3 | 2020-08-11 12:04:40 -0700 | [diff] [blame] | 153 | message(STATUS "Building target backends: ${IREE_TARGET_BACKENDS_TO_BUILD}") |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 154 | |
| 155 | # Default every IREE_TARGET_BACKEND_* to OFF |
| 156 | foreach(_backend ${IREE_ALL_TARGET_BACKENDS}) |
| 157 | string(TOUPPER "${_backend}" uppercase_backend) |
| 158 | set(IREE_TARGET_BACKEND_${uppercase_backend} OFF CACHE BOOL "" FORCE) |
| 159 | endforeach() |
| 160 | |
| 161 | # Set IREE_TARGET_BACKEND_* based on configuration |
| 162 | foreach(_backend ${IREE_TARGET_BACKENDS_TO_BUILD}) |
| 163 | string(TOUPPER "${_backend}" uppercase_backend) |
| 164 | set(IREE_TARGET_BACKEND_${uppercase_backend} ON CACHE BOOL "" FORCE) |
| 165 | endforeach() |
| 166 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 167 | list(APPEND CMAKE_MODULE_PATH |
| 168 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 169 | ${CMAKE_CURRENT_LIST_DIR}/bindings/python/build_tools/cmake/ |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 170 | ${CMAKE_CURRENT_LIST_DIR}/third_party/abseil-cpp/absl/copts/ |
| 171 | ) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 172 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 173 | #------------------------------------------------------------------------------- |
| 174 | # Cross compiling configuration |
| 175 | #------------------------------------------------------------------------------- |
| 176 | |
| 177 | if(CMAKE_CROSSCOMPILING) |
Lei Zhang | 45695f9 | 2020-06-16 19:36:41 -0400 | [diff] [blame] | 178 | message(STATUS "Detected cross compilation mode; configuring IREE on host...") |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 179 | |
| 180 | # C/C++ compilers for host compilation. |
| 181 | # Note: we need to explicitly set this because IREE does not work well with |
| 182 | # GCC at the moment: https://github.com/google/iree/issues/1269 |
| 183 | set(IREE_HOST_C_COMPILER "$ENV{IREE_HOST_C_COMPILER}" CACHE FILEPATH "C compiler for host compilation") |
| 184 | set(IREE_HOST_CXX_COMPILER "$ENV{IREE_HOST_CXX_COMPILER}" CACHE FILEPATH "C++ compiler for host compilation") |
| 185 | |
| 186 | # Master configuration for the binary directory containing all artifacts |
| 187 | # compiled for host. |
Lei Zhang | e71d973 | 2020-06-23 10:21:09 -0400 | [diff] [blame] | 188 | if(NOT IREE_HOST_BINARY_ROOT) |
| 189 | set(IREE_HOST_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/host" CACHE FILEPATH "directory containing host artifacts") |
| 190 | endif() |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 191 | |
| 192 | set(IREE_HOST_BUILD_COMPILER ON) # For iree-translate |
| 193 | set(IREE_HOST_ENABLE_LLVM ON) # For iree-tblgen |
| 194 | |
| 195 | # Set the host build directory for LLVM to our directory. Otherwise it will |
| 196 | # follow its own convention. |
Lei Zhang | 7f6dfbf | 2020-06-30 14:31:35 -0400 | [diff] [blame] | 197 | set(LLVM_NATIVE_BUILD |
| 198 | "${IREE_HOST_BINARY_ROOT}/third_party/llvm-project/llvm" |
| 199 | CACHE FILEPATH "directory containing host artifacts for LLVM" |
| 200 | ) |
| 201 | |
| 202 | # And set host C/C++ compiler for LLVM. This makes cross compilation using |
| 203 | # Windows as the host platform nicer. Because we have various development |
| 204 | # evnironments on Windows (CMD, Cygwin, MSYS, etc.), LLVM can have problems |
| 205 | # figuring out the host triple and toolchain. We are passing in the host |
| 206 | # C/C++ compiler toolchain for IREE anyway; so we can give LLVM side some |
| 207 | # help here. This hides some complexity and ugliness from the users. |
| 208 | set(CROSS_TOOLCHAIN_FLAGS_NATIVE |
| 209 | "-DCMAKE_C_COMPILER=\"${IREE_HOST_C_COMPILER}\";-DCMAKE_CXX_COMPILER=\"${IREE_HOST_CXX_COMPILER}\"" |
| 210 | CACHE FILEPATH "LLVM toolchain configuration for host build" |
| 211 | ) |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 212 | |
| 213 | include(iree_cross_compile) |
| 214 | |
| 215 | # Use another CMake invocation to configure a build for host. |
| 216 | iree_create_configuration(HOST) |
Lei Zhang | 1e6a7a7 | 2020-06-04 13:12:01 -0400 | [diff] [blame] | 217 | |
Lei Zhang | 45695f9 | 2020-06-16 19:36:41 -0400 | [diff] [blame] | 218 | message(STATUS "Done configuring IREE on host in ${IREE_HOST_BINARY_ROOT}") |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 219 | endif() |
| 220 | |
| 221 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 222 | # IREE compilation toolchain configuration |
| 223 | #------------------------------------------------------------------------------- |
| 224 | |
| 225 | # Enable using lld as the linker for C/C++ targets. This affects IREE and all |
| 226 | # dependency projects. |
| 227 | option(IREE_ENABLE_LLD "Use lld when linking" OFF) |
| 228 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 229 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 230 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 231 | option(IREE_ENABLE_CCACHE "Use ccache if installed to speed up rebuilds." OFF) |
| 232 | |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 233 | if(${IREE_ENABLE_CCACHE}) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 234 | find_program(CCACHE_PROGRAM ccache) |
| 235 | if(CCACHE_PROGRAM) |
| 236 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
| 237 | endif() |
| 238 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 239 | |
| 240 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 241 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 242 | #------------------------------------------------------------------------------- |
| 243 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 244 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 245 | include(iree_copts) |
bjacob | c12ba3b | 2020-11-03 10:32:00 -0500 | [diff] [blame] | 246 | include(sanitizers) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 247 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 248 | include(iree_cc_library) |
| 249 | include(iree_cc_test) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 250 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 251 | include(iree_tablegen_doc) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 252 | include(iree_cc_embed_data) |
| 253 | include(iree_bytecode_module) |
Stella Laurenzo | 66578b0 | 2020-07-20 17:34:44 -0700 | [diff] [blame] | 254 | include(iree_multipy) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 255 | include(iree_lit_test) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 256 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 257 | include(iree_check_test) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 258 | |
Marius Brehler | c4b6b91 | 2020-01-15 08:44:23 -0800 | [diff] [blame] | 259 | set(DEFAULT_CMAKE_BUILD_TYPE "Release") |
Ben Vanik | 85cdd86 | 2020-11-14 11:26:12 -0800 | [diff] [blame] | 260 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
Marius Brehler | c4b6b91 | 2020-01-15 08:44:23 -0800 | [diff] [blame] | 261 | message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}") |
| 262 | set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
| 263 | endif() |
| 264 | |
Marius Brehler | 06ac36e | 2020-01-10 14:44:11 -0800 | [diff] [blame] | 265 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 266 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 267 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 268 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 269 | #------------------------------------------------------------------------------- |
| 270 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 271 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 272 | 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] | 273 | |
| 274 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 275 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 276 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 277 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 278 | mark_as_advanced( |
| 279 | CMAKE_CXX_FLAGS_FASTBUILD |
| 280 | CMAKE_C_FLAGS_FASTBUILD |
| 281 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 282 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 283 | ) |
| 284 | |
| 285 | include(iree_setup_toolchain) |
| 286 | |
| 287 | #------------------------------------------------------------------------------- |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 288 | # Configure python early if there are any features that need it. |
| 289 | # Note that doing this early ensures that dependencies that make incidental |
| 290 | # use of Python (such as LLVM) resolve the same version. |
| 291 | #------------------------------------------------------------------------------- |
| 292 | |
| 293 | if(${IREE_BUILD_COMPILER} OR |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame^] | 294 | ${IREE_BUILD_PYTHON_BINDINGS}) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 295 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
| 296 | endif() |
| 297 | |
| 298 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 299 | # MLIR/LLVM Dependency |
| 300 | # We treat the LLVM dependency specially because we support several different |
| 301 | # ways to use it: |
scotttodd | 354b691 | 2020-06-24 16:29:35 -0700 | [diff] [blame] | 302 | # - Bundled (default): a source dependency directly on the |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 303 | # third_party/llvm-project submodule. |
| 304 | # - External: An external (source or installed) dependency on LLVM. |
| 305 | # - Provided: When IREE is used as a sub-project, it is assumed that the LLVM |
| 306 | # dependency is added prior to including this configuration. |
| 307 | #------------------------------------------------------------------------------- |
| 308 | |
Ben Vanik | afd7abe | 2020-10-07 09:01:53 -0700 | [diff] [blame] | 309 | # Disable LLVM's warnings. |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 310 | set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "don't use global flags /facepalm") |
| 311 | set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "don't use global flags /facepalm") |
Ben Vanik | afd7abe | 2020-10-07 09:01:53 -0700 | [diff] [blame] | 312 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 313 | # Adds bundled projects that must be included after the LLVM directory has |
scotttodd | 354b691 | 2020-06-24 16:29:35 -0700 | [diff] [blame] | 314 | # been added and within the scope of its settings (i.e. build type override, |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 315 | # etc). |
| 316 | function(add_bundled_mlir_dependent_projects) |
| 317 | if(${IREE_ENABLE_EMITC}) |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 318 | add_subdirectory(third_party/mlir-emitc EXCLUDE_FROM_ALL) |
| 319 | endif() |
| 320 | |
| 321 | if(${IREE_BUILD_COMPILER}) |
| 322 | add_subdirectory(third_party/tensorflow/tensorflow/compiler/mlir/hlo EXCLUDE_FROM_ALL) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 323 | endif() |
| 324 | endfunction() |
| 325 | |
| 326 | function(add_iree_mlir_src_dep llvm_monorepo_path) |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 327 | # Stash cmake build type in case LLVM messes with it. |
| 328 | set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}") |
| 329 | |
Thomas Raoux | 3b6a42a | 2020-06-26 18:18:48 -0700 | [diff] [blame] | 330 | # experimental model builder uses vulkan runner. |
| 331 | if(${IREE_BUILD_EXPERIMENTAL}) |
| 332 | set(MLIR_VULKAN_RUNNER_ENABLED ON) |
| 333 | endif() |
| 334 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 335 | add_subdirectory("${llvm_monorepo_path}/llvm" "third_party/llvm-project/llvm" EXCLUDE_FROM_ALL) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 336 | |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 337 | # Reset CMAKE_BUILD_TYPE to its previous setting. |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 338 | set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
| 339 | endfunction() |
| 340 | |
| 341 | if(${IREE_ENABLE_MLIR}) |
| 342 | if(${IREE_MLIR_DEP_MODE} STREQUAL "DISABLED") |
| 343 | message(STATUS "Not adding MLIR/LLVM dep due to IREE_MLIR_DEP_MODE=DISABLED") |
| 344 | elseif(${IREE_MLIR_DEP_MODE} STREQUAL "BUNDLED") |
| 345 | message(STATUS "Adding bundled LLVM source dependency") |
| 346 | add_iree_mlir_src_dep("third_party/llvm-project") |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 347 | |
Ben Vanik | 6bc6f90 | 2020-11-16 05:37:08 -0800 | [diff] [blame] | 348 | # Extend module path to allow submodules to use LLVM and MLIR CMake modules. |
Ben Vanik | 479ef30 | 2020-11-14 08:36:35 -0800 | [diff] [blame] | 349 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/mlir") |
| 350 | 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] | 351 | |
Ben Vanik | 6bc6f90 | 2020-11-16 05:37:08 -0800 | [diff] [blame] | 352 | # Add the bundled include directories for cmake files looking for them. |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 353 | list(APPEND LLVM_INCLUDE_DIRS |
Ben Vanik | 479ef30 | 2020-11-14 08:36:35 -0800 | [diff] [blame] | 354 | ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/llvm/include |
| 355 | ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/include |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 356 | ) |
| 357 | list(APPEND MLIR_INCLUDE_DIRS |
Ben Vanik | 479ef30 | 2020-11-14 08:36:35 -0800 | [diff] [blame] | 358 | ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/mlir/include |
| 359 | ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 360 | ) |
| 361 | |
Ben Vanik | 6bc6f90 | 2020-11-16 05:37:08 -0800 | [diff] [blame] | 362 | # Avoid globally modifying paths by instead adding the include paths to the |
| 363 | # rules that really should have them in the first place. |
| 364 | target_include_directories(LLVMSupport PUBLIC |
| 365 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/llvm/include> |
| 366 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/include> |
| 367 | ) |
| 368 | target_include_directories(MLIRSupport PUBLIC |
| 369 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/mlir/include> |
| 370 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include> |
| 371 | ) |
| 372 | |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 373 | # Set build option to use MHLO alongside with bundled MLIR |
| 374 | set(MHLO_BUILD_EMBEDDED ON) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 375 | elseif(${IREE_MLIR_DEP_MODE} STREQUAL "INSTALLED") |
Stella Laurenzo | a1914e7 | 2020-07-25 00:06:47 -0700 | [diff] [blame] | 376 | # Deps of installed MLIR/LLVM packages. |
| 377 | find_package(ZLIB) # See: https://reviews.llvm.org/D79219 |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 378 | message(STATUS "Looking for installed MLIR/LLVM packages (configure with MLIR_DIR variable)") |
| 379 | find_package(MLIR REQUIRED CONFIG) |
| 380 | message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") |
| 381 | message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") |
| 382 | list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") |
| 383 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") |
| 384 | include(TableGen) |
| 385 | include(AddLLVM) |
| 386 | include(AddMLIR) |
| 387 | include(HandleLLVMOptions) |
| 388 | |
| 389 | # Add include/link directories |
Ben Vanik | afd7abe | 2020-10-07 09:01:53 -0700 | [diff] [blame] | 390 | include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) |
| 391 | include_directories(SYSTEM ${MLIR_INCLUDE_DIRS}) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 392 | link_directories(${LLVM_BUILD_LIBRARY_DIR}) |
| 393 | add_definitions(${LLVM_DEFINITIONS}) |
| 394 | else() |
| 395 | message(FATAL "Unsupported IREE_MLIR_DEP_MODE=${IREE_MLIR_DEP_MODE}") |
| 396 | endif() |
| 397 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 398 | add_bundled_mlir_dependent_projects() |
| 399 | endif() |
| 400 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 401 | #------------------------------------------------------------------------------- |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 402 | # Python bindings. |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 403 | #------------------------------------------------------------------------------- |
| 404 | |
Lei Zhang | 8478778 | 2020-06-02 08:42:25 -0700 | [diff] [blame] | 405 | if(${IREE_BUILD_PYTHON_BINDINGS}) |
Stella Laurenzo | c8f906c | 2020-07-21 13:55:50 -0700 | [diff] [blame] | 406 | # Note: Optional because python libs can be manually specified. |
Marius Brehler | af7b4c3 | 2020-11-24 19:19:17 +0100 | [diff] [blame] | 407 | find_package(Python3 COMPONENTS Interpreter Development REQUIRED) |
Scott Todd | 4af17b6 | 2019-12-17 16:47:00 -0800 | [diff] [blame] | 408 | endif() |
| 409 | |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 410 | #------------------------------------------------------------------------------- |
| 411 | # Bazel setup (conditional on whether features need it) |
| 412 | # Depends on python configuration. |
| 413 | #------------------------------------------------------------------------------- |
| 414 | |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame^] | 415 | if(${IREE_ENABLE_TENSORFLOW}) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 416 | include(configure_bazel) |
| 417 | iree_configure_bazel() |
| 418 | endif() |
| 419 | |
| 420 | #------------------------------------------------------------------------------- |
| 421 | # Other dependencies. |
| 422 | #------------------------------------------------------------------------------- |
| 423 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 424 | include(external_cc_library) |
Ben Vanik | 2d1808b | 2020-07-17 19:02:16 -0700 | [diff] [blame] | 425 | include(flatbuffer_c_library) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 426 | |
Ben Vanik | 71527c2 | 2020-07-17 13:09:57 -0700 | [diff] [blame] | 427 | add_subdirectory(build_tools/third_party/flatcc EXCLUDE_FROM_ALL) |
Thomas | 6456bfb | 2020-11-18 15:05:13 -0800 | [diff] [blame] | 428 | add_subdirectory(build_tools/third_party/half EXCLUDE_FROM_ALL) |
NatashaKnk | 0d7e00f | 2020-11-10 19:16:31 -0800 | [diff] [blame] | 429 | add_subdirectory(build_tools/third_party/pffft EXCLUDE_FROM_ALL) |
Ben Vanik | 71527c2 | 2020-07-17 13:09:57 -0700 | [diff] [blame] | 430 | add_subdirectory(build_tools/third_party/renderdoc_api EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 431 | add_subdirectory(build_tools/third_party/ruy EXCLUDE_FROM_ALL) |
Ben Vanik | 28040cd | 2020-11-14 10:52:22 -0800 | [diff] [blame] | 432 | add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 433 | |
Ben Vanik | da79d9b | 2020-10-01 09:52:54 -0700 | [diff] [blame] | 434 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 435 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 436 | add_subdirectory(third_party/abseil-cpp EXCLUDE_FROM_ALL) |
Ben Vanik | 71527c2 | 2020-07-17 13:09:57 -0700 | [diff] [blame] | 437 | add_subdirectory(third_party/flatcc EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 438 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 439 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 440 | if(CMAKE_CROSSCOMPILING) |
Lei Zhang | 1e6a7a7 | 2020-06-04 13:12:01 -0400 | [diff] [blame] | 441 | # We need flatc to generate some source code. When cross-compiling, we need |
| 442 | # to make sure the flatc binary is configured under host environment. |
Scott Todd | 7f4c2d2 | 2020-10-14 14:10:22 -0700 | [diff] [blame] | 443 | iree_declare_host_excutable(flatc "flatc" BUILDONLY) |
| 444 | iree_declare_host_excutable(flatcc_cli "flatcc_cli" BUILDONLY) |
Lei Zhang | 1e6a7a7 | 2020-06-04 13:12:01 -0400 | [diff] [blame] | 445 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 446 | # Set the FLATBUFFERS_FLATC_EXECUTABLE. It controls where to find the flatc |
| 447 | # binary in BuildFlatBuffers(). |
Lei Zhang | 486e707 | 2020-06-16 11:42:49 -0400 | [diff] [blame] | 448 | iree_get_executable_path(FLATBUFFERS_FLATC_EXECUTABLE flatc) |
Lei Zhang | 1e6a7a7 | 2020-06-04 13:12:01 -0400 | [diff] [blame] | 449 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 450 | # Add a custom target to copy the flatc to the binary directory. |
Ben Vanik | eb53de3 | 2020-07-17 19:05:27 -0700 | [diff] [blame] | 451 | add_custom_target(iree_host_flatcc_cli |
Ben Vanik | 71527c2 | 2020-07-17 13:09:57 -0700 | [diff] [blame] | 452 | COMMAND |
| 453 | "${CMAKE_COMMAND}" -E copy_if_different |
Ben Vanik | 479ef30 | 2020-11-14 08:36:35 -0800 | [diff] [blame] | 454 | "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatcc/bin/flatcc${IREE_HOST_EXECUTABLE_SUFFIX}" |
Scott Todd | 7f4c2d2 | 2020-10-14 14:10:22 -0700 | [diff] [blame] | 455 | "${IREE_HOST_BINARY_ROOT}/bin/flatcc_cli${IREE_HOST_EXECUTABLE_SUFFIX}" |
Ben Vanik | eb53de3 | 2020-07-17 19:05:27 -0700 | [diff] [blame] | 456 | DEPENDS iree_host_build_flatcc_cli |
Ben Vanik | 71527c2 | 2020-07-17 13:09:57 -0700 | [diff] [blame] | 457 | COMMENT "Installing host flatcc..." |
| 458 | ) |
Ben Vanik | 1425737 | 2020-07-21 08:05:18 -0700 | [diff] [blame] | 459 | else() |
| 460 | # TODO: unify flatc and flatcc handling to the same mechanism. |
| 461 | add_executable(iree_host_flatcc_cli ALIAS flatcc_cli) |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 462 | endif() |
| 463 | |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 464 | if(${IREE_BUILD_COMPILER}) |
Marius Brehler | 87eaa3c | 2020-07-02 17:39:49 +0200 | [diff] [blame] | 465 | add_subdirectory(build_tools/third_party/tensorflow/tensorflow/compiler/mlir/hlo EXCLUDE_FROM_ALL) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 466 | endif() |
| 467 | |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 468 | if(${IREE_BUILD_TESTS}) |
| 469 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
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 | |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 473 | if(${IREE_BUILD_PYTHON_BINDINGS}) |
Stella Laurenzo | 66578b0 | 2020-07-20 17:34:44 -0700 | [diff] [blame] | 474 | # NOTE: The multipy defaults come from pybind's configuration and must come |
| 475 | # after. This should be pulled in locally at some point. |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 476 | add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL) |
Stella Laurenzo | 66578b0 | 2020-07-20 17:34:44 -0700 | [diff] [blame] | 477 | iree_multipy_configure() |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 478 | endif() |
| 479 | |
Lei Zhang | 3cbb28e | 2020-09-22 15:30:27 -0400 | [diff] [blame] | 480 | if(${IREE_TARGET_BACKEND_METAL-SPIRV}) |
| 481 | # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code. |
| 482 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 483 | endif() |
| 484 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 485 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 486 | # IREE top-level targets |
| 487 | #------------------------------------------------------------------------------- |
| 488 | |
| 489 | if(${IREE_BUILD_DOCS}) |
| 490 | # Add a top-level custom target to drive generating all documentation. |
| 491 | # Register it to the default target given that IREE_BUILD_DOCS is explicitly |
| 492 | # requested. |
| 493 | add_custom_target(iree-doc ALL) |
| 494 | endif() |
| 495 | |
| 496 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 497 | # IREE top-level libraries |
| 498 | #------------------------------------------------------------------------------- |
| 499 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 500 | add_subdirectory(build_tools/embed_data/) |
| 501 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 502 | add_subdirectory(iree/base) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 503 | add_subdirectory(iree/hal) |
Marius Brehler | 9317d1f | 2020-01-08 10:34:11 -0800 | [diff] [blame] | 504 | add_subdirectory(iree/modules) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 505 | add_subdirectory(iree/schemas) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 506 | add_subdirectory(iree/testing) |
Marius Brehler | 476031a | 2020-03-24 16:14:30 -0700 | [diff] [blame] | 507 | add_subdirectory(iree/test) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 508 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 509 | if(${IREE_ENABLE_MLIR}) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 510 | # The VM requires LLVM to build its op definitions. |
| 511 | add_subdirectory(iree/vm) |
| 512 | endif() |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 513 | |
| 514 | if(${IREE_BUILD_COMPILER}) |
| 515 | add_subdirectory(iree/compiler) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 516 | elseif(${IREE_ENABLE_MLIR}) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 517 | # If not building the compiler, tablegen is still needed |
| 518 | # to generate vm ops so deep include it only. |
Marius Brehler | c61240a | 2020-04-20 11:22:59 -0700 | [diff] [blame] | 519 | add_subdirectory(iree/compiler/Dialect/IREE/Tools) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 520 | add_subdirectory(iree/compiler/Dialect/VM/Tools) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 521 | endif() |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 522 | |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 523 | if(${IREE_BUILD_PYTHON_BINDINGS}) |
| 524 | add_subdirectory(bindings/python) |
| 525 | endif() |
| 526 | |
Jenni Kilduff | 0d09cf3 | 2020-10-19 10:23:34 -0700 | [diff] [blame] | 527 | if(${IREE_BUILD_JAVA_BINDINGS}) |
| 528 | add_subdirectory(bindings/java) |
| 529 | add_subdirectory(bindings/javatests) |
| 530 | endif() |
| 531 | |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 532 | add_subdirectory(iree/tools) |
| 533 | |
| 534 | if(${IREE_BUILD_SAMPLES}) |
| 535 | add_subdirectory(iree/samples) |
| 536 | endif() |
Ben Vanik | b64e918 | 2020-01-30 15:19:37 -0800 | [diff] [blame] | 537 | |
| 538 | if(${IREE_BUILD_EXPERIMENTAL}) |
| 539 | add_subdirectory(experimental) |
| 540 | endif() |
Scott Todd | ee30e1b | 2020-02-03 16:44:15 -0800 | [diff] [blame] | 541 | |
Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame^] | 542 | if(${IREE_ENABLE_TENSORFLOW}) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 543 | add_subdirectory(integrations/tensorflow) |
| 544 | endif() |
| 545 | |
Marius Brehler | 42cc5e6 | 2020-02-18 11:17:12 -0800 | [diff] [blame] | 546 | if(${IREE_BUILD_PYTHON_BINDINGS}) |
| 547 | iree_complete_py_extension_link_options() |
| 548 | endif() |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 549 | |
| 550 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 551 | CACHE INTERNAL "IREE: Include Directories" FORCE) |