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 | |
Scott Todd | a24c8c5 | 2022-05-17 09:22:47 -0700 | [diff] [blame] | 7 | cmake_minimum_required(VERSION 3.21...3.23) |
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) |
Scott Todd | 07349fa | 2022-07-27 12:16:05 -0700 | [diff] [blame] | 18 | set(CMAKE_CXX_STANDARD 17) |
Stella Laurenzo | bc09f0e | 2022-07-27 16:22:39 -0700 | [diff] [blame] | 19 | # LLVM defines this as a CACHE property and uses a policy that causes the |
| 20 | # cache value to take precedence. This is causing us to mix 17/14 across |
| 21 | # the boundary. |
| 22 | # TODO: Remove this once the LLVM mechanism is updated. See: |
| 23 | # https://discourse.llvm.org/t/important-new-toolchain-requirements-to-build-llvm-will-most-likely-be-landing-within-a-week-prepare-your-buildbots/61447/9 |
| 24 | set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to" FORCE) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 25 | set(IREE_IDE_FOLDER IREE) |
| 26 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 27 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 28 | if(MSVC) |
Ben Vanik | 96fd277 | 2021-04-19 20:30:56 -0700 | [diff] [blame] | 29 | enable_language(ASM_MASM) |
| 30 | else() |
| 31 | enable_language(ASM) |
| 32 | endif() |
| 33 | |
Cindy Liu | b1bfb9c | 2022-06-27 10:46:13 -0700 | [diff] [blame] | 34 | # Set the default CMake build type so some of the build type dependent setting |
| 35 | # in the submodules and functions (IREE assertion) can be set properly. |
Cindy Liu | 23dafd0 | 2022-06-22 15:36:21 -0700 | [diff] [blame] | 36 | set(DEFAULT_CMAKE_BUILD_TYPE "Release") |
| 37 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 38 | message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}") |
| 39 | set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
| 40 | endif() |
| 41 | |
Scott Todd | 99e9f5b | 2021-12-30 10:56:12 -0800 | [diff] [blame] | 42 | include(CMakeDependentOption) |
| 43 | |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 44 | #------------------------------------------------------------------------------- |
| 45 | # Project component configuration |
| 46 | #------------------------------------------------------------------------------- |
| 47 | |
Ben Vanik | 56d44bf | 2020-05-15 13:20:50 -0700 | [diff] [blame] | 48 | option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF) |
Scott Todd | 1cd9f0a | 2021-07-29 10:05:44 -0700 | [diff] [blame] | 49 | option(IREE_ENABLE_COMPILER_TRACING "Enables instrumented compiler tracing." OFF) |
Geoffrey Martin-Noble | fe74bd4 | 2021-10-27 22:17:13 -0700 | [diff] [blame] | 50 | option(IREE_ENABLE_THREADING "Builds IREE in with thread library support." ON) |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 51 | option(IREE_ENABLE_CLANG_TIDY "Builds IREE in with clang tidy enabled on IREE's libraries." OFF) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 52 | |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 53 | # TODO(#8469): remove the dependency on cpuinfo entirely. |
| 54 | option(IREE_ENABLE_CPUINFO "Enables runtime use of cpuinfo for processor topology detection." ON) |
| 55 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 56 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 57 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 58 | option(IREE_BUILD_DOCS "Builds IREE docs." OFF) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 59 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 60 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF) |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 61 | option(IREE_BUILD_TRACY "Builds tracy server tools." OFF) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 62 | |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 63 | option(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER "Use the system linker when generating IREE modules in tests/samples/benchmarks (useful for Tracy)." OFF) |
bjacob | 1af90ee | 2022-03-28 22:10:53 -0400 | [diff] [blame] | 64 | |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 65 | # Properties controlling version and naming of release artifacts. |
Stella Laurenzo | f33f5b5 | 2022-01-08 17:49:52 +0000 | [diff] [blame] | 66 | set(IREE_RELEASE_PACKAGE_SUFFIX "" CACHE STRING "Suffix to append to distributed package names") |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 67 | set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages") |
| 68 | set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages") |
| 69 | |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 70 | 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] | 71 | 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] | 72 | |
Jerry Wu | b6b1dee | 2022-06-01 13:45:16 +0000 | [diff] [blame] | 73 | # Properties building and controlling benchmark suites. |
| 74 | option(IREE_BUILD_BENCHMARKS "Builds IREE benchmark suites." OFF) |
| 75 | # TODO(pzread): Currently IREE_ENABLE_COMPILATION_BENCHMARKS needs |
| 76 | # IREE_BUILD_BENCHMARKS. Eventually we will decouple them. |
| 77 | cmake_dependent_option(IREE_ENABLE_COMPILATION_BENCHMARKS "Builds IREE benchmark suites for compilation statistics." OFF ${IREE_BUILD_BENCHMARKS} OFF) |
| 78 | |
| 79 | option(IREE_BUILD_MICROBENCHMARKS "Builds IREE microbenchmark suites." OFF) |
| 80 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 81 | #------------------------------------------------------------------------------- |
| 82 | # Experimental project flags |
| 83 | #------------------------------------------------------------------------------- |
| 84 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 85 | option(IREE_BUILD_EXPERIMENTAL_REMOTING "Builds experimental remoting support." OFF) |
Ben Vanik | a372ab5 | 2022-07-25 18:40:22 -0700 | [diff] [blame] | 86 | option(IREE_BUILD_EXPERIMENTAL_VMVX_MMT4D "Enables MMT4D methods in the VMVX module." OFF) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 87 | option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." OFF) |
Jerry Wu | 5263dde | 2022-09-21 11:30:35 -0700 | [diff] [blame] | 88 | option(IREE_BUILD_EXPERIMENTAL_PYTHON_GENERATED_BENCHMARKS "Builds IREE benchmark suites generated by the python benchmark framework." OFF) |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 89 | |
| 90 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 91 | # Runtime HAL Driver Options |
| 92 | # By default, all runtime drivers supported by the current platform which do |
| 93 | # not require external deps are enabled by default. This can be changed with: |
| 94 | # -DIREE_HAL_DRIVER_DEFAULTS=OFF |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 95 | #------------------------------------------------------------------------------- |
| 96 | |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 97 | # External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more |
| 98 | # information on how to declare external drivers. |
| 99 | set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "") |
| 100 | |
Ben Vanik | 8916027 | 2022-09-26 16:44:11 -0700 | [diff] [blame] | 101 | # Additional executable loader deps to add dependent libraries to any target |
| 102 | # using the default executable loader registration utilities. |
| 103 | # TODO(benvanik): extend the deps to encompass the built-in loaders too so that |
| 104 | # we have one flag. We could also support a list of deps and automatically |
| 105 | # generate the registration from that via a configure file. |
| 106 | set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "") |
| 107 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 108 | option(IREE_HAL_DRIVER_DEFAULTS "Sets the default value for all runtime HAL drivers" ON) |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 109 | # CUDA support must be explicitly enabled. |
| 110 | set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF) |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 111 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 112 | # Vulkan is not natively supported on Apple platforms. |
| 113 | # Metal should generally be used instead, though MoltenVK may also work. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 114 | if(APPLE) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 115 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF) |
| 116 | else() |
| 117 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
| 118 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 119 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 120 | option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 121 | option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 122 | option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 123 | option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT}) |
| 124 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 125 | option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON) |
| 126 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 127 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 128 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 129 | |
| 130 | # Emscripten builds don't support embedded ELF libraries. |
| 131 | if(EMSCRIPTEN) |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 132 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 133 | endif() |
| 134 | |
| 135 | # If forcing system libraries (for TSAN/debugging tools/etc) then ensure the |
| 136 | # system library loader is linked in. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 137 | if(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 138 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ON) |
| 139 | endif() |
| 140 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 141 | # If no local driver is enabled then we force all the loaders off; this allows |
| 142 | # for simpler checks that don't need to see if both the driver and loader is |
| 143 | # available. |
| 144 | if(NOT IREE_HAL_DRIVER_LOCAL_SYNC AND NOT IREE_HAL_DRIVER_LOCAL_TASK) |
| 145 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
| 146 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT OFF) |
| 147 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT OFF) |
| 148 | endif() |
| 149 | |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 150 | option(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF "Enables the embedded dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 151 | option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT}) |
| 152 | option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT}) |
| 153 | |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 154 | if(IREE_BUILD_COMPILER) |
| 155 | # The compiler requires the local task driver with the VMVX loader. |
| 156 | set(IREE_HAL_DRIVER_LOCAL_TASK ON) |
| 157 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE ON) |
| 158 | endif() |
| 159 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 160 | message(STATUS "IREE HAL drivers:") |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 161 | if(IREE_HAL_DRIVER_CUDA) |
| 162 | message(STATUS " - cuda") |
| 163 | endif() |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 164 | if(IREE_HAL_DRIVER_LOCAL_SYNC) |
| 165 | message(STATUS " - local-sync") |
| 166 | endif() |
| 167 | if(IREE_HAL_DRIVER_LOCAL_TASK) |
| 168 | message(STATUS " - local-task") |
| 169 | endif() |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 170 | if(IREE_HAL_DRIVER_VULKAN) |
| 171 | message(STATUS " - vulkan") |
| 172 | endif() |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 173 | if(IREE_EXTERNAL_HAL_DRIVERS) |
| 174 | message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}") |
| 175 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 176 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 177 | message(STATUS "IREE HAL local executable library loaders:") |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 178 | if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF) |
| 179 | message(STATUS " - embedded-elf") |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 180 | endif() |
| 181 | if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY) |
| 182 | message(STATUS " - system-library") |
| 183 | endif() |
| 184 | if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE) |
| 185 | message(STATUS " - vmvx-module") |
| 186 | endif() |
| 187 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 188 | #------------------------------------------------------------------------------- |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 189 | # Experimental ROCM HAL driver |
| 190 | #------------------------------------------------------------------------------- |
| 191 | |
| 192 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/experimental/rocm") |
| 193 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/experimental/rocm") |
| 194 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_TARGET "iree::experimental::rocm::registration") |
| 195 | set(IREE_EXTERNAL_ROCM_HAL_DRIVER_REGISTER "iree_hal_rocm_driver_module_register") |
| 196 | |
| 197 | #------------------------------------------------------------------------------- |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 198 | # Compiler Target Options |
| 199 | # By default, all compiler targets supported by the current platform which do |
| 200 | # not require external deps are enabled by default. This can be changed with: |
| 201 | # -DIREE_TARGET_BACKEND_DEFAULTS=OFF |
| 202 | #------------------------------------------------------------------------------- |
| 203 | |
| 204 | option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON) |
| 205 | |
| 206 | # The VMVX backend is always enabled. |
| 207 | cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF) |
| 208 | |
| 209 | # Supported default target backends. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 210 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 211 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU_WASM "Enables WebAssembly in the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_TARGET_BACKEND_LLVM_CPU} OFF) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 212 | cmake_dependent_option(IREE_TARGET_BACKEND_METAL_SPIRV "Enables the 'metal-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 213 | cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 214 | |
| 215 | # Non-default target backends either have additional dependencies or are |
| 216 | # experimental/niche in some fashion. |
| 217 | cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 218 | cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 219 | # Disable WebGPU by default - it has complex deps and is under development. |
| 220 | cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 221 | |
| 222 | #------------------------------------------------------------------------------- |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 223 | # Compiler Input Dialects |
| 224 | #------------------------------------------------------------------------------- |
| 225 | |
| 226 | cmake_dependent_option(IREE_INPUT_MHLO "Builds support for compiling MHLO programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 227 | cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 228 | cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 229 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 230 | if(IREE_BUILD_COMPILER) |
| 231 | message(STATUS "IREE compiler input dialects:") |
| 232 | if(IREE_INPUT_MHLO) |
| 233 | message(STATUS " - MHLO") |
| 234 | endif() |
| 235 | if(IREE_INPUT_TORCH) |
| 236 | message(STATUS " - Torch MLIR") |
| 237 | endif() |
| 238 | if(IREE_INPUT_TOSA) |
| 239 | message(STATUS " - TOSA") |
| 240 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 241 | endif() |
| 242 | |
| 243 | #------------------------------------------------------------------------------- |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 244 | # Compiler Output Formats |
| 245 | #------------------------------------------------------------------------------- |
| 246 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 247 | cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF) |
| 248 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 249 | if(IREE_BUILD_COMPILER) |
| 250 | message(STATUS "IREE compiler output formats:") |
| 251 | if(IREE_OUTPUT_FORMAT_C) |
| 252 | message(STATUS " - C source module") |
| 253 | endif() |
| 254 | # The 'vm-bytecode' and 'vm-asm' formats are always enabled. |
| 255 | message(STATUS " - VM Bytecode") |
| 256 | message(STATUS " - VM MLIR Assembly") |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 257 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 258 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 259 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 260 | # IREE compilation toolchain configuration |
| 261 | #------------------------------------------------------------------------------- |
| 262 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 263 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 264 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 265 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 266 | option(IREE_BYTECODE_MODULE_ENABLE_TSAN "Enable thread sanitizer in IREE modules in tests" OFF) |
Jakub Kuderski | 068b172 | 2022-07-27 18:14:59 -0400 | [diff] [blame] | 267 | option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 268 | |
| 269 | # STREQUAL feels wrong here - we don't care about the exact true-value used, |
| 270 | # ON or TRUE or something else. But we haven't been able to think of a less bad |
Scott Todd | 7df3973 | 2022-06-28 09:21:35 -0700 | [diff] [blame] | 271 | # alternative. https://github.com/iree-org/iree/pull/8474#discussion_r840790062 |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 272 | if(NOT IREE_ENABLE_TSAN STREQUAL IREE_BYTECODE_MODULE_ENABLE_TSAN) |
| 273 | message(SEND_ERROR |
| 274 | "IREE_ENABLE_TSAN and IREE_BYTECODE_MODULE_ENABLE_TSAN must be " |
| 275 | "simultaneously ON or OFF. " |
| 276 | "A discrepancy between the two would cause tests to crash as IREE " |
| 277 | "runtime code (controlled by IREE_ENABLE_TSAN) calls into test IREE " |
| 278 | "modules (controlled by IREE_BYTECODE_MODULE_ENABLE_TSAN)") |
| 279 | endif() |
| 280 | |
| 281 | if(IREE_BYTECODE_MODULE_ENABLE_TSAN) |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 282 | if(NOT IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 283 | message(SEND_ERROR |
| 284 | "When IREE_BYTECODE_MODULE_ENABLE_TSAN is ON, " |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 285 | "IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER must also be ON. " |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 286 | "TSAN instrumentation is not currently supported in embedded modules.") |
| 287 | endif() |
| 288 | endif() |
| 289 | |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 290 | option(IREE_ENABLE_CCACHE "Use ccache if installed to speed up rebuilds." OFF) |
| 291 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 292 | if(IREE_ENABLE_CCACHE) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 293 | find_program(CCACHE_PROGRAM ccache) |
| 294 | if(CCACHE_PROGRAM) |
| 295 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
| 296 | endif() |
| 297 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 298 | |
Geoffrey Martin-Noble | 3fa4f8d | 2021-09-10 09:25:27 -0700 | [diff] [blame] | 299 | 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] | 300 | |
| 301 | #------------------------------------------------------------------------------- |
| 302 | # IREE assertions |
| 303 | # We don't love the way this is done, but we have to line it up with how LLVM |
| 304 | # does it and not diverge, since all implementations and all header users must |
| 305 | # have the same definition of NDEBUG. |
| 306 | # |
| 307 | # LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then |
| 308 | # conditions itself to only update flags if not building Debug. We just let |
| 309 | # IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the |
| 310 | # flags in appropriate build types. |
| 311 | # |
| 312 | # If IREE_ENABLE_ASSERTIONS is set ON manually, then |
| 313 | # - NDEBUG must be undefined |
| 314 | # - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties |
| 315 | # from mucking with globals. |
| 316 | # |
| 317 | # Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done |
| 318 | # at the top level to avoid divergence. |
| 319 | #------------------------------------------------------------------------------- |
| 320 | |
| 321 | option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF) |
| 322 | |
| 323 | # Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if |
| 324 | # CMAKE_BUILD_TYPE is not Debug). |
| 325 | function(iree_fix_ndebug) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 326 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE) |
| 327 | if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 328 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 329 | foreach(_FLAGS_VAR_TO_SCRUB |
| 330 | CMAKE_CXX_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE} |
| 331 | CMAKE_C_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE}) |
| 332 | set(_ORIGINAL_FLAGS "${${_FLAGS_VAR_TO_SCRUB}}") |
| 333 | string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " _ALTERED_FLAGS "${_ORIGINAL_FLAGS}") |
| 334 | if(NOT "${_ORIGINAL_FLAGS}" STREQUAL "${_ALTERED_FLAGS}") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 335 | message(STATUS |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 336 | "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${_FLAGS_VAR_TO_SCRUB}: '${_ORIGINAL_FLAGS}' -> '${_ALTERED_FLAGS}'") |
| 337 | set(${_FLAGS_VAR_TO_SCRUB} "${_ALTERED_FLAGS}" PARENT_SCOPE) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 338 | endif() |
| 339 | endforeach() |
| 340 | |
| 341 | # Make sure that LLVM doesn't add its own logic for assertion disabling. |
| 342 | # We'd like to make sure that we are not dueling over globals. |
| 343 | set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE) |
| 344 | endif() |
| 345 | endfunction() |
| 346 | iree_fix_ndebug() |
| 347 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 348 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 349 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 350 | #------------------------------------------------------------------------------- |
| 351 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 352 | list(APPEND CMAKE_MODULE_PATH |
| 353 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 354 | ) |
| 355 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 356 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 357 | include(iree_copts) |
bjacob | c12ba3b | 2020-11-03 10:32:00 -0500 | [diff] [blame] | 358 | include(sanitizers) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 359 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 360 | include(iree_cc_library) |
| 361 | include(iree_cc_test) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 362 | include(iree_external_cmake_options) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 363 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 364 | include(iree_tablegen_doc) |
CindyLiu | 40ed02d | 2021-04-22 16:16:28 +0000 | [diff] [blame] | 365 | include(iree_c_embed_data) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 366 | include(iree_bytecode_module) |
Marius Brehler | 46e8331 | 2021-03-25 00:11:39 +0100 | [diff] [blame] | 367 | include(iree_c_module) |
Stella Laurenzo | 94363e2 | 2020-12-15 13:46:14 -0800 | [diff] [blame] | 368 | include(iree_python) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 369 | include(iree_lit_test) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 370 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 371 | include(iree_check_test) |
bjacob | 5feef48 | 2021-10-21 16:53:58 -0400 | [diff] [blame] | 372 | include(iree_trace_runner_test) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 373 | include(iree_native_test) |
Geoffrey Martin-Noble | 2811e50 | 2022-01-25 09:44:40 -0800 | [diff] [blame] | 374 | include(iree_cc_binary_benchmark) |
Geoffrey Martin-Noble | 66d4889 | 2021-10-29 12:24:58 -0700 | [diff] [blame] | 375 | include(iree_benchmark_suite) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 376 | include(iree_microbenchmark_suite) |
Scott Todd | 434ff0e | 2021-12-21 10:38:36 -0800 | [diff] [blame] | 377 | include(iree_hal_cts_test_suite) |
CindyLiu | ae72b95 | 2022-08-23 15:26:08 -0700 | [diff] [blame] | 378 | include(iree_static_linker_test) |
Jerry Wu | 116db87 | 2022-09-22 19:33:13 +0000 | [diff] [blame] | 379 | include(iree_fetch_artifact) |
CindyLiu | 080198f | 2022-10-06 07:21:17 -0700 | [diff] [blame^] | 380 | include(iree_run_module_test) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 381 | |
Marius Brehler | 06ac36e | 2020-01-10 14:44:11 -0800 | [diff] [blame] | 382 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 383 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 384 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 385 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 386 | #------------------------------------------------------------------------------- |
| 387 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 388 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 389 | 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] | 390 | |
| 391 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 392 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 393 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 394 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 395 | mark_as_advanced( |
| 396 | CMAKE_CXX_FLAGS_FASTBUILD |
| 397 | CMAKE_C_FLAGS_FASTBUILD |
| 398 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 399 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 400 | ) |
| 401 | |
Scott Todd | 7649dee | 2022-07-18 11:31:46 -0700 | [diff] [blame] | 402 | # Override the system's default linker. |
| 403 | # See also: https://llvm.org/docs/CMake.html#llvm-use-linker. |
| 404 | set(IREE_USE_LINKER "" CACHE STRING "") |
| 405 | # Equivalent to setting -DIREE_USE_LINKER=lld. |
| 406 | # Note that unlike LLVM's LLVM_ENABLE_LLD, this does _not_ build lld. You will |
| 407 | # need to either install a recent version of lld or build it from source prior |
| 408 | # to setting this option. See also: https://lld.llvm.org/#using-lld. |
| 409 | # This option is disabled on Apple platforms, where lld is not supported. |
| 410 | cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF) |
| 411 | |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 412 | include(iree_setup_toolchain) |
| 413 | |
| 414 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 415 | # Python |
| 416 | # If building features that require Python development, find them early in |
| 417 | # one invocation (some CMake versions are sensitive to resolving out of order). |
| 418 | # Otherwise, for features that just require the interpreter, find that alone. |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 419 | #------------------------------------------------------------------------------- |
| 420 | |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 421 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 422 | # After CMake 3.18, we are able to limit the scope of the search to just |
| 423 | # Development.Module. Searching for Development will fail in situations where |
| 424 | # the Python libraries are not available. When possible, limit to just |
| 425 | # Development.Module. |
| 426 | # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode |
Scott Todd | a24c8c5 | 2022-05-17 09:22:47 -0700 | [diff] [blame] | 427 | # |
| 428 | # Configuring the Development.Module is flaky in multi-project setups. |
| 429 | # "Bootstrapping" by first looking for the optional Development component |
| 430 | # seems to be robust generally. |
| 431 | # See: https://reviews.llvm.org/D118148 |
| 432 | find_package(Python3 COMPONENTS Interpreter Development) |
| 433 | find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 434 | elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 435 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
| 436 | endif() |
| 437 | |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 438 | # Extended Python environment checks. |
| 439 | if(Python3_FOUND) |
| 440 | iree_detect_pyyaml() |
| 441 | endif() |
| 442 | |
| 443 | if(IREE_BUILD_TESTS AND NOT IREE_PYYAML_FOUND) |
| 444 | message(WARNING "IREE's regression test suite requires PyYAML to run all tests. It is not installed, so some tests will be disabled.") |
| 445 | endif() |
| 446 | |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 447 | #------------------------------------------------------------------------------- |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 448 | # Check if git submodules have been initialized. |
| 449 | # This will only run if python3 is available. |
| 450 | #------------------------------------------------------------------------------- |
| 451 | |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 452 | option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON) |
| 453 | |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 454 | find_package(Python3 COMPONENTS Interpreter QUIET) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 455 | find_package(Git) |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 456 | if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 457 | # Only check submodule status when the git commit changes. |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 458 | execute_process( |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 459 | COMMAND git rev-parse --short HEAD |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 460 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 461 | RESULT_VARIABLE SHORT_HASH_RESULT |
| 462 | OUTPUT_VARIABLE SHORT_HASH) |
| 463 | string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}") |
Scott Todd | 2a8cd3b | 2021-12-13 11:58:44 -0800 | [diff] [blame] | 464 | 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] | 465 | execute_process( |
Stella Laurenzo | 41224d1 | 2022-04-21 18:20:06 -0700 | [diff] [blame] | 466 | COMMAND ${Python3_EXECUTABLE} build_tools/scripts/git/check_submodule_init.py |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 467 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 468 | RESULT_VARIABLE SUBMODULE_INIT_RESULT |
| 469 | ) |
| 470 | if(NOT SUBMODULE_INIT_RESULT EQUAL "0") |
| 471 | message(FATAL_ERROR "check_submodule_init.py failed, see the logs above") |
| 472 | else() |
| 473 | set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE) |
| 474 | endif() |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 475 | endif() |
| 476 | endif() |
| 477 | |
| 478 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 479 | # CUDA configuration for both the compiler and runtime. |
| 480 | # We do this at the top level so that we can fail fast and make global |
| 481 | # decisions that effect both compiler and runtime. It also helps with error |
| 482 | # messaging to do this all in one place, since we can provide very targeted |
| 483 | # advice. |
| 484 | #------------------------------------------------------------------------------- |
| 485 | |
| 486 | set(IREE_CUDA_LIBDEVICE_PATH "" CACHE STRING "Absolute path to an appropriate libdevice.*.bc (needed to build the IREE cuda compiler target)") |
| 487 | |
| 488 | # If any CUDA features are being built, try to locate a CUDA SDK. We will fall |
| 489 | # back to this as needed for specific features. |
| 490 | if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA) |
Stella Laurenzo | 5062ae3 | 2022-02-04 17:59:16 -0800 | [diff] [blame] | 491 | find_package(CUDAToolkit) |
Stella Laurenzo | 5943902 | 2022-04-12 21:04:26 -0700 | [diff] [blame] | 492 | |
Kojo Acquah | 719856b | 2022-06-15 18:35:02 -0400 | [diff] [blame] | 493 | if(NOT CUDAToolkit_FOUND) |
| 494 | if(DEFINED ENV{IREE_CUDA_DEPS_DIR}) |
| 495 | # We define the magic IREE_CUDA_DEPS_DIR env var in our CI docker images if we |
| 496 | # have a stripped down CUDA toolkit suitable for compiling available. We |
| 497 | # trigger on this below as a fallback for locating headers and libdevice |
| 498 | # files. |
| 499 | set(CUDAToolkit_ROOT "$ENV{IREE_CUDA_DEPS_DIR}") |
| 500 | message(STATUS "CUDA SDK not found by CMake but using IREE_CUDA_DEPS = ${CUDAToolkit_ROOT}") |
| 501 | else() |
| 502 | # If we haven't found CUDA deps, download at least enough to build for CUDA. |
| 503 | # This will define IREE_CUDA_DOWNLOAD_LIBDEVICE_PATH & IREE_CUDA_DOWNLOAD_INCLUDE_PATH |
| 504 | # vars with the target deps. |
| 505 | message(STATUS "CUDA SDK not found by CMake but downloading dependencies") |
| 506 | add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL) |
| 507 | endif() |
Stella Laurenzo | 5943902 | 2022-04-12 21:04:26 -0700 | [diff] [blame] | 508 | endif() |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 509 | endif() |
| 510 | |
| 511 | # If an explicit libdevice file was not specified, and the compiler backend |
| 512 | # is being built, probe for one. |
| 513 | if(IREE_TARGET_BACKEND_CUDA) |
Stella Laurenzo | 9fd5b5d | 2022-02-14 17:07:28 -0800 | [diff] [blame] | 514 | if(IREE_CUDA_LIBDEVICE_PATH) |
| 515 | # Explicitly provided: do nothing. |
| 516 | elseif(CUDAToolkit_FOUND AND CUDAToolkit_LIBRARY_ROOT) |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 517 | # Note that the variable CUDAToolkit_LIBRARY_ROOT keys off of the presence |
| 518 | # of version.txt, which was changed to version.json in recent releases |
| 519 | # and thwarts the search. |
| 520 | set(IREE_CUDA_LIBDEVICE_PATH "${CUDAToolkit_LIBRARY_ROOT}/nvvm/libdevice/libdevice.10.bc") |
| 521 | elseif(CUDAToolkit_FOUND AND CUDAToolkit_BIN_DIR) |
| 522 | # Back-track from the bin dir as a fallback. |
| 523 | set(IREE_CUDA_LIBDEVICE_PATH "${CUDAToolkit_BIN_DIR}/../nvvm/libdevice/libdevice.10.bc") |
Stella Laurenzo | 5062ae3 | 2022-02-04 17:59:16 -0800 | [diff] [blame] | 524 | elseif(CUDAToolkit_ROOT) |
| 525 | # Sometimes the CUDA toolkit doesn't detect... because, you know. Computers |
| 526 | # are hard and such. In this case, if the user went to the trouble to |
| 527 | # tell us where it is, we have enough information. |
| 528 | set(IREE_CUDA_LIBDEVICE_PATH "${CUDAToolkit_ROOT}/nvvm/libdevice/libdevice.10.bc") |
Kojo Acquah | 719856b | 2022-06-15 18:35:02 -0400 | [diff] [blame] | 529 | elseif(IREE_CUDA_DOWNLOAD_LIBDEVICE_PATH) |
| 530 | message(STATUS "Using downloaded CUDA libdevice") |
| 531 | set(IREE_CUDA_LIBDEVICE_PATH "${IREE_CUDA_DOWNLOAD_LIBDEVICE_PATH}") |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 532 | else() |
| 533 | message(FATAL_ERROR "Building with IREE_TARGET_BACKEND_CUDA requires either a CUDA SDK (consult CMake docs for your version: https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html) or an explicit path to libdevice (set with -DIREE_CUDA_LIBDEVICE_PATH=/path/to/libdevice.10.bc)") |
| 534 | endif() |
| 535 | |
| 536 | if(EXISTS "${IREE_CUDA_LIBDEVICE_PATH}") |
| 537 | message(STATUS "Using CUDA libdevice: ${IREE_CUDA_LIBDEVICE_PATH}") |
| 538 | else() |
| 539 | message(SEND_ERROR "Cannot find CUDA libdevice file (${IREE_CUDA_LIBDEVICE_PATH}). Either configure your CUDA SDK such that it can be found or specify explicitly via -DIREE_CUDA_LIBDEVICE_PATH=/path/to/libdevice.10.bc") |
| 540 | endif() |
| 541 | endif() |
| 542 | |
Stella Laurenzo | 5062ae3 | 2022-02-04 17:59:16 -0800 | [diff] [blame] | 543 | if(IREE_HAL_DRIVER_CUDA) |
| 544 | if(CUDAToolkit_FOUND) |
| 545 | message(STATUS "Using CUDA INCLUDE_DIRS from found SDK: ${CUDAToolkit_INCLUDE_DIRS}") |
| 546 | elseif(CUDAToolkit_ROOT) |
| 547 | # See note above about computers being hard. |
| 548 | # We make minimal use of CUDA for the runtime and really just need cuda.h |
| 549 | # presently. So let's make a guess at that. |
| 550 | set(CUDAToolkit_INCLUDE_DIRS "${CUDAToolkit_ROOT}/include") |
| 551 | if(EXISTS "${CUDAToolkit_INCLUDE_DIRS}/cuda.h") |
| 552 | message(STATUS "Using CUDA INCLUDE_DIRS from CUDAToolkit_ROOT: ${CUDAToolkit_INCLUDE_DIRS}") |
| 553 | else() |
| 554 | message(SEND_ERROR "Using explicitly specified CUDAToolkit_ROOT, could not find cuda.h at: ${CUDAToolkit_INCLUDE_DIRS}") |
| 555 | endif() |
Kojo Acquah | 719856b | 2022-06-15 18:35:02 -0400 | [diff] [blame] | 556 | elseif(IREE_CUDA_DOWNLOAD_INCLUDE_PATH) |
| 557 | message(STATUS "Using downloaded CUDA includes") |
| 558 | set(CUDAToolkit_INCLUDE_DIRS "${IREE_CUDA_DOWNLOAD_INCLUDE_PATH}") |
Stella Laurenzo | 5062ae3 | 2022-02-04 17:59:16 -0800 | [diff] [blame] | 559 | else() |
| 560 | message(SEND_ERROR "Cannot build IREE runtime CUDA components (-DIREE_HAL_DRIVER_CUDA=ON) because a CUDA SDK was not found. Consult CMake docs for your version: https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html") |
| 561 | endif() |
Stella Laurenzo | 9838866 | 2022-02-03 15:37:30 -0800 | [diff] [blame] | 562 | endif() |
| 563 | |
| 564 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 565 | # MLIR/LLVM Dependency |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 566 | #------------------------------------------------------------------------------- |
| 567 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 568 | if(NOT IREE_BUILD_COMPILER) |
| 569 | message(STATUS "Not adding LLVM/MLIR because the configuration does not require it") |
| 570 | elseif(TARGET LLVMSupport) |
| 571 | message(STATUS "Not adding IREE bundled LLVM because it has already been included") |
| 572 | if(NOT TARGET MLIRIR) |
| 573 | 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] | 574 | endif() |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 575 | else() |
| 576 | message(STATUS "Adding bundled LLVM source dependency") |
| 577 | iree_set_llvm_cmake_options() |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 578 | |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 579 | # Enable MLIR Python bindings if IREE Python bindings enabled. |
| 580 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 581 | set(MLIR_ENABLE_BINDINGS_PYTHON ON) |
| 582 | set(MHLO_ENABLE_BINDINGS_PYTHON ON) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 583 | endif() |
| 584 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 585 | # Disable LLVM's warnings. |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 586 | set(LLVM_ENABLE_WARNINGS OFF) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 587 | |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 588 | # Stash cmake build type in case LLVM messes with it. |
| 589 | set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}") |
| 590 | |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 591 | # Add default external projects. |
Stella Laurenzo | 02230c1 | 2021-08-10 03:58:42 +0000 | [diff] [blame] | 592 | 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] | 593 | iree_add_llvm_external_project(mlir-hlo MLIR_HLO ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mlir-hlo) |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 594 | if(IREE_INPUT_TORCH) |
Yi Zhang | c35fee8 | 2022-04-06 14:35:28 -0400 | [diff] [blame] | 595 | iree_add_llvm_external_project(torch-mlir-dialects TORCH_MLIR_DIALECTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/torch-mlir-dialects) |
| 596 | endif() |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 597 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 598 | add_subdirectory("third_party/llvm-project/llvm" EXCLUDE_FROM_ALL) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 599 | |
Ben Vanik | 89a77fa | 2020-10-07 17:19:31 -0700 | [diff] [blame] | 600 | # Reset CMAKE_BUILD_TYPE to its previous setting. |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 601 | set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" ) |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 602 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 603 | # Extend module path to allow submodules to use LLVM and MLIR CMake modules. |
| 604 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/mlir") |
| 605 | 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] | 606 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 607 | # Add the bundled include directories for cmake files looking for them. |
| 608 | list(APPEND LLVM_INCLUDE_DIRS |
| 609 | ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/llvm/include |
| 610 | ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/include |
| 611 | ) |
| 612 | list(APPEND MLIR_INCLUDE_DIRS |
| 613 | ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/mlir/include |
| 614 | ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include |
| 615 | ) |
Marius Brehler | 71f76cb | 2020-11-10 20:56:55 +0100 | [diff] [blame] | 616 | |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 617 | # TODO: It should be possible to fix upstream targets so as to not require |
| 618 | # any of these. Remove as they become unnecessary. |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 619 | function(_hack_llvm_include_paths) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 620 | set(_COMMON_INCLUDE_DIRS |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 621 | # LLVM |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 622 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/llvm/include> |
| 623 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/include> |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 624 | |
| 625 | # MLIR |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 626 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/mlir/include> |
| 627 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include> |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 628 | |
| 629 | # LLD |
| 630 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/lld/include> |
| 631 | $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/lld/include> |
| 632 | |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 633 | ) |
| 634 | # Avoid globally modifying paths by instead adding the include paths to the |
| 635 | # rules that really should have them in the first place. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 636 | target_include_directories(LLVMSupport PUBLIC ${_COMMON_INCLUDE_DIRS}) |
| 637 | target_include_directories(MLIRSupport PUBLIC ${_COMMON_INCLUDE_DIRS}) |
Stella Laurenzo | 62fbef0 | 2021-08-09 20:52:48 -0700 | [diff] [blame] | 638 | endfunction() |
| 639 | _hack_llvm_include_paths() |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 640 | endif() |
| 641 | |
Stella Laurenzo | 382122d | 2020-06-11 16:18:09 -0700 | [diff] [blame] | 642 | #------------------------------------------------------------------------------- |
Scott Todd | 8b0b0cd | 2021-12-16 15:13:57 -0800 | [diff] [blame] | 643 | # Other dependencies |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 644 | #------------------------------------------------------------------------------- |
| 645 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 646 | include(external_cc_library) |
Ben Vanik | 2d1808b | 2020-07-17 19:02:16 -0700 | [diff] [blame] | 647 | include(flatbuffer_c_library) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 648 | |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 649 | add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL) |
Jerry Wu | ae05f30 | 2022-05-17 13:58:13 +0000 | [diff] [blame] | 650 | add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL) |
Ben Vanik | a903649 | 2021-06-25 09:39:53 -0700 | [diff] [blame] | 651 | add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 652 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 653 | iree_set_googletest_cmake_options() |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 654 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 655 | |
| 656 | if(IREE_ENABLE_THREADING) |
| 657 | iree_set_benchmark_cmake_options() |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 658 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 659 | if(IREE_ENABLE_CPUINFO) |
| 660 | iree_set_cpuinfo_cmake_options() |
| 661 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
| 662 | endif() |
Cindy Liu | 331946c | 2021-06-01 12:20:30 -0700 | [diff] [blame] | 663 | endif() |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 664 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 665 | add_subdirectory(build_tools/third_party/flatcc EXCLUDE_FROM_ALL) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 666 | |
Marius Brehler | 9b86ad5 | 2022-06-08 17:09:02 +0200 | [diff] [blame] | 667 | if(IREE_HAL_DRIVER_VULKAN) |
| 668 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
| 669 | endif() |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 670 | |
Scott Todd | 4e1a69b | 2021-01-25 15:29:49 -0800 | [diff] [blame] | 671 | # TODO(scotttodd): Iterate some more and find a better place for this. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 672 | if(NOT CMAKE_CROSSCOMPILING) |
Ben Vanik | 6874719 | 2021-10-26 20:38:45 -0700 | [diff] [blame] | 673 | install( |
| 674 | TARGETS iree-flatcc-cli |
| 675 | COMPONENT iree-flatcc-cli |
| 676 | RUNTIME DESTINATION bin |
| 677 | ) |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 678 | endif() |
| 679 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 680 | if(IREE_BUILD_COMPILER) |
Marius Brehler | 3eaf444 | 2021-01-13 18:22:08 +0100 | [diff] [blame] | 681 | add_subdirectory(build_tools/third_party/mlir-hlo EXCLUDE_FROM_ALL) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 682 | endif() |
| 683 | |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 684 | if(IREE_BUILD_TESTS) |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 685 | include(iree_configure_testing) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 686 | endif() |
| 687 | |
MaheshRavishankar | 1547ac2 | 2021-09-23 15:22:46 -0700 | [diff] [blame] | 688 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 95ad84c | 2021-09-24 14:56:01 -0700 | [diff] [blame] | 689 | if(NOT TARGET pybind11::module) |
| 690 | message(STATUS "Using bundled pybind11") |
| 691 | add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL) |
| 692 | else() |
| 693 | message(STATUS "Not including bundled pybind11 (already configured)") |
| 694 | endif() |
Marius Brehler | f3d73c9 | 2020-01-16 16:11:52 -0800 | [diff] [blame] | 695 | endif() |
| 696 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 697 | if(IREE_TARGET_BACKEND_METAL_SPIRV) |
Stella Laurenzo | 275215d | 2021-08-06 11:50:28 -0700 | [diff] [blame] | 698 | iree_set_spirv_cross_cmake_options() |
Lei Zhang | 3cbb28e | 2020-09-22 15:30:27 -0400 | [diff] [blame] | 699 | # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code. |
| 700 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 701 | endif() |
| 702 | |
Scott Todd | f8519ca | 2021-12-16 16:01:49 -0800 | [diff] [blame] | 703 | if(IREE_TARGET_BACKEND_WEBGPU) |
| 704 | # Tint is needed to compile SPIR-V into WGSL source code. |
| 705 | # Tint also requires SPIRV-Tools, which requires SPIRV-Headers. |
| 706 | iree_set_spirv_headers_cmake_options() |
| 707 | add_subdirectory(third_party/spirv_headers EXCLUDE_FROM_ALL) |
| 708 | add_subdirectory(build_tools/third_party/spirv-tools EXCLUDE_FROM_ALL) |
| 709 | add_subdirectory(build_tools/third_party/tint EXCLUDE_FROM_ALL) |
| 710 | endif() |
| 711 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 712 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 713 | # IREE top-level targets |
| 714 | #------------------------------------------------------------------------------- |
| 715 | |
Jerry Wu | 5263dde | 2022-09-21 11:30:35 -0700 | [diff] [blame] | 716 | if(IREE_BUILD_BENCHMARKS OR IREE_BUILD_EXPERIMENTAL_PYTHON_GENERATED_BENCHMARKS) |
Scott Todd | 9ca7563 | 2022-04-13 10:47:11 -0700 | [diff] [blame] | 717 | # Add top-level custom targets to drive generating benchmark suites. |
| 718 | |
| 719 | # iree-benchmark-import-models imports benchmark models from their source |
| 720 | # formats, such as .tflite flatbuffers, to IREE-compatible .mlir files. |
| 721 | add_custom_target(iree-benchmark-import-models) |
| 722 | |
| 723 | # iree-benchmark-suites fully prepares benchmark models for benchmarking: |
| 724 | # * importing from source formats to IREE-compatible .mlir files |
| 725 | # * compiling from .mlir files to benchmark-ready .vmfb files |
| 726 | # * generating flagfiles for executing the benchmark .vmfb files |
Lei Zhang | fe4403e | 2021-06-01 15:09:43 -0400 | [diff] [blame] | 727 | add_custom_target(iree-benchmark-suites) |
| 728 | endif() |
| 729 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 730 | if(IREE_BUILD_MICROBENCHMARKS) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 731 | # Add top-level custom targets to drive generating microbenchmark suites. |
| 732 | add_custom_target(iree-microbenchmark-suites) |
| 733 | endif() |
| 734 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 735 | if(IREE_BUILD_DOCS) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 736 | # Add a top-level custom target to drive generating all documentation. |
| 737 | # Register it to the default target given that IREE_BUILD_DOCS is explicitly |
| 738 | # requested. |
| 739 | add_custom_target(iree-doc ALL) |
| 740 | endif() |
| 741 | |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 742 | # Testing rules that require generation will add dependencies to this target. |
| 743 | # This allows them to be EXCLUDE_FROM_ALL but still invokable. |
| 744 | add_custom_target(iree-test-deps COMMENT "Building IREE test deps") |
| 745 | |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 746 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 747 | # IREE top-level libraries |
| 748 | #------------------------------------------------------------------------------- |
| 749 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 750 | if(IREE_ENABLE_CLANG_TIDY) |
| 751 | set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*) |
| 752 | endif() |
| 753 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 754 | add_subdirectory(build_tools/embed_data/) |
| 755 | |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 756 | # Note: Test deps are not built as part of all (use the iree-test-deps target). |
Scott Todd | 748bcd2 | 2022-05-25 12:18:40 -0700 | [diff] [blame] | 757 | add_subdirectory(tests EXCLUDE_FROM_ALL) |
Lei Zhang | ff38a68 | 2021-06-08 21:12:24 -0400 | [diff] [blame] | 758 | |
Jerry Wu | 5263dde | 2022-09-21 11:30:35 -0700 | [diff] [blame] | 759 | if(IREE_BUILD_BENCHMARKS OR IREE_BUILD_EXPERIMENTAL_PYTHON_GENERATED_BENCHMARKS) |
Stella Laurenzo | a6bf65c | 2022-01-11 20:47:51 -0800 | [diff] [blame] | 760 | find_program(IREE_IMPORT_TFLITE_PATH iree-import-tflite) |
| 761 | if(IREE_IMPORT_TFLITE_PATH) |
| 762 | message(STATUS "Found ${IREE_IMPORT_TFLITE_PATH} to generate benchmark artifacts") |
| 763 | else() |
| 764 | message(STATUS "iree-import-tflite not found. Some benchmarks may not configure") |
| 765 | endif() |
Jerry Wu | 60798ca | 2022-06-21 23:36:40 +0000 | [diff] [blame] | 766 | find_program(IREE_IMPORT_TF_PATH iree-import-tf) |
| 767 | if(IREE_IMPORT_TF_PATH) |
| 768 | message(STATUS "Found ${IREE_IMPORT_TF_PATH} to generate benchmark artifacts") |
| 769 | else() |
| 770 | message(STATUS "iree-import-tf not found. Some benchmarks may not configure") |
| 771 | endif() |
Lei Zhang | 08cea04 | 2021-07-20 12:44:01 -0400 | [diff] [blame] | 772 | add_subdirectory(benchmarks) |
Lei Zhang | ff38a68 | 2021-06-08 21:12:24 -0400 | [diff] [blame] | 773 | endif() |
| 774 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 775 | if(IREE_BUILD_COMPILER) |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 776 | add_subdirectory(compiler) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 777 | endif() |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 778 | |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 779 | add_subdirectory(runtime) |
| 780 | |
Scott Todd | 4c022df | 2022-05-10 16:55:18 -0700 | [diff] [blame] | 781 | # tools/ can depend on compiler/ and runtime/ |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 782 | add_subdirectory(tools) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 783 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 784 | |
| 785 | if(IREE_ENABLE_CLANG_TIDY) |
| 786 | set(CMAKE_CXX_CLANG_TIDY "") |
| 787 | endif() |
| 788 | |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 789 | if(IREE_BUILD_TRACY) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 790 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux") |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 791 | message(WARNING "Building Tracy (IREE_BUILD_TRACY) on non-Linux is unsupported and may fail below.") |
| 792 | endif() |
| 793 | add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy) |
| 794 | if(NOT TARGET IREETracyCaptureServer) |
| 795 | message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.") |
| 796 | endif() |
| 797 | endif() |
| 798 | |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 799 | # Order constraint: The python bindings install tools targets from tools/ |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 800 | # and tracy, and must come after it. |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 801 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 802 | # Write out a .env file to make IDEs and developers happy. |
| 803 | # Yes, we are writing this to the source dir. It is only for IDEs and if |
| 804 | # it gets clobbered, it is fine. |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 805 | set(_PYTHONPATH_ENV "PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 806 | file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 807 | CONTENT "${_PYTHONPATH_ENV}" |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 808 | ) |
| 809 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 810 | CONTENT "${_PYTHONPATH_ENV}" |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 811 | ) |
Stella Laurenzo | 77a63cd | 2021-01-04 17:29:54 -0800 | [diff] [blame] | 812 | endif() |
| 813 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 814 | if(IREE_BUILD_BINDINGS_TFLITE) |
Scott Todd | ada25e6 | 2022-05-03 16:16:15 -0700 | [diff] [blame] | 815 | add_subdirectory(runtime/bindings/tflite) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 816 | endif() |
| 817 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 818 | if(IREE_BUILD_EXPERIMENTAL_REMOTING) |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 819 | # NOTE: Currently liburing is only used by the experimental remoting |
| 820 | # support, so keeping it scoped here. If this broadens, then include along |
| 821 | # with other dependencies as normal. |
| 822 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") |
| 823 | message(STATUS "Enabling liburing") |
| 824 | add_subdirectory(build_tools/third_party/liburing EXCLUDE_FROM_ALL) |
| 825 | endif() |
| 826 | add_subdirectory(experimental/remoting) |
Ben Vanik | b64e918 | 2020-01-30 15:19:37 -0800 | [diff] [blame] | 827 | endif() |
Scott Todd | ee30e1b | 2020-02-03 16:44:15 -0800 | [diff] [blame] | 828 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 829 | if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES) |
Scott Todd | 15fce0a | 2022-02-14 12:43:23 -0800 | [diff] [blame] | 830 | add_subdirectory(experimental/web) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 831 | endif() |
| 832 | |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 833 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 834 | CACHE INTERNAL "IREE: Include Directories" FORCE) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 835 | |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 836 | #------------------------------------------------------------------------------- |
| 837 | # IREE benchmark tools |
| 838 | #------------------------------------------------------------------------------- |
| 839 | |
| 840 | add_subdirectory(build_tools/benchmarks) |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 841 | |
| 842 | #------------------------------------------------------------------------------- |
Jerry Wu | 71562cc | 2022-09-20 18:56:41 -0700 | [diff] [blame] | 843 | # IREE build tools python modules |
| 844 | #------------------------------------------------------------------------------- |
| 845 | |
| 846 | add_subdirectory(build_tools/python) |
| 847 | |
| 848 | #------------------------------------------------------------------------------- |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 849 | # Samples |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 850 | #------------------------------------------------------------------------------- |
| 851 | |
Scott Todd | 4c022df | 2022-05-10 16:55:18 -0700 | [diff] [blame] | 852 | # samples/ can depend on anything, so we include it last |
Stella Laurenzo | 1e8d1fa | 2022-04-22 09:50:43 -0700 | [diff] [blame] | 853 | if(IREE_BUILD_SAMPLES) |
| 854 | add_subdirectory(samples) |
| 855 | endif() |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 856 | |
| 857 | if(IREE_BUILD_TESTS) |
| 858 | iree_create_ctest_customization() |
| 859 | endif() |