Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2019 The IREE Authors |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 2 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 6 | |
Geoffrey Martin-Noble | 4fd7a1d | 2022-11-17 15:09:49 -0800 | [diff] [blame] | 7 | cmake_minimum_required(VERSION 3.21...3.24) |
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) |
Ben Vanik | a49a5f5 | 2023-02-21 12:19:17 -0800 | [diff] [blame] | 13 | if(POLICY CMP0116) |
| 14 | cmake_policy(SET CMP0116 OLD) |
| 15 | endif() |
Ben Vanik | 552c5f4 | 2021-06-21 17:39:14 -0700 | [diff] [blame] | 16 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 17 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 18 | |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 19 | project(IREE ASM C CXX) |
Lei Zhang | 6c5907b | 2020-06-02 09:06:08 -0700 | [diff] [blame] | 20 | set(CMAKE_C_STANDARD 11) |
Scott Todd | 07349fa | 2022-07-27 12:16:05 -0700 | [diff] [blame] | 21 | set(CMAKE_CXX_STANDARD 17) |
Stella Laurenzo | bc09f0e | 2022-07-27 16:22:39 -0700 | [diff] [blame] | 22 | # LLVM defines this as a CACHE property and uses a policy that causes the |
| 23 | # cache value to take precedence. This is causing us to mix 17/14 across |
| 24 | # the boundary. |
| 25 | # TODO: Remove this once the LLVM mechanism is updated. See: |
| 26 | # 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 |
| 27 | 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] | 28 | set(IREE_IDE_FOLDER IREE) |
| 29 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 30 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 31 | if(MSVC) |
Ben Vanik | 96fd277 | 2021-04-19 20:30:56 -0700 | [diff] [blame] | 32 | enable_language(ASM_MASM) |
| 33 | else() |
| 34 | enable_language(ASM) |
| 35 | endif() |
| 36 | |
Cindy Liu | b1bfb9c | 2022-06-27 10:46:13 -0700 | [diff] [blame] | 37 | # Set the default CMake build type so some of the build type dependent setting |
| 38 | # in the submodules and functions (IREE assertion) can be set properly. |
Cindy Liu | 23dafd0 | 2022-06-22 15:36:21 -0700 | [diff] [blame] | 39 | set(DEFAULT_CMAKE_BUILD_TYPE "Release") |
| 40 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 41 | message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}") |
| 42 | set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE) |
| 43 | endif() |
| 44 | |
Scott Todd | 99e9f5b | 2021-12-30 10:56:12 -0800 | [diff] [blame] | 45 | include(CMakeDependentOption) |
| 46 | |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 47 | #------------------------------------------------------------------------------- |
| 48 | # Project component configuration |
| 49 | #------------------------------------------------------------------------------- |
| 50 | |
Ben Vanik | 56d44bf | 2020-05-15 13:20:50 -0700 | [diff] [blame] | 51 | option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF) |
Scott Todd | 1cd9f0a | 2021-07-29 10:05:44 -0700 | [diff] [blame] | 52 | option(IREE_ENABLE_COMPILER_TRACING "Enables instrumented compiler tracing." OFF) |
Ben Vanik | 2d79c20 | 2022-10-24 15:08:57 -0700 | [diff] [blame] | 53 | option(IREE_ENABLE_RENDERDOC_PROFILING "Enables profiling HAL devices with the RenderDoc tool." OFF) |
Geoffrey Martin-Noble | fe74bd4 | 2021-10-27 22:17:13 -0700 | [diff] [blame] | 54 | option(IREE_ENABLE_THREADING "Builds IREE in with thread library support." ON) |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 55 | 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] | 56 | |
Ben Vanik | 7ed4f4b | 2023-06-14 13:33:54 -0700 | [diff] [blame] | 57 | set(IREE_TRACING_PROVIDER_DEFAULT "tracy" CACHE STRING "Default tracing implementation.") |
| 58 | set(IREE_TRACING_PROVIDER ${IREE_TRACING_PROVIDER_DEFAULT} CACHE STRING "Chooses which built-in tracing implementation is used when tracing is enabled.") |
| 59 | set(IREE_TRACING_PROVIDER_H "" CACHE STRING "Header file for custom tracing providers.") |
| 60 | set(IREE_TRACING_MODE_DEFAULT "2" CACHE STRING "Default tracing feature/verbosity mode. See iree/base/tracing.h for more.") |
| 61 | set(IREE_TRACING_MODE ${IREE_TRACING_MODE_DEFAULT} CACHE STRING "Tracing feature/verbosity mode. See iree/base/tracing.h for more.") |
| 62 | |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 63 | # TODO(#8469): remove the dependency on cpuinfo entirely. |
Ben Vanik | cbe93c0 | 2023-08-08 10:12:08 -0700 | [diff] [blame] | 64 | set(IREE_ENABLE_CPUINFO_DEFAULT ON) |
Ben Vanik | 62c4f98 | 2023-12-12 18:01:52 -0800 | [diff] [blame] | 65 | if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Emscripten|Windows|WindowsStore") |
Ben Vanik | cbe93c0 | 2023-08-08 10:12:08 -0700 | [diff] [blame] | 66 | set(IREE_ENABLE_CPUINFO_DEFAULT OFF) |
| 67 | endif() |
| 68 | option(IREE_ENABLE_CPUINFO "Enables runtime use of cpuinfo for processor topology detection." ${IREE_ENABLE_CPUINFO_DEFAULT}) |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 69 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 70 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 71 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Scott Todd | 96d9213 | 2023-06-12 15:45:19 -0700 | [diff] [blame] | 72 | option(IREE_BUILD_DOCS "Builds IREE documentation files." OFF) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 73 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 74 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF) |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 75 | option(IREE_BUILD_TRACY "Builds tracy server tools." OFF) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 76 | option(IREE_BUILD_BUNDLED_LLVM "Builds the bundled llvm-project (vs using installed)" ON) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 77 | |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 78 | 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] | 79 | |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 80 | # Properties controlling version and naming of release artifacts. |
Stella Laurenzo | f33f5b5 | 2022-01-08 17:49:52 +0000 | [diff] [blame] | 81 | 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] | 82 | set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages") |
| 83 | set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages") |
Jacques Pienaar | 27779b2 | 2022-12-22 15:37:56 -0800 | [diff] [blame] | 84 | option(IREE_EMBED_RELEASE_INFO "Embed the IREE version information in built artifacts." OFF) |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 85 | |
Scott Todd | de426de | 2023-01-13 08:26:02 -0800 | [diff] [blame] | 86 | # Using already built host binaries, such as for cross-compilation. |
| 87 | set(IREE_HOST_BIN_DIR_DEFAULT "") |
| 88 | if(IREE_HOST_BINARY_ROOT) |
| 89 | message(WARNING "IREE_HOST_BINARY_ROOT is deprecated. Use IREE_HOST_BIN_DIR" |
| 90 | " pointing directly to the directory containing binaries" |
| 91 | " instead.") |
| 92 | set(IREE_HOST_BIN_DIR_DEFAULT "${IREE_HOST_BINARY_ROOT}/bin") |
| 93 | endif() |
| 94 | set(IREE_HOST_BIN_DIR "${IREE_HOST_BIN_DIR_DEFAULT}" CACHE STRING "Path to directory containing IREE binary tools to use instead of building them from source.") |
| 95 | |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 96 | 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] | 97 | 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] | 98 | |
Jerry Wu | b6b1dee | 2022-06-01 13:45:16 +0000 | [diff] [blame] | 99 | option(IREE_BUILD_MICROBENCHMARKS "Builds IREE microbenchmark suites." OFF) |
| 100 | |
Jerry Wu | 5740497 | 2023-03-02 22:16:11 +0000 | [diff] [blame] | 101 | option(IREE_BUILD_E2E_TEST_ARTIFACTS "Builds IREE E2E test artifacts suite generated by the e2e test framework." "${IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS}") |
Jerry Wu | fed372c | 2023-10-19 12:05:32 -0700 | [diff] [blame] | 102 | set(IREE_E2E_TEST_ARTIFACTS_DIR "" CACHE STRING "Set external prebuilt E2E test artifacts directory") |
| 103 | if(IREE_BUILD_E2E_TEST_ARTIFACTS AND NOT "${IREE_E2E_TEST_ARTIFACTS_DIR}" STREQUAL "") |
| 104 | message(SEND_ERROR |
| 105 | "IREE_E2E_TEST_ARTIFACTS_DIR and IREE_BUILD_E2E_TEST_ARTIFACTS can't be" |
| 106 | " set at the same time." |
| 107 | ) |
| 108 | endif() |
| 109 | |
Boian Petkantchin | d4e3968 | 2023-07-31 10:09:16 -0700 | [diff] [blame] | 110 | option(IREE_ENABLE_COLLECTIVE_RUNTIME_TESTS "Enable runtime tests for collective operations." OFF) |
Jerry Wu | 5740497 | 2023-03-02 22:16:11 +0000 | [diff] [blame] | 111 | |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 112 | # For development, builds LLVM (and in the future) the whole compiler as |
| 113 | # individual shared libraries similar to if passing -DBUILD_SHARED_LIBS=ON |
| 114 | # to a standalone LLVM build. This can dramatically reduce linking time and |
| 115 | # makes the management of some dependencies more strict. |
| 116 | # This option is considered experimental and should not be relied on until |
| 117 | # CI coverage is established. |
| 118 | option(IREE_COMPILER_BUILD_SHARED_LIBS "Enables BUILD_SHARED_LIBS CMake mode for LLVM and the compiler (this is only suitable for development)" OFF) |
| 119 | |
| 120 | # Must be defined as an option (CMake does not do it automatically), even though |
| 121 | # we override it for different parts of the tree. |
| 122 | # This option is considered experimental and should not be relied on until |
| 123 | # CI coverage is established. |
| 124 | option(BUILD_SHARED_LIBS "Instructs CMake to build libraries as shared if possible" OFF) |
| 125 | |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 126 | #------------------------------------------------------------------------------- |
Ben Vanik | 5363ea3 | 2023-05-02 15:47:58 -0700 | [diff] [blame] | 127 | # IREE command-line tooling configuration |
| 128 | #------------------------------------------------------------------------------- |
| 129 | |
| 130 | # External user modules linked into IREE tooling (iree-run-module/etc). |
| 131 | # These are only available in the internal IREE tools and here for testing |
| 132 | # custom modules in standard workflows. This is not a deployment mechanism and |
| 133 | # users integrating IREE into their libraries or applications will need to |
| 134 | # manage the building and registering/resolving the modules themselves. |
| 135 | # |
| 136 | # See runtime/src/iree/tooling/modules/CMakeLists.txt for more information on |
| 137 | # how to declare external modules. |
| 138 | set(IREE_EXTERNAL_TOOLING_MODULES "" CACHE STRING "") |
| 139 | |
| 140 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 141 | # IREE out of tree plugins |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 142 | # |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 143 | # IREE has multiple facilities for building with out of tree plugin sources. |
| 144 | # The entry-point is via the -DIREE_CMAKE_PLUGIN_PATHS=<dir1;dir2> setting. |
| 145 | # Each directory in this list can have any of the following files in it, which |
| 146 | # will be included at the appropriate point in the CMake build: |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 147 | # |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 148 | # iree_compiler_plugin.cmake : Included in the context of the compiler/ |
| 149 | # directory before sources and bindings. Will execute with source and |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 150 | # binary dir ${IREE_BUILD_DIR}/compiler/plugins (shared with all other |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 151 | # dirs). |
| 152 | # iree_runtime_plugin.cmake : Included in the context of the runtime/ |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 153 | # directory before sources. Will execute with source and binary dir |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 154 | # ${IREE_BUILD_DIR}/runtime/plugins (shared with all other dirs). |
| 155 | # |
| 156 | # Typically, these plugins will perform additional project setup, and |
| 157 | # eventually call registration functions to advertise additional capabilities |
| 158 | # to the build system. |
| 159 | # |
| 160 | # Super-projects can populate the list IREE_CMAKE_BUILTIN_PLUGIN_PATHS to |
Stella Laurenzo | 62a7f35 | 2023-07-10 17:59:15 -0700 | [diff] [blame] | 161 | # statically configure more plugin directories to be used. |
| 162 | # |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 163 | # Compiler Plugins |
| 164 | # ---------------- |
| 165 | # Compiler plugins are advertised to the build system via the function |
| 166 | # iree_compiler_register_plugin(), which associated a plugin id to a build target |
| 167 | # and registration function. See samples/compiler_plugins for examples. |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 168 | # |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 169 | # External HAL Driver Plugins |
| 170 | # --------------------------- |
| 171 | # HAL driver implementations are advertised to the build system via |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 172 | # iree_register_external_hal_driver(), which specifies the name, target, |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 173 | # registration function and optional source/binary directory. |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 174 | #------------------------------------------------------------------------------- |
| 175 | |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 176 | set(IREE_CMAKE_PLUGIN_PATHS "" CACHE STRING "Paths to be scanned for IREE CMake plugin includes") |
| 177 | list(APPEND IREE_CMAKE_BUILTIN_PLUGIN_PATHS "compiler/plugins") |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 178 | if(IREE_BUILD_SAMPLES) |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 179 | list(APPEND IREE_CMAKE_BUILTIN_PLUGIN_PATHS "samples/compiler_plugins") |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 180 | endif() |
| 181 | |
| 182 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 183 | # Experimental project flags |
| 184 | #------------------------------------------------------------------------------- |
| 185 | |
bjacob | 2eda767 | 2023-11-14 14:23:13 -0500 | [diff] [blame] | 186 | option(IREE_BUILD_EXPERIMENTAL_CPU_UKERNEL_PLUGINS "Build experimental plugins making builtin ukernels available to llvm-cpu modules compiled with --iree-llvmcpu-enable-ukernels" OFF) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 187 | option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." OFF) |
Stella Laurenzo | 0f005e5 | 2020-12-27 11:54:33 -0800 | [diff] [blame] | 188 | |
| 189 | #------------------------------------------------------------------------------- |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 190 | # CUDA Toolkit. |
| 191 | # |
| 192 | # Using the (optional) CUDA support in the compiler and runtime requires the |
| 193 | # NVIDIA CUDA Toolkit. The toolkit can either be installed ahead of time or |
| 194 | # it can be automatically downloaded on certain host architectures. |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 195 | #------------------------------------------------------------------------------- |
| 196 | |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 197 | set(IREE_CUDA_AVAILABLE OFF) |
| 198 | find_package(CUDAToolkit) |
| 199 | if(CUDAToolkit_FOUND) |
| 200 | set(IREE_CUDA_AVAILABLE ON) |
| 201 | else() |
| 202 | # We can download the SDK in build_tools/third_party/cuda/CMakeLists.txt, if |
| 203 | # on a supported platform/arch. |
| 204 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR WIN32) |
| 205 | if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)") |
| 206 | set(IREE_CUDA_AVAILABLE ON) |
| 207 | endif() |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 208 | endif() |
| 209 | endif() |
| 210 | |
| 211 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 212 | # Runtime HAL Driver Options |
| 213 | # By default, all runtime drivers supported by the current platform which do |
| 214 | # not require external deps are enabled by default. This can be changed with: |
| 215 | # -DIREE_HAL_DRIVER_DEFAULTS=OFF |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 216 | #------------------------------------------------------------------------------- |
| 217 | |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 218 | # External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more |
| 219 | # information on how to declare external drivers. |
| 220 | set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "") |
| 221 | |
Ben Vanik | 8916027 | 2022-09-26 16:44:11 -0700 | [diff] [blame] | 222 | # Additional executable loader deps to add dependent libraries to any target |
| 223 | # using the default executable loader registration utilities. |
| 224 | # TODO(benvanik): extend the deps to encompass the built-in loaders too so that |
| 225 | # we have one flag. We could also support a list of deps and automatically |
| 226 | # generate the registration from that via a configure file. |
| 227 | set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "") |
| 228 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 229 | # Additional executable import provider deps to add dependent libraries to any |
| 230 | # target using the default executable import registration utilities. |
| 231 | # TODO(benvanik): extend the deps to encompass the built-in imports too so that |
| 232 | # we have one flag. We could also support a list of deps and automatically |
| 233 | # generate the registration from that via a configure file. |
| 234 | set(IREE_HAL_EXECUTABLE_PLUGIN_EXTRA_DEPS "" CACHE STRING "") |
| 235 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 236 | option(IREE_HAL_DRIVER_DEFAULTS "Sets the default value for all runtime HAL drivers" ON) |
Ben Vanik | a9aaebe | 2022-12-16 09:14:53 -0800 | [diff] [blame] | 237 | |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 238 | # CUDA support is enabled by default if the platform supports the CUDA SDK and |
| 239 | # not cross compiling. Note: a CUDA-compatible GPU with drivers is still |
| 240 | # required to actually run CUDA workloads. |
| 241 | set(IREE_HAL_DRIVER_CUDA_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 242 | if(NOT IREE_CUDA_AVAILABLE OR CMAKE_CROSSCOMPILING) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 243 | set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF) |
| 244 | endif() |
| 245 | |
| 246 | # Vulkan support is enabled by default if the platform might support Vulkan. |
| 247 | # Apple platforms support Metal instead of Vulkan, though MoltenVK may work. |
| 248 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 249 | if(APPLE) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 250 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF) |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 251 | endif() |
Marius Brehler | 0a4b67f | 2020-05-08 13:19:16 -0700 | [diff] [blame] | 252 | |
Lei Zhang | d1d03cb | 2023-08-07 13:52:56 -0400 | [diff] [blame] | 253 | # Metal support is enabled if it's one of the Apple platforms. |
| 254 | set(IREE_HAL_DRIVER_METAL_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
| 255 | # Right now only support Apple silicon devices. |
| 256 | if(NOT APPLE OR NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") |
| 257 | set(IREE_HAL_DRIVER_METAL_DEFAULT OFF) |
| 258 | endif() |
| 259 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 260 | 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] | 261 | option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 262 | option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 263 | option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT}) |
Lei Zhang | d1d03cb | 2023-08-07 13:52:56 -0400 | [diff] [blame] | 264 | option(IREE_HAL_DRIVER_METAL "Enables the 'metal' runtime HAL driver" ${IREE_HAL_DRIVER_METAL_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 265 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 266 | option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON) |
| 267 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 268 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 269 | 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] | 270 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 271 | option(IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS "Sets the default value for all runtime HAL executable plugin mechanisms" ON) |
| 272 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS}) |
| 273 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS}) |
| 274 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 275 | # Emscripten builds don't support embedded ELF libraries. |
| 276 | if(EMSCRIPTEN) |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 277 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 278 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 279 | endif() |
| 280 | |
| 281 | # If forcing system libraries (for TSAN/debugging tools/etc) then ensure the |
| 282 | # system library loader is linked in. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 283 | if(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 284 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ON) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 285 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ON) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 286 | endif() |
| 287 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 288 | # If no local driver is enabled then we force all the loaders/imports off; this |
| 289 | # allows for simpler checks that don't need to see if both the driver and |
| 290 | # feature is available. |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 291 | if(NOT IREE_HAL_DRIVER_LOCAL_SYNC AND NOT IREE_HAL_DRIVER_LOCAL_TASK) |
| 292 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
| 293 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT OFF) |
| 294 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT OFF) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 295 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF) |
| 296 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT OFF) |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 297 | endif() |
| 298 | |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 299 | 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] | 300 | option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT}) |
| 301 | option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT}) |
| 302 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 303 | option(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF "Enables the embedded dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT}) |
| 304 | option(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY "Enables the system dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT}) |
| 305 | |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 306 | if(IREE_BUILD_COMPILER) |
| 307 | # The compiler requires the local task driver with the VMVX loader. |
| 308 | set(IREE_HAL_DRIVER_LOCAL_TASK ON) |
| 309 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE ON) |
| 310 | endif() |
| 311 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 312 | message(STATUS "IREE HAL drivers:") |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 313 | if(IREE_HAL_DRIVER_CUDA) |
| 314 | message(STATUS " - cuda") |
| 315 | endif() |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 316 | if(IREE_HAL_DRIVER_LOCAL_SYNC) |
| 317 | message(STATUS " - local-sync") |
| 318 | endif() |
| 319 | if(IREE_HAL_DRIVER_LOCAL_TASK) |
| 320 | message(STATUS " - local-task") |
| 321 | endif() |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 322 | if(IREE_HAL_DRIVER_VULKAN) |
| 323 | message(STATUS " - vulkan") |
| 324 | endif() |
Lei Zhang | d1d03cb | 2023-08-07 13:52:56 -0400 | [diff] [blame] | 325 | if(IREE_HAL_DRIVER_METAL) |
| 326 | message(STATUS " - metal") |
| 327 | endif() |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 328 | if(IREE_EXTERNAL_HAL_DRIVERS) |
| 329 | message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}") |
| 330 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 331 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 332 | message(STATUS "IREE HAL local executable library loaders:") |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 333 | if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF) |
| 334 | message(STATUS " - embedded-elf") |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 335 | endif() |
| 336 | if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY) |
| 337 | message(STATUS " - system-library") |
| 338 | endif() |
| 339 | if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE) |
| 340 | message(STATUS " - vmvx-module") |
| 341 | endif() |
| 342 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 343 | message(STATUS "IREE HAL local executable plugin mechanisms:") |
| 344 | if(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF) |
| 345 | message(STATUS " - embedded-elf") |
| 346 | endif() |
| 347 | if(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY) |
| 348 | message(STATUS " - system-library") |
| 349 | endif() |
| 350 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 351 | #------------------------------------------------------------------------------- |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 352 | # Compiler Target Options |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 353 | # By default, all compiler targets supported by the current platform are |
| 354 | # enabled. Some compiler targets like CUDA will install external deps as |
| 355 | # needed at configure time. This can be changed with: |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 356 | # -DIREE_TARGET_BACKEND_DEFAULTS=OFF |
| 357 | #------------------------------------------------------------------------------- |
| 358 | |
| 359 | option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON) |
| 360 | |
| 361 | # The VMVX backend is always enabled. |
| 362 | cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF) |
| 363 | |
| 364 | # Supported default target backends. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 365 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 366 | 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] | 367 | 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] | 368 | cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 369 | |
Stella Laurenzo | 58b5670 | 2023-10-05 15:05:58 -0700 | [diff] [blame] | 370 | # Default target backends that are not yet fully supported but are being brought up. |
| 371 | cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 372 | |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 373 | # Supported default target backends that are only available on certain |
| 374 | # platforms. |
| 375 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT ${IREE_TARGET_BACKEND_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 376 | if(NOT IREE_CUDA_AVAILABLE) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 377 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT OFF) |
| 378 | endif() |
| 379 | cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" ${IREE_TARGET_BACKEND_CUDA_DEFAULT} ${IREE_BUILD_COMPILER} OFF) |
| 380 | |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 381 | # Non-default target backends either have additional dependencies or are |
| 382 | # experimental/niche in some fashion. |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 383 | # Disable WebGPU by default - it has complex deps and is under development. |
| 384 | cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
| 385 | |
| 386 | #------------------------------------------------------------------------------- |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 387 | # Compiler Input Dialects |
| 388 | #------------------------------------------------------------------------------- |
| 389 | |
Jakub Kuderski | 0dbf086 | 2023-06-12 14:33:06 -0400 | [diff] [blame] | 390 | cmake_dependent_option(IREE_INPUT_STABLEHLO "Builds support for compiling StableHLO programs" ON ${IREE_BUILD_COMPILER} OFF) |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 391 | cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 392 | cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 393 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 394 | if(IREE_BUILD_COMPILER) |
| 395 | message(STATUS "IREE compiler input dialects:") |
Jakub Kuderski | 0dbf086 | 2023-06-12 14:33:06 -0400 | [diff] [blame] | 396 | if(IREE_INPUT_STABLEHLO) |
| 397 | message(STATUS " - StableHLO") |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 398 | endif() |
| 399 | if(IREE_INPUT_TORCH) |
| 400 | message(STATUS " - Torch MLIR") |
| 401 | endif() |
| 402 | if(IREE_INPUT_TOSA) |
| 403 | message(STATUS " - TOSA") |
| 404 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 405 | endif() |
| 406 | |
| 407 | #------------------------------------------------------------------------------- |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 408 | # Compiler Output Formats |
| 409 | #------------------------------------------------------------------------------- |
| 410 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 411 | cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF) |
| 412 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 413 | if(IREE_BUILD_COMPILER) |
| 414 | message(STATUS "IREE compiler output formats:") |
| 415 | if(IREE_OUTPUT_FORMAT_C) |
Ben Vanik | 09630d6 | 2023-04-13 14:21:40 -0700 | [diff] [blame] | 416 | message(STATUS " - 'vm-c': textual C source module") |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 417 | endif() |
| 418 | # The 'vm-bytecode' and 'vm-asm' formats are always enabled. |
Ben Vanik | 09630d6 | 2023-04-13 14:21:40 -0700 | [diff] [blame] | 419 | message(STATUS " - 'vm-bytecode': VM bytecode") |
| 420 | message(STATUS " - 'vm-asm': VM MLIR assembly") |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 421 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 422 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 423 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 424 | # IREE compilation toolchain configuration |
| 425 | #------------------------------------------------------------------------------- |
| 426 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 427 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 428 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 429 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
bjacob | 0e03852 | 2023-06-08 18:16:32 -0400 | [diff] [blame] | 430 | option(IREE_BYTECODE_MODULE_ENABLE_ASAN "Enable address sanitizer in IREE modules in tests" OFF) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 431 | 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] | 432 | option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF) |
Stella Laurenzo | deb4805 | 2022-11-25 10:41:46 -0800 | [diff] [blame] | 433 | option(IREE_ENABLE_SPLIT_DWARF "Enable gsplit-dwarf for debug information if the platform supports it" OFF) |
| 434 | option(IREE_ENABLE_THIN_ARCHIVES "Enables thin ar archives (elf systems only). Disable for released static archives" OFF) |
Ben Vanik | adadd03 | 2022-11-28 23:18:16 -0800 | [diff] [blame] | 435 | option(IREE_LINK_COMPILER_SHARED_LIBRARY "Links IREE tools using the compiler compiled into a shared library" ON) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 436 | |
| 437 | # STREQUAL feels wrong here - we don't care about the exact true-value used, |
| 438 | # ON or TRUE or something else. But we haven't been able to think of a less bad |
Scott Todd | c7b2912 | 2023-02-21 17:33:35 -0800 | [diff] [blame] | 439 | # alternative. https://github.com/openxla/iree/pull/8474#discussion_r840790062 |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 440 | if(NOT IREE_ENABLE_TSAN STREQUAL IREE_BYTECODE_MODULE_ENABLE_TSAN) |
| 441 | message(SEND_ERROR |
| 442 | "IREE_ENABLE_TSAN and IREE_BYTECODE_MODULE_ENABLE_TSAN must be " |
| 443 | "simultaneously ON or OFF. " |
| 444 | "A discrepancy between the two would cause tests to crash as IREE " |
| 445 | "runtime code (controlled by IREE_ENABLE_TSAN) calls into test IREE " |
| 446 | "modules (controlled by IREE_BYTECODE_MODULE_ENABLE_TSAN)") |
| 447 | endif() |
| 448 | |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 449 | if(IREE_BUILD_COMPILER) |
| 450 | if(IREE_BYTECODE_MODULE_ENABLE_ASAN OR IREE_BYTECODE_MODULE_ENABLE_TSAN) |
| 451 | if(NOT IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER) |
| 452 | message(SEND_ERROR |
| 453 | "When IREE_BYTECODE_MODULE_ENABLE_ASAN or IREE_BYTECODE_MODULE_ENABLE_TSAN is ON, " |
| 454 | "IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER must also be ON. " |
| 455 | "ASAN/TSAN instrumentation is not currently supported in embedded modules.") |
| 456 | endif() |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 457 | endif() |
| 458 | endif() |
| 459 | |
Scott Todd | 8678138 | 2023-02-07 14:11:52 -0800 | [diff] [blame] | 460 | if(IREE_LINK_COMPILER_SHARED_LIBRARY AND IREE_ENABLE_COMPILER_TRACING) |
| 461 | message(SEND_ERROR |
| 462 | "IREE_ENABLE_COMPILER_TRACING requires " |
| 463 | "-DIREE_LINK_COMPILER_SHARED_LIBRARY=OFF (the compiler library must not " |
| 464 | "be unloaded before Tracy finishes, static linking is one workaround)") |
| 465 | endif() |
| 466 | |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 467 | option(IREE_ENABLE_CCACHE |
| 468 | "[DEPRECATED: Use CMAKE_<LANG>_COMPILER_LAUNCHER configure options or environment variables instead.] Use ccache if installed." |
| 469 | OFF) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 470 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 471 | if(IREE_ENABLE_CCACHE) |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 472 | message(WARNING |
| 473 | "IREE_ENABLE_CCACHE is deprecated. Use CMAKE_<LANG>_COMPILER_LAUNCHER" |
| 474 | " configure options or environment variables instead.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 475 | find_program(CCACHE_PROGRAM ccache) |
| 476 | if(CCACHE_PROGRAM) |
| 477 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 478 | else() |
| 479 | message(SEND_ERROR |
| 480 | "IREE_ENABLE_CCACHE was set, but executable `ccache` was not found.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 481 | endif() |
| 482 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 483 | |
Geoffrey Martin-Noble | 3fa4f8d | 2021-09-10 09:25:27 -0700 | [diff] [blame] | 484 | 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] | 485 | |
| 486 | #------------------------------------------------------------------------------- |
| 487 | # IREE assertions |
| 488 | # We don't love the way this is done, but we have to line it up with how LLVM |
| 489 | # does it and not diverge, since all implementations and all header users must |
| 490 | # have the same definition of NDEBUG. |
| 491 | # |
| 492 | # LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then |
| 493 | # conditions itself to only update flags if not building Debug. We just let |
| 494 | # IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the |
| 495 | # flags in appropriate build types. |
| 496 | # |
| 497 | # If IREE_ENABLE_ASSERTIONS is set ON manually, then |
| 498 | # - NDEBUG must be undefined |
| 499 | # - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties |
| 500 | # from mucking with globals. |
| 501 | # |
| 502 | # Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done |
| 503 | # at the top level to avoid divergence. |
| 504 | #------------------------------------------------------------------------------- |
| 505 | |
| 506 | option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF) |
| 507 | |
| 508 | # Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if |
| 509 | # CMAKE_BUILD_TYPE is not Debug). |
| 510 | function(iree_fix_ndebug) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 511 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE) |
| 512 | if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 513 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 514 | foreach(_FLAGS_VAR_TO_SCRUB |
| 515 | CMAKE_CXX_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE} |
| 516 | CMAKE_C_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE}) |
| 517 | set(_ORIGINAL_FLAGS "${${_FLAGS_VAR_TO_SCRUB}}") |
| 518 | string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " _ALTERED_FLAGS "${_ORIGINAL_FLAGS}") |
| 519 | if(NOT "${_ORIGINAL_FLAGS}" STREQUAL "${_ALTERED_FLAGS}") |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 520 | message(STATUS |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 521 | "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${_FLAGS_VAR_TO_SCRUB}: '${_ORIGINAL_FLAGS}' -> '${_ALTERED_FLAGS}'") |
| 522 | set(${_FLAGS_VAR_TO_SCRUB} "${_ALTERED_FLAGS}" PARENT_SCOPE) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 523 | endif() |
| 524 | endforeach() |
| 525 | |
| 526 | # Make sure that LLVM doesn't add its own logic for assertion disabling. |
| 527 | # We'd like to make sure that we are not dueling over globals. |
| 528 | set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE) |
| 529 | endif() |
| 530 | endfunction() |
| 531 | iree_fix_ndebug() |
| 532 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 533 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 534 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 535 | #------------------------------------------------------------------------------- |
| 536 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 537 | list(APPEND CMAKE_MODULE_PATH |
| 538 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 539 | ) |
| 540 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 541 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 542 | include(iree_copts) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 543 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 544 | include(iree_cc_library) |
| 545 | include(iree_cc_test) |
Scott Todd | 20d746a | 2023-01-12 09:11:59 -0800 | [diff] [blame] | 546 | include(iree_import_binary) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 547 | include(iree_external_cmake_options) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 548 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 549 | include(iree_tablegen_doc) |
CindyLiu | 40ed02d | 2021-04-22 16:16:28 +0000 | [diff] [blame] | 550 | include(iree_c_embed_data) |
Ben Vanik | 7f6c57c | 2023-02-07 18:04:32 -0800 | [diff] [blame] | 551 | include(iree_bitcode_library) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 552 | include(iree_bytecode_module) |
Marius Brehler | 46e8331 | 2021-03-25 00:11:39 +0100 | [diff] [blame] | 553 | include(iree_c_module) |
Stella Laurenzo | 94363e2 | 2020-12-15 13:46:14 -0800 | [diff] [blame] | 554 | include(iree_python) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 555 | include(iree_lit_test) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 556 | include(iree_llvm) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 557 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 558 | include(iree_check_test) |
bjacob | 5feef48 | 2021-10-21 16:53:58 -0400 | [diff] [blame] | 559 | include(iree_trace_runner_test) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 560 | include(iree_native_test) |
Geoffrey Martin-Noble | 2811e50 | 2022-01-25 09:44:40 -0800 | [diff] [blame] | 561 | include(iree_cc_binary_benchmark) |
Geoffrey Martin-Noble | 66d4889 | 2021-10-29 12:24:58 -0700 | [diff] [blame] | 562 | include(iree_benchmark_suite) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 563 | include(iree_microbenchmark_suite) |
Scott Todd | 434ff0e | 2021-12-21 10:38:36 -0800 | [diff] [blame] | 564 | include(iree_hal_cts_test_suite) |
CindyLiu | ae72b95 | 2022-08-23 15:26:08 -0700 | [diff] [blame] | 565 | include(iree_static_linker_test) |
Jerry Wu | 116db87 | 2022-09-22 19:33:13 +0000 | [diff] [blame] | 566 | include(iree_fetch_artifact) |
CindyLiu | 080198f | 2022-10-06 07:21:17 -0700 | [diff] [blame] | 567 | include(iree_run_module_test) |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 568 | include(iree_plugin_register) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 569 | |
Stella Laurenzo | be0f1e1 | 2023-04-03 13:34:38 -0700 | [diff] [blame] | 570 | # Default any sub-tree which doesn't provide its own package namespacing |
| 571 | # to derive it relative to this directory and prefixed with iree/. |
| 572 | set(IREE_PACKAGE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}") |
Lei Zhang | 923535d | 2023-04-06 18:07:43 -0400 | [diff] [blame] | 573 | set(IREE_PACKAGE_ROOT_PREFIX "iree") |
Stella Laurenzo | be0f1e1 | 2023-04-03 13:34:38 -0700 | [diff] [blame] | 574 | |
Marius Brehler | 06ac36e | 2020-01-10 14:44:11 -0800 | [diff] [blame] | 575 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 576 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 577 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 578 | # Experimental next-generation CUDA HAL driver |
| 579 | # Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=cuda2 |
| 580 | #------------------------------------------------------------------------------- |
| 581 | |
| 582 | iree_register_external_hal_driver( |
| 583 | NAME |
| 584 | cuda2 |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 585 | SOURCE_DIR |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 586 | "${CMAKE_CURRENT_SOURCE_DIR}/experimental/cuda2" |
| 587 | DRIVER_TARGET |
| 588 | iree::experimental::cuda2::registration |
| 589 | REGISTER_FN |
| 590 | iree_hal_cuda2_driver_module_register |
| 591 | ) |
| 592 | |
| 593 | #------------------------------------------------------------------------------- |
| 594 | # Experimental ROCM HAL driver |
| 595 | # Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=rocm |
| 596 | #------------------------------------------------------------------------------- |
| 597 | |
| 598 | iree_register_external_hal_driver( |
| 599 | NAME |
| 600 | rocm |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 601 | SOURCE_DIR |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 602 | "${CMAKE_CURRENT_SOURCE_DIR}/experimental/rocm" |
| 603 | DRIVER_TARGET |
| 604 | iree::experimental::rocm::registration |
| 605 | REGISTER_FN |
| 606 | iree_hal_rocm_driver_module_register |
| 607 | ) |
| 608 | |
| 609 | #------------------------------------------------------------------------------- |
Nithin Meganathan | ef51eb6 | 2023-11-30 14:32:40 -0800 | [diff] [blame] | 610 | # Experimental HIP HAL driver |
| 611 | # Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=hip |
| 612 | #------------------------------------------------------------------------------- |
| 613 | |
| 614 | iree_register_external_hal_driver( |
| 615 | NAME |
| 616 | hip |
Ben Vanik | 62c4f98 | 2023-12-12 18:01:52 -0800 | [diff] [blame] | 617 | SOURCE_DIR |
Nithin Meganathan | ef51eb6 | 2023-11-30 14:32:40 -0800 | [diff] [blame] | 618 | "${CMAKE_CURRENT_SOURCE_DIR}/experimental/hip" |
| 619 | DRIVER_TARGET |
| 620 | iree::experimental::hip::registration |
| 621 | REGISTER_FN |
| 622 | iree_hal_hip_driver_module_register |
| 623 | ) |
| 624 | |
| 625 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 626 | # Experimental WebGPU HAL driver |
| 627 | # Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=webgpu |
| 628 | #------------------------------------------------------------------------------- |
| 629 | |
| 630 | iree_register_external_hal_driver( |
| 631 | NAME |
| 632 | webgpu |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 633 | SOURCE_DIR |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 634 | "${CMAKE_CURRENT_SOURCE_DIR}/experimental/webgpu" |
Scott Todd | 50aa2cc | 2023-11-27 10:28:47 -0800 | [diff] [blame] | 635 | BINARY_DIR |
| 636 | "${CMAKE_CURRENT_BINARY_DIR}/experimental/webgpu" |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 637 | DRIVER_TARGET |
| 638 | iree::experimental::webgpu::registration |
| 639 | REGISTER_FN |
| 640 | iree_hal_webgpu_driver_module_register |
| 641 | ) |
| 642 | |
| 643 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 644 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 645 | #------------------------------------------------------------------------------- |
| 646 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 647 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 648 | 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] | 649 | |
| 650 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 651 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 652 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 653 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 654 | mark_as_advanced( |
| 655 | CMAKE_CXX_FLAGS_FASTBUILD |
| 656 | CMAKE_C_FLAGS_FASTBUILD |
| 657 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 658 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 659 | ) |
| 660 | |
Scott Todd | 7649dee | 2022-07-18 11:31:46 -0700 | [diff] [blame] | 661 | # Override the system's default linker. |
| 662 | # See also: https://llvm.org/docs/CMake.html#llvm-use-linker. |
| 663 | set(IREE_USE_LINKER "" CACHE STRING "") |
| 664 | # Equivalent to setting -DIREE_USE_LINKER=lld. |
| 665 | # Note that unlike LLVM's LLVM_ENABLE_LLD, this does _not_ build lld. You will |
| 666 | # need to either install a recent version of lld or build it from source prior |
| 667 | # to setting this option. See also: https://lld.llvm.org/#using-lld. |
| 668 | # This option is disabled on Apple platforms, where lld is not supported. |
| 669 | cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF) |
| 670 | |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 671 | include(iree_setup_toolchain) |
| 672 | |
| 673 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 674 | # Python |
| 675 | # If building features that require Python development, find them early in |
| 676 | # one invocation (some CMake versions are sensitive to resolving out of order). |
| 677 | # Otherwise, for features that just require the interpreter, find that alone. |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 678 | #------------------------------------------------------------------------------- |
| 679 | |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 680 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 681 | # After CMake 3.18, we are able to limit the scope of the search to just |
| 682 | # Development.Module. Searching for Development will fail in situations where |
| 683 | # the Python libraries are not available. When possible, limit to just |
| 684 | # Development.Module. |
| 685 | # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode |
Scott Todd | a24c8c5 | 2022-05-17 09:22:47 -0700 | [diff] [blame] | 686 | # |
| 687 | # Configuring the Development.Module is flaky in multi-project setups. |
| 688 | # "Bootstrapping" by first looking for the optional Development component |
| 689 | # seems to be robust generally. |
| 690 | # See: https://reviews.llvm.org/D118148 |
Han-Chung Wang | 9ed3dab | 2023-08-30 14:25:24 -0700 | [diff] [blame] | 691 | # If building Python packages, we have a hard requirement on 3.9+. |
| 692 | find_package(Python3 3.9 COMPONENTS Interpreter Development NumPy) |
| 693 | find_package(Python3 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED) |
Stella Laurenzo | acf0b27 | 2023-06-26 21:25:48 -0700 | [diff] [blame] | 694 | # Some parts of the build use FindPython instead of FindPython3. Why? No |
| 695 | # one knows, but they are different. So make sure to bootstrap this one too. |
| 696 | # Not doing this here risks them diverging, which on multi-Python systems, |
| 697 | # can be troublesome. Note that nanobind requires FindPython. |
| 698 | set(Python_EXECUTABLE "${Python3_EXECUTABLE}") |
Han-Chung Wang | 9ed3dab | 2023-08-30 14:25:24 -0700 | [diff] [blame] | 699 | find_package(Python 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 700 | elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 701 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
Stella Laurenzo | acf0b27 | 2023-06-26 21:25:48 -0700 | [diff] [blame] | 702 | set(Python_EXECUTABLE "${Python3_EXECUTABLE}") |
| 703 | find_package(Python COMPONENTS Interpreter REQUIRED) |
| 704 | endif() |
| 705 | |
| 706 | if(NOT "${Python_EXECUTABLE}" STREQUAL "${Python3_EXECUTABLE}") |
| 707 | message(WARNING "FindPython and FindPython3 found different executables. You may need to pin -DPython_EXECUTABLE and -DPython3_EXECUTABLE (${Python_EXECUTABLE} vs ${Python3_EXECUTABLE})") |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 708 | endif() |
| 709 | |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 710 | # Extended Python environment checks. |
| 711 | if(Python3_FOUND) |
| 712 | iree_detect_pyyaml() |
| 713 | endif() |
| 714 | |
| 715 | if(IREE_BUILD_TESTS AND NOT IREE_PYYAML_FOUND) |
| 716 | message(WARNING "IREE's regression test suite requires PyYAML to run all tests. It is not installed, so some tests will be disabled.") |
| 717 | endif() |
| 718 | |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 719 | #------------------------------------------------------------------------------- |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 720 | # Check if git submodules have been initialized. |
| 721 | # This will only run if python3 is available. |
| 722 | #------------------------------------------------------------------------------- |
| 723 | |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 724 | option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON) |
| 725 | |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 726 | find_package(Python3 COMPONENTS Interpreter QUIET) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 727 | find_package(Git) |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 728 | if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 729 | # Only check submodule status when the git commit changes. |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 730 | execute_process( |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 731 | COMMAND git rev-parse --short HEAD |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 732 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 733 | RESULT_VARIABLE SHORT_HASH_RESULT |
| 734 | OUTPUT_VARIABLE SHORT_HASH) |
| 735 | string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}") |
Scott Todd | 2a8cd3b | 2021-12-13 11:58:44 -0800 | [diff] [blame] | 736 | if(SHORT_HASH_RESULT EQUAL "0" AND NOT "${IREE_GIT_SHORT_HASH}" STREQUAL "${SHORT_HASH}") |
CindyLiu | 0e8fdc6 | 2022-10-14 09:35:44 -0700 | [diff] [blame] | 737 | if(NOT IREE_BUILD_COMPILER) |
| 738 | set(CHECK_SUBMODULE_ARGS "--runtime_only") |
| 739 | endif() |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 740 | execute_process( |
CindyLiu | 0e8fdc6 | 2022-10-14 09:35:44 -0700 | [diff] [blame] | 741 | COMMAND ${Python3_EXECUTABLE} build_tools/scripts/git/check_submodule_init.py ${CHECK_SUBMODULE_ARGS} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 742 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 743 | RESULT_VARIABLE SUBMODULE_INIT_RESULT |
| 744 | ) |
| 745 | if(NOT SUBMODULE_INIT_RESULT EQUAL "0") |
| 746 | message(FATAL_ERROR "check_submodule_init.py failed, see the logs above") |
| 747 | else() |
| 748 | set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE) |
| 749 | endif() |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 750 | endif() |
| 751 | endif() |
| 752 | |
| 753 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 754 | # IREE top-level targets |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 755 | # We define these here because various things in the build tree adds |
| 756 | # dependencies to them. |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 757 | #------------------------------------------------------------------------------- |
| 758 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 759 | if(IREE_BUILD_MICROBENCHMARKS) |
Han-Chung Wang | a6fbb76 | 2022-04-15 14:25:04 -0700 | [diff] [blame] | 760 | # Add top-level custom targets to drive generating microbenchmark suites. |
| 761 | add_custom_target(iree-microbenchmark-suites) |
| 762 | endif() |
| 763 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 764 | if(IREE_BUILD_DOCS) |
Scott Todd | 96d9213 | 2023-06-12 15:45:19 -0700 | [diff] [blame] | 765 | # Define a top-level custom target to drive generating documentation files. |
| 766 | # Add to the default target given that docs were explicitly requested. |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 767 | add_custom_target(iree-doc ALL) |
| 768 | endif() |
| 769 | |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 770 | # Samples may require additional files to be built/configured and will add |
| 771 | # dependencies to this target. |
| 772 | # Note: These will be automatically built with test dependencies |
| 773 | # (`iree-test-deps`). |
| 774 | add_custom_target(iree-sample-deps |
| 775 | COMMENT |
| 776 | "Building IREE sample data targets" |
| 777 | ) |
| 778 | |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 779 | # Testing rules that require generation will add dependencies to this target. |
| 780 | # This allows them to be EXCLUDE_FROM_ALL but still invokable. |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 781 | add_custom_target(iree-test-deps |
| 782 | COMMENT |
| 783 | "Building IREE test deps" |
| 784 | DEPENDS |
| 785 | iree-sample-deps |
| 786 | ) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 787 | |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 788 | # Testing rules that generate test scripts for iree-run-module-test will add |
| 789 | # dependencies to this target. It is a subset of `iree-test-deps`. |
| 790 | add_custom_target(iree-run-module-test-deps |
| 791 | COMMENT |
| 792 | "Building IREE run module test targets" |
| 793 | ) |
| 794 | |
Stella Laurenzo | e2dfc65 | 2023-02-15 18:12:03 -0800 | [diff] [blame] | 795 | # Convenience target for running IREE tests. |
| 796 | add_custom_target(iree-run-tests |
| 797 | COMMENT |
| 798 | "Run IREE unit tests" |
| 799 | WORKING_DIRECTORY |
| 800 | "${CMAKE_CURRENT_BINARY_DIR}" |
| 801 | USES_TERMINAL |
| 802 | COMMAND |
| 803 | "${CMAKE_COMMAND}" -E echo |
| 804 | "The 'iree-run-tests' target is a helper for running ctest. For advanced" |
| 805 | "options, build dependencies and invoke ctest independently as in:" |
| 806 | COMMAND |
| 807 | "${CMAKE_COMMAND}" -E echo |
| 808 | " \\(cd ${CMAKE_CURRENT_BINARY_DIR} \\&\\& cmake --build . --target iree-test-deps \\&\\& ctest --output-on-failure\\)" |
| 809 | COMMAND |
| 810 | "${CMAKE_COMMAND}" -E echo |
| 811 | "Run tests in parallel by setting a variable like CTEST_PARALLEL_LEVEL=25." |
| 812 | COMMAND |
| 813 | "${CMAKE_CTEST_COMMAND}" |
| 814 | --output-on-failure |
| 815 | ) |
| 816 | add_dependencies(iree-run-tests iree-test-deps) |
| 817 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 818 | #------------------------------------------------------------------------------- |
| 819 | # CUDA configuration for both the compiler and runtime. |
| 820 | # We do this at the top level so that we can fail fast and make global |
| 821 | # decisions that effect both compiler and runtime. It also helps with error |
| 822 | # messaging to do this all in one place, since we can provide very targeted |
| 823 | # advice. |
| 824 | #------------------------------------------------------------------------------- |
| 825 | |
| 826 | set(IREE_CUDA_LIBDEVICE_PATH "" CACHE FILEPATH "Absolute path to an appropriate libdevice.*.bc (needed to build the IREE cuda compiler target)") |
| 827 | |
| 828 | # If any CUDA features are being built, try to locate a CUDA SDK. We will fall |
| 829 | # back to this as needed for specific features. |
| 830 | if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA) |
| 831 | add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL) |
| 832 | endif() |
| 833 | |
| 834 | #------------------------------------------------------------------------------- |
| 835 | # MLIR/LLVM Dependency |
| 836 | #------------------------------------------------------------------------------- |
| 837 | |
| 838 | if(NOT IREE_BUILD_COMPILER) |
| 839 | message(STATUS "Not adding LLVM/MLIR because the configuration does not require it") |
| 840 | else() |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 841 | # Force enable BUILD_SHARED_LIBS for the compiler if instructed. |
| 842 | set(_IREE_ORIG_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) |
| 843 | if(IREE_COMPILER_BUILD_SHARED_LIBS) |
| 844 | set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) |
| 845 | endif() |
| 846 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 847 | # Get the main LLVM deps. |
| 848 | if(IREE_BUILD_BUNDLED_LLVM) |
| 849 | iree_llvm_configure_bundled() |
| 850 | else() |
| 851 | iree_llvm_configure_installed() |
| 852 | endif() |
| 853 | |
| 854 | # Also add a library that can be depended on to get LLVM includes setup |
| 855 | # properly. bazel_to_cmake targets this for some header only pseudo deps. |
| 856 | add_library(IREELLVMIncludeSetup INTERFACE) |
| 857 | target_include_directories(IREELLVMIncludeSetup INTERFACE |
| 858 | ${LLVM_INCLUDE_DIRS} |
| 859 | ${MLIR_INCLUDE_DIRS} |
| 860 | ${LLD_INCLUDE_DIRS} |
| 861 | ) |
| 862 | |
| 863 | # Splice the includes setup into base LLVM libraries so that using them |
| 864 | # gets everything nice and tidy. It would be super if some day, LLVM |
| 865 | # libraries set their right usage requirements for includes. In the meantime |
| 866 | # we add usage requirements to libraries at the root of all things LLVM. |
| 867 | iree_llvm_add_usage_requirements(LLVMSupport IREELLVMIncludeSetup) |
| 868 | iree_llvm_add_usage_requirements(MLIRSupport IREELLVMIncludeSetup) |
| 869 | |
Scott Todd | 53af681 | 2023-11-27 10:33:08 -0800 | [diff] [blame] | 870 | # Add external projects. |
| 871 | |
| 872 | message(STATUS "Configuring llvm-external-projects/mlir-iree-dialects") |
| 873 | list(APPEND CMAKE_MESSAGE_INDENT " ") |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 874 | iree_llvm_add_external_project(mlir-iree-dialects ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects) |
Scott Todd | 53af681 | 2023-11-27 10:33:08 -0800 | [diff] [blame] | 875 | list(POP_BACK CMAKE_MESSAGE_INDENT) |
| 876 | |
Stella Laurenzo | fd9cd2f | 2023-11-01 16:22:00 -0700 | [diff] [blame] | 877 | if(IREE_INPUT_STABLEHLO) |
Scott Todd | 53af681 | 2023-11-27 10:33:08 -0800 | [diff] [blame] | 878 | message(STATUS "Configuring third_party/stablehlo") |
| 879 | list(APPEND CMAKE_MESSAGE_INDENT " ") |
Stella Laurenzo | fd9cd2f | 2023-11-01 16:22:00 -0700 | [diff] [blame] | 880 | iree_llvm_add_external_project(stablehlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stablehlo) |
Scott Todd | 53af681 | 2023-11-27 10:33:08 -0800 | [diff] [blame] | 881 | list(POP_BACK CMAKE_MESSAGE_INDENT) |
Stella Laurenzo | fd9cd2f | 2023-11-01 16:22:00 -0700 | [diff] [blame] | 882 | endif() |
Ben Vanik | e3578d5 | 2023-09-12 09:35:11 -0700 | [diff] [blame] | 883 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 884 | # Ensure that LLVM-based dependencies needed for testing are included. |
| 885 | add_dependencies(iree-test-deps FileCheck) |
| 886 | if(IREE_LLD_TARGET) |
| 887 | add_dependencies(iree-test-deps ${IREE_LLD_TARGET}) |
| 888 | endif() |
| 889 | if(IREE_CLANG_TARGET) |
| 890 | add_dependencies(iree-test-deps ${IREE_CLANG_TARGET}) |
| 891 | endif() |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 892 | |
| 893 | set(BUILD_SHARED_LIBS ${_IREE_ORIG_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 894 | endif() |
| 895 | |
| 896 | #------------------------------------------------------------------------------- |
| 897 | # Other dependencies |
| 898 | #------------------------------------------------------------------------------- |
| 899 | |
| 900 | include(external_cc_library) |
| 901 | include(flatbuffer_c_library) |
| 902 | |
| 903 | add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL) |
| 904 | add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL) |
| 905 | add_subdirectory(build_tools/third_party/tracy_client EXCLUDE_FROM_ALL) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 906 | |
| 907 | iree_set_googletest_cmake_options() |
| 908 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
| 909 | |
| 910 | if(IREE_ENABLE_THREADING) |
| 911 | iree_set_benchmark_cmake_options() |
| 912 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
| 913 | if(IREE_ENABLE_CPUINFO) |
| 914 | iree_set_cpuinfo_cmake_options() |
| 915 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
| 916 | endif() |
| 917 | endif() |
| 918 | |
| 919 | # This defines the iree-flatcc-cli target, so we don't use EXCLUDE_FROM_ALL. |
| 920 | add_subdirectory(build_tools/third_party/flatcc) |
| 921 | |
| 922 | if(IREE_HAL_DRIVER_CUDA) |
| 923 | add_subdirectory(build_tools/third_party/nccl EXCLUDE_FROM_ALL) |
| 924 | endif() |
| 925 | |
| 926 | if(IREE_HAL_DRIVER_VULKAN) |
| 927 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
| 928 | endif() |
| 929 | |
| 930 | if(IREE_BUILD_COMPILER) |
Jakub Kuderski | 3546f2a | 2023-06-14 13:18:44 -0400 | [diff] [blame] | 931 | add_subdirectory(build_tools/third_party/stablehlo EXCLUDE_FROM_ALL) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 932 | endif() |
| 933 | |
| 934 | if(IREE_BUILD_TESTS) |
| 935 | include(iree_configure_testing) |
| 936 | endif() |
| 937 | |
| 938 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | abe91fa | 2023-06-26 16:57:30 -0700 | [diff] [blame] | 939 | # The compiler uses pybind11 |
| 940 | if(IREE_BUILD_COMPILER) |
| 941 | if(NOT TARGET pybind11::module) |
| 942 | message(STATUS "Using bundled pybind11") |
| 943 | add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL) |
| 944 | else() |
| 945 | message(STATUS "Not including bundled pybind11 (already configured)") |
| 946 | endif() |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 947 | endif() |
| 948 | endif() |
| 949 | |
| 950 | if(IREE_TARGET_BACKEND_METAL_SPIRV) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 951 | # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code. |
Scott Todd | ad321b6 | 2023-06-05 14:39:30 -0700 | [diff] [blame] | 952 | iree_set_spirv_cross_cmake_options() |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 953 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 954 | endif() |
| 955 | |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 956 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 957 | # IREE top-level libraries |
| 958 | #------------------------------------------------------------------------------- |
| 959 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 960 | if(IREE_ENABLE_CLANG_TIDY) |
| 961 | set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*) |
| 962 | endif() |
| 963 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 964 | add_subdirectory(build_tools/embed_data/) |
| 965 | |
Jerry Wu | 36641f9 | 2023-05-24 19:30:38 +0000 | [diff] [blame] | 966 | if(IREE_BUILD_E2E_TEST_ARTIFACTS) |
Stella Laurenzo | a6bf65c | 2022-01-11 20:47:51 -0800 | [diff] [blame] | 967 | find_program(IREE_IMPORT_TFLITE_PATH iree-import-tflite) |
| 968 | if(IREE_IMPORT_TFLITE_PATH) |
| 969 | message(STATUS "Found ${IREE_IMPORT_TFLITE_PATH} to generate benchmark artifacts") |
| 970 | else() |
| 971 | message(STATUS "iree-import-tflite not found. Some benchmarks may not configure") |
| 972 | endif() |
Jerry Wu | 60798ca | 2022-06-21 23:36:40 +0000 | [diff] [blame] | 973 | find_program(IREE_IMPORT_TF_PATH iree-import-tf) |
| 974 | if(IREE_IMPORT_TF_PATH) |
| 975 | message(STATUS "Found ${IREE_IMPORT_TF_PATH} to generate benchmark artifacts") |
| 976 | else() |
| 977 | message(STATUS "iree-import-tf not found. Some benchmarks may not configure") |
| 978 | endif() |
Jerry Wu | fed372c | 2023-10-19 12:05:32 -0700 | [diff] [blame] | 979 | |
| 980 | set(IREE_E2E_TEST_ARTIFACTS_DIR "${IREE_BINARY_DIR}/e2e_test_artifacts") |
Jerry Wu | 16e2d9c | 2022-11-22 06:19:46 +0000 | [diff] [blame] | 981 | endif() |
| 982 | |
| 983 | # Note: Test deps are not built as part of all (use the iree-test-deps target). |
| 984 | add_subdirectory(tests EXCLUDE_FROM_ALL) |
| 985 | |
Jacques Pienaar | 702929a | 2022-12-30 14:46:22 -0800 | [diff] [blame] | 986 | # tools/ can depend on compiler/ and runtime/. |
| 987 | # Note: tools sub directory is added before compiler/ so that phony targets for |
| 988 | # files with the same names from different rules are disambiguated towards |
| 989 | # those in tools/. |
| 990 | add_subdirectory(tools) |
Stella Laurenzo | 309dc5b | 2023-02-22 23:07:43 -0800 | [diff] [blame] | 991 | add_subdirectory(compiler) |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 992 | add_subdirectory(runtime) |
| 993 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 994 | if(IREE_ENABLE_CLANG_TIDY) |
| 995 | set(CMAKE_CXX_CLANG_TIDY "") |
| 996 | endif() |
| 997 | |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 998 | if(IREE_BUILD_TRACY) |
Ben Vanik | 77a8741 | 2023-10-09 14:46:28 -0700 | [diff] [blame] | 999 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux") |
| 1000 | message(WARNING "Building Tracy (IREE_BUILD_TRACY) on non-Darwin/Linux is unsupported and may fail below.") |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 1001 | endif() |
| 1002 | add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy) |
| 1003 | if(NOT TARGET IREETracyCaptureServer) |
| 1004 | message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.") |
| 1005 | endif() |
| 1006 | endif() |
| 1007 | |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 1008 | # Order constraint: The python bindings install tools targets from tools/ |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 1009 | # and tracy, and must come after it. |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 1010 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 1011 | # Write out a .env file to make IDEs and developers happy. |
| 1012 | # Yes, we are writing this to the source dir. It is only for IDEs and if |
Scott Todd | fe9cb17 | 2022-12-08 09:17:52 -0800 | [diff] [blame] | 1013 | # it gets clobbered, it is fine (it is also ignored in .gitignore). |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 1014 | set(_PYTHONPATH_ENV "PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
Scott Todd | fe9cb17 | 2022-12-08 09:17:52 -0800 | [diff] [blame] | 1015 | file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
| 1016 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
Scott Todd | 2fe00a5 | 2023-11-09 10:46:49 -0800 | [diff] [blame] | 1017 | # Similarly, write out .env.bat and .env.ps1 for Windows. |
Scott Todd | fe9cb17 | 2022-12-08 09:17:52 -0800 | [diff] [blame] | 1018 | set(_PYTHONPATH_ENV_BAT "set PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
| 1019 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.bat" CONTENT "${_PYTHONPATH_ENV_BAT}") |
Scott Todd | 2fe00a5 | 2023-11-09 10:46:49 -0800 | [diff] [blame] | 1020 | set(_PYTHONPATH_ENV_PS1 "$env:PYTHONPATH = '$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>'\n") |
| 1021 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.ps1" CONTENT "${_PYTHONPATH_ENV_PS1}") |
Stella Laurenzo | 77a63cd | 2021-01-04 17:29:54 -0800 | [diff] [blame] | 1022 | endif() |
| 1023 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 1024 | if(IREE_BUILD_BINDINGS_TFLITE) |
Scott Todd | ada25e6 | 2022-05-03 16:16:15 -0700 | [diff] [blame] | 1025 | add_subdirectory(runtime/bindings/tflite) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 1026 | endif() |
| 1027 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 1028 | if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES) |
Scott Todd | 15fce0a | 2022-02-14 12:43:23 -0800 | [diff] [blame] | 1029 | add_subdirectory(experimental/web) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 1030 | endif() |
| 1031 | |
bjacob | 3dc368e | 2023-05-09 12:50:18 -0400 | [diff] [blame] | 1032 | if(IREE_BUILD_EXPERIMENTAL_CPU_UKERNEL_PLUGINS) |
| 1033 | add_subdirectory(experimental/cpu_ukernel) |
| 1034 | endif() |
| 1035 | |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 1036 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 1037 | CACHE INTERNAL "IREE: Include Directories" FORCE) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 1038 | |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 1039 | #------------------------------------------------------------------------------- |
Jerry Wu | 161daa7 | 2023-05-22 22:08:49 +0000 | [diff] [blame] | 1040 | # IREE build tools |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 1041 | #------------------------------------------------------------------------------- |
| 1042 | |
| 1043 | add_subdirectory(build_tools/benchmarks) |
Jerry Wu | 161daa7 | 2023-05-22 22:08:49 +0000 | [diff] [blame] | 1044 | add_subdirectory(build_tools/github_actions) |
Jerry Wu | 71562cc | 2022-09-20 18:56:41 -0700 | [diff] [blame] | 1045 | add_subdirectory(build_tools/python) |
| 1046 | |
| 1047 | #------------------------------------------------------------------------------- |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 1048 | # Optional features |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 1049 | #------------------------------------------------------------------------------- |
| 1050 | |
Scott Todd | 4c022df | 2022-05-10 16:55:18 -0700 | [diff] [blame] | 1051 | # samples/ can depend on anything, so we include it last |
Stella Laurenzo | 1e8d1fa | 2022-04-22 09:50:43 -0700 | [diff] [blame] | 1052 | if(IREE_BUILD_SAMPLES) |
| 1053 | add_subdirectory(samples) |
| 1054 | endif() |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 1055 | |
| 1056 | if(IREE_BUILD_TESTS) |
| 1057 | iree_create_ctest_customization() |
| 1058 | endif() |