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 | |
Jakub Kuderski | e942406 | 2024-03-27 23:42:29 -0400 | [diff] [blame] | 63 | if(IREE_ENABLE_COMPILER_TRACING AND NOT IREE_ENABLE_RUNTIME_TRACING) |
| 64 | message(SEND_ERROR |
| 65 | "IREE_ENABLE_COMPILER_TRACING currently requires " |
| 66 | "-DIREE_ENABLE_RUNTIME_TRACING=ON") |
| 67 | endif() |
| 68 | |
Ben Vanik | 4aae003 | 2022-04-19 15:49:26 -0700 | [diff] [blame] | 69 | # TODO(#8469): remove the dependency on cpuinfo entirely. |
Ben Vanik | cbe93c0 | 2023-08-08 10:12:08 -0700 | [diff] [blame] | 70 | set(IREE_ENABLE_CPUINFO_DEFAULT ON) |
Ben Vanik | 62c4f98 | 2023-12-12 18:01:52 -0800 | [diff] [blame] | 71 | if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Emscripten|Windows|WindowsStore") |
Ben Vanik | cbe93c0 | 2023-08-08 10:12:08 -0700 | [diff] [blame] | 72 | set(IREE_ENABLE_CPUINFO_DEFAULT OFF) |
| 73 | endif() |
| 74 | 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] | 75 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 76 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 77 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Scott Todd | 96d9213 | 2023-06-12 15:45:19 -0700 | [diff] [blame] | 78 | option(IREE_BUILD_DOCS "Builds IREE documentation files." OFF) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 79 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 80 | option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF) |
Scott Todd | 3d6a8ee | 2024-05-23 14:49:54 -0700 | [diff] [blame] | 81 | option(IREE_BUILD_TRACY "Enables building the 'iree-tracy-capture' CLI tool and includes it in runtime Python bindings." OFF) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 82 | 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] | 83 | |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 84 | # Properties controlling version and naming of release artifacts. |
Stella Laurenzo | f33f5b5 | 2022-01-08 17:49:52 +0000 | [diff] [blame] | 85 | 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] | 86 | set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages") |
| 87 | set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages") |
Cullen Rhodes | 5f4235a | 2024-08-20 08:28:10 +0100 | [diff] [blame] | 88 | option(IREE_EMBEDDED_RELEASE_INFO "Embed the IREE version information in built artifacts." OFF) |
Stella Laurenzo | bb1de96 | 2021-01-05 08:18:33 -0800 | [diff] [blame] | 89 | |
Scott Todd | de426de | 2023-01-13 08:26:02 -0800 | [diff] [blame] | 90 | # Using already built host binaries, such as for cross-compilation. |
| 91 | set(IREE_HOST_BIN_DIR_DEFAULT "") |
| 92 | if(IREE_HOST_BINARY_ROOT) |
| 93 | message(WARNING "IREE_HOST_BINARY_ROOT is deprecated. Use IREE_HOST_BIN_DIR" |
| 94 | " pointing directly to the directory containing binaries" |
| 95 | " instead.") |
| 96 | set(IREE_HOST_BIN_DIR_DEFAULT "${IREE_HOST_BINARY_ROOT}/bin") |
| 97 | endif() |
| 98 | 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.") |
| 99 | |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 100 | 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] | 101 | 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] | 102 | |
Scott Todd | 46e1206 | 2024-02-02 10:54:59 -0800 | [diff] [blame] | 103 | option(IREE_BUILD_ALL_CHECK_TEST_MODULES "Builds all modules for iree_check_test, regardless of which would be tested" ON) |
| 104 | |
Boian Petkantchin | d4e3968 | 2023-07-31 10:09:16 -0700 | [diff] [blame] | 105 | 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] | 106 | |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 107 | # For development, builds LLVM (and in the future) the whole compiler as |
| 108 | # individual shared libraries similar to if passing -DBUILD_SHARED_LIBS=ON |
| 109 | # to a standalone LLVM build. This can dramatically reduce linking time and |
| 110 | # makes the management of some dependencies more strict. |
| 111 | # This option is considered experimental and should not be relied on until |
| 112 | # CI coverage is established. |
| 113 | option(IREE_COMPILER_BUILD_SHARED_LIBS "Enables BUILD_SHARED_LIBS CMake mode for LLVM and the compiler (this is only suitable for development)" OFF) |
| 114 | |
| 115 | # Must be defined as an option (CMake does not do it automatically), even though |
| 116 | # we override it for different parts of the tree. |
| 117 | # This option is considered experimental and should not be relied on until |
| 118 | # CI coverage is established. |
| 119 | option(BUILD_SHARED_LIBS "Instructs CMake to build libraries as shared if possible" OFF) |
| 120 | |
Stella Laurenzo | b61a918 | 2024-03-18 12:52:22 -0700 | [diff] [blame] | 121 | # Control of LTO settings for the runtime build. |
Jakub Kuderski | e942406 | 2024-03-27 23:42:29 -0400 | [diff] [blame] | 122 | set(IREE_RUNTIME_OPTIMIZATION_PROFILE "" CACHE STRING |
Stella Laurenzo | b61a918 | 2024-03-18 12:52:22 -0700 | [diff] [blame] | 123 | "Build optimization profile to apply. One of '', 'lto', 'size'.") |
| 124 | set(IREE_LTO_MODE "full" CACHE STRING "LTO type, 'thin' or 'full'. Only consulted on clang-like compilers.") |
| 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 | |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 186 | option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." OFF) |
Benoit Jacob | 655b71a | 2024-04-23 11:07:38 -0400 | [diff] [blame] | 187 | option(IREE_BUILD_EXPERIMENTAL_HAL_EXECUTABLE_LIBRARY_CALL_HOOKS "Build experimental hal_executable_library_call hook libraries that can be used with LD_PRELOAD against runtimes built with `-DCMAKE_C_FLAGS=-DIREE_HAL_EXECUTABLE_LIBRARY_CALL_HOOK`." 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) |
Lei Zhang | 41583ca | 2024-01-27 10:31:21 -0800 | [diff] [blame] | 198 | # The IREE cuda driver requires CUDA >= 12. |
Boian Petkantchin | 58cd112 | 2024-01-18 13:40:48 -0800 | [diff] [blame] | 199 | set(IREE_CUDA_MIN_VERSION_REQUIRED 12) |
| 200 | find_package(CUDAToolkit ${IREE_CUDA_MIN_VERSION_REQUIRED}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 201 | if(CUDAToolkit_FOUND) |
| 202 | set(IREE_CUDA_AVAILABLE ON) |
| 203 | else() |
| 204 | # We can download the SDK in build_tools/third_party/cuda/CMakeLists.txt, if |
| 205 | # on a supported platform/arch. |
| 206 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR WIN32) |
| 207 | if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)") |
| 208 | set(IREE_CUDA_AVAILABLE ON) |
| 209 | endif() |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 210 | endif() |
| 211 | endif() |
| 212 | |
| 213 | #------------------------------------------------------------------------------- |
Lei Zhang | 5f2743b | 2024-03-20 16:39:24 -0700 | [diff] [blame] | 214 | # HIP Default Target Configuration. |
| 215 | # |
| 216 | # HIP does not have a stable instruction set like NVIDIA PTX; it requires |
| 217 | # binaries specific to a target chip. We have tests that generate and run |
| 218 | # deployable code which need to specify the proper target chip. |
| 219 | #------------------------------------------------------------------------------- |
| 220 | |
| 221 | set(IREE_HIP_TEST_TARGET_CHIP "" CACHE STRING |
| 222 | "Target chip for HIP tests that need to compile device code. \ |
| 223 | Defaults to empty string to disable tests.") |
| 224 | |
| 225 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 226 | # Runtime HAL Driver Options |
| 227 | # By default, all runtime drivers supported by the current platform which do |
| 228 | # not require external deps are enabled by default. This can be changed with: |
| 229 | # -DIREE_HAL_DRIVER_DEFAULTS=OFF |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 230 | #------------------------------------------------------------------------------- |
| 231 | |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 232 | # External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more |
| 233 | # information on how to declare external drivers. |
| 234 | set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "") |
| 235 | |
Ben Vanik | 8916027 | 2022-09-26 16:44:11 -0700 | [diff] [blame] | 236 | # Additional executable loader deps to add dependent libraries to any target |
| 237 | # using the default executable loader registration utilities. |
| 238 | # TODO(benvanik): extend the deps to encompass the built-in loaders too so that |
| 239 | # we have one flag. We could also support a list of deps and automatically |
| 240 | # generate the registration from that via a configure file. |
| 241 | set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "") |
| 242 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 243 | # Additional executable import provider deps to add dependent libraries to any |
| 244 | # target using the default executable import registration utilities. |
| 245 | # TODO(benvanik): extend the deps to encompass the built-in imports too so that |
| 246 | # we have one flag. We could also support a list of deps and automatically |
| 247 | # generate the registration from that via a configure file. |
| 248 | set(IREE_HAL_EXECUTABLE_PLUGIN_EXTRA_DEPS "" CACHE STRING "") |
| 249 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 250 | 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] | 251 | |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 252 | # CUDA support is disabled by default. Note: a CUDA-compatible GPU with drivers is still |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 253 | # required to actually run CUDA workloads. |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 254 | set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 255 | |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 256 | # HIP support is disabled by default. Note: a HIP-compatible GPU with drivers is still |
| 257 | # required to actually run HIP workloads. |
| 258 | set(IREE_HAL_DRIVER_HIP_DEFAULT OFF) |
Lei Zhang | 5f2743b | 2024-03-20 16:39:24 -0700 | [diff] [blame] | 259 | |
Lei Zhang | d1d03cb | 2023-08-07 13:52:56 -0400 | [diff] [blame] | 260 | # Metal support is enabled if it's one of the Apple platforms. |
| 261 | set(IREE_HAL_DRIVER_METAL_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
| 262 | # Right now only support Apple silicon devices. |
| 263 | if(NOT APPLE OR NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") |
| 264 | set(IREE_HAL_DRIVER_METAL_DEFAULT OFF) |
| 265 | endif() |
| 266 | |
Ben Vanik | a6043e2 | 2024-10-03 08:49:55 -0700 | [diff] [blame] | 267 | # Null skeleton driver is only enabled in debug builds or dev mode. |
| 268 | # We don't want to ship release builds with it or count it when calculating |
| 269 | # binary sizes of minified builds. |
| 270 | set(IREE_HAL_DRIVER_NULL_DEFAULT OFF) |
| 271 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE) |
| 272 | if (IREE_DEV_MODE OR (_UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "DEBUG")) |
| 273 | set(IREE_HAL_DRIVER_NULL_DEFAULT ON) |
| 274 | endif() |
| 275 | |
| 276 | # Vulkan support is enabled by default if the platform might support Vulkan. |
| 277 | # Apple platforms support Metal instead of Vulkan, though MoltenVK may work. |
| 278 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS}) |
| 279 | if(APPLE) |
| 280 | set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF) |
| 281 | endif() |
| 282 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 283 | option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT}) |
Lei Zhang | 5f2743b | 2024-03-20 16:39:24 -0700 | [diff] [blame] | 284 | option(IREE_HAL_DRIVER_HIP "Enables the 'hip' runtime HAL driver" ${IREE_HAL_DRIVER_HIP_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 285 | option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
| 286 | option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS}) |
Lei Zhang | d1d03cb | 2023-08-07 13:52:56 -0400 | [diff] [blame] | 287 | option(IREE_HAL_DRIVER_METAL "Enables the 'metal' runtime HAL driver" ${IREE_HAL_DRIVER_METAL_DEFAULT}) |
Ben Vanik | a6043e2 | 2024-10-03 08:49:55 -0700 | [diff] [blame] | 288 | option(IREE_HAL_DRIVER_NULL "Enables the 'null' runtime HAL driver" ${IREE_HAL_DRIVER_NULL_DEFAULT}) |
| 289 | option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT}) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 290 | |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 291 | option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON) |
| 292 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 293 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS}) |
| 294 | 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] | 295 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 296 | option(IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS "Sets the default value for all runtime HAL executable plugin mechanisms" ON) |
| 297 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS}) |
| 298 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS}) |
| 299 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 300 | # Emscripten builds don't support embedded ELF libraries. |
| 301 | if(EMSCRIPTEN) |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 302 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 303 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF) |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 304 | endif() |
| 305 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 306 | # If no local driver is enabled then we force all the loaders/imports off; this |
| 307 | # allows for simpler checks that don't need to see if both the driver and |
| 308 | # feature is available. |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 309 | if(NOT IREE_HAL_DRIVER_LOCAL_SYNC AND NOT IREE_HAL_DRIVER_LOCAL_TASK) |
| 310 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF) |
| 311 | set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT OFF) |
| 312 | set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT OFF) |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 313 | set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF) |
| 314 | set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT OFF) |
Ben Vanik | 6e64b6e | 2022-06-07 09:14:53 -0700 | [diff] [blame] | 315 | endif() |
| 316 | |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 317 | 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] | 318 | option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT}) |
| 319 | option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT}) |
| 320 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 321 | 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}) |
| 322 | 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}) |
| 323 | |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 324 | if(IREE_BUILD_COMPILER) |
Scott Todd | f5660ee | 2024-04-22 16:16:37 -0700 | [diff] [blame] | 325 | # The compiler minimally requires the local task driver with the default |
| 326 | # (embedded elf) executable loader. This is used by the ConstEval component, |
| 327 | # which can also be used with VMVX or other loaders/devices. See issue#17070. |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 328 | set(IREE_HAL_DRIVER_LOCAL_TASK ON) |
Scott Todd | f5660ee | 2024-04-22 16:16:37 -0700 | [diff] [blame] | 329 | set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF ON) |
Scott Todd | 0f1f8eb | 2022-06-10 15:53:30 -0700 | [diff] [blame] | 330 | endif() |
| 331 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 332 | message(STATUS "IREE HAL drivers:") |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 333 | if(IREE_HAL_DRIVER_CUDA) |
| 334 | message(STATUS " - cuda") |
| 335 | endif() |
Lei Zhang | 5f2743b | 2024-03-20 16:39:24 -0700 | [diff] [blame] | 336 | if(IREE_HAL_DRIVER_HIP) |
| 337 | message(STATUS " - hip") |
| 338 | endif() |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 339 | if(IREE_HAL_DRIVER_LOCAL_SYNC) |
| 340 | message(STATUS " - local-sync") |
| 341 | endif() |
| 342 | if(IREE_HAL_DRIVER_LOCAL_TASK) |
| 343 | message(STATUS " - local-task") |
| 344 | endif() |
Lei Zhang | d1d03cb | 2023-08-07 13:52:56 -0400 | [diff] [blame] | 345 | if(IREE_HAL_DRIVER_METAL) |
| 346 | message(STATUS " - metal") |
| 347 | endif() |
Ben Vanik | a6043e2 | 2024-10-03 08:49:55 -0700 | [diff] [blame] | 348 | if(IREE_HAL_DRIVER_NULL) |
| 349 | message(STATUS " - null") |
| 350 | endif() |
| 351 | if(IREE_HAL_DRIVER_VULKAN) |
| 352 | message(STATUS " - vulkan") |
| 353 | endif() |
Ben Vanik | 4e6af05 | 2022-06-07 17:10:20 -0700 | [diff] [blame] | 354 | if(IREE_EXTERNAL_HAL_DRIVERS) |
| 355 | message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}") |
| 356 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 357 | |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 358 | message(STATUS "IREE HAL local executable library loaders:") |
Ben Vanik | 2e8540e | 2022-06-06 20:39:34 -0700 | [diff] [blame] | 359 | if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF) |
| 360 | message(STATUS " - embedded-elf") |
Ben Vanik | e305807 | 2022-06-06 19:21:44 -0700 | [diff] [blame] | 361 | endif() |
| 362 | if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY) |
| 363 | message(STATUS " - system-library") |
| 364 | endif() |
| 365 | if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE) |
| 366 | message(STATUS " - vmvx-module") |
| 367 | endif() |
| 368 | |
Ben Vanik | e19fc8e | 2023-04-14 16:08:01 -0700 | [diff] [blame] | 369 | message(STATUS "IREE HAL local executable plugin mechanisms:") |
| 370 | if(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF) |
| 371 | message(STATUS " - embedded-elf") |
| 372 | endif() |
| 373 | if(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY) |
| 374 | message(STATUS " - system-library") |
| 375 | endif() |
| 376 | |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 377 | #------------------------------------------------------------------------------- |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 378 | # Compiler Target Options |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 379 | # We try to keep the default build as simple as possible and disable heavy targets. |
| 380 | # Some compiler targets like CUDA will install external deps as needed at configure time. |
| 381 | # This can be changed with: |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 382 | # -DIREE_TARGET_BACKEND_DEFAULTS=OFF |
| 383 | #------------------------------------------------------------------------------- |
| 384 | |
| 385 | option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON) |
| 386 | |
| 387 | # The VMVX backend is always enabled. |
| 388 | cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF) |
| 389 | |
| 390 | # Supported default target backends. |
Scott Todd | 352da3f | 2022-07-20 15:25:11 -0700 | [diff] [blame] | 391 | cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 392 | 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] | 393 | 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] | 394 | cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF) |
| 395 | |
Stella Laurenzo | 58b5670 | 2023-10-05 15:05:58 -0700 | [diff] [blame] | 396 | # Default target backends that are not yet fully supported but are being brought up. |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 397 | cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
Stella Laurenzo | 58b5670 | 2023-10-05 15:05:58 -0700 | [diff] [blame] | 398 | |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 399 | # Supported target backends that are only available on certain platforms. |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 400 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT ${IREE_TARGET_BACKEND_DEFAULTS}) |
Scott Todd | 18a5485 | 2023-01-27 08:52:12 -0800 | [diff] [blame] | 401 | if(NOT IREE_CUDA_AVAILABLE) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 402 | set(IREE_TARGET_BACKEND_CUDA_DEFAULT OFF) |
| 403 | endif() |
maxbartel | f2bf602 | 2024-09-04 17:53:38 +0200 | [diff] [blame] | 404 | cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
Scott Todd | 9fa5de7 | 2023-01-23 14:40:18 -0800 | [diff] [blame] | 405 | |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 406 | # Non-default target backends either have additional dependencies or are |
| 407 | # experimental/niche in some fashion. |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 408 | # Disable WebGPU by default - it has complex deps and is under development. |
Ben Vanik | eeda5ca | 2024-02-27 14:18:32 -0800 | [diff] [blame] | 409 | cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU_SPIRV "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF) |
Scott Todd | 382fc63 | 2022-06-06 10:57:24 -0700 | [diff] [blame] | 410 | |
| 411 | #------------------------------------------------------------------------------- |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 412 | # Compiler Input Dialects |
| 413 | #------------------------------------------------------------------------------- |
| 414 | |
Jakub Kuderski | 0dbf086 | 2023-06-12 14:33:06 -0400 | [diff] [blame] | 415 | 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] | 416 | cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 417 | cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF) |
| 418 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 419 | if(IREE_BUILD_COMPILER) |
| 420 | message(STATUS "IREE compiler input dialects:") |
Jakub Kuderski | 0dbf086 | 2023-06-12 14:33:06 -0400 | [diff] [blame] | 421 | if(IREE_INPUT_STABLEHLO) |
| 422 | message(STATUS " - StableHLO") |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 423 | endif() |
| 424 | if(IREE_INPUT_TORCH) |
| 425 | message(STATUS " - Torch MLIR") |
| 426 | endif() |
| 427 | if(IREE_INPUT_TOSA) |
| 428 | message(STATUS " - TOSA") |
| 429 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 430 | endif() |
| 431 | |
| 432 | #------------------------------------------------------------------------------- |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 433 | # Compiler Output Formats |
| 434 | #------------------------------------------------------------------------------- |
| 435 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 436 | cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF) |
| 437 | |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 438 | if(IREE_BUILD_COMPILER) |
| 439 | message(STATUS "IREE compiler output formats:") |
| 440 | if(IREE_OUTPUT_FORMAT_C) |
Ben Vanik | 09630d6 | 2023-04-13 14:21:40 -0700 | [diff] [blame] | 441 | message(STATUS " - 'vm-c': textual C source module") |
Marius Brehler | 36f2451 | 2022-08-04 17:39:03 +0200 | [diff] [blame] | 442 | endif() |
| 443 | # The 'vm-bytecode' and 'vm-asm' formats are always enabled. |
Ben Vanik | 09630d6 | 2023-04-13 14:21:40 -0700 | [diff] [blame] | 444 | message(STATUS " - 'vm-bytecode': VM bytecode") |
| 445 | message(STATUS " - 'vm-asm': VM MLIR assembly") |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 446 | endif() |
Scott Todd | e23d4a7 | 2022-07-27 14:16:39 -0700 | [diff] [blame] | 447 | |
Scott Todd | 2a1925c | 2022-06-13 10:03:52 -0700 | [diff] [blame] | 448 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 449 | # IREE compilation toolchain configuration |
| 450 | #------------------------------------------------------------------------------- |
| 451 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 452 | option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 453 | option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 454 | option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF) |
Jakub Kuderski | 068b172 | 2022-07-27 18:14:59 -0400 | [diff] [blame] | 455 | option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF) |
Stella Laurenzo | deb4805 | 2022-11-25 10:41:46 -0800 | [diff] [blame] | 456 | option(IREE_ENABLE_SPLIT_DWARF "Enable gsplit-dwarf for debug information if the platform supports it" OFF) |
| 457 | 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] | 458 | option(IREE_LINK_COMPILER_SHARED_LIBRARY "Links IREE tools using the compiler compiled into a shared library" ON) |
Rechie Kho | dd17612 | 2024-01-17 06:40:18 +0800 | [diff] [blame] | 459 | option(IREE_ENABLE_WERROR_FLAG "Enable `-Werror` flag, treat error as warning" ON) |
Gyungmin Myung | 00c9fc2 | 2024-03-02 23:51:46 +0900 | [diff] [blame] | 460 | option(IREE_ENABLE_POSITION_INDEPENDENT_CODE "Enable position independent code" TRUE) |
bjacob | 7cf5b84 | 2022-04-04 16:48:04 -0400 | [diff] [blame] | 461 | |
Scott Todd | 8678138 | 2023-02-07 14:11:52 -0800 | [diff] [blame] | 462 | if(IREE_LINK_COMPILER_SHARED_LIBRARY AND IREE_ENABLE_COMPILER_TRACING) |
| 463 | message(SEND_ERROR |
| 464 | "IREE_ENABLE_COMPILER_TRACING requires " |
| 465 | "-DIREE_LINK_COMPILER_SHARED_LIBRARY=OFF (the compiler library must not " |
| 466 | "be unloaded before Tracy finishes, static linking is one workaround)") |
| 467 | endif() |
| 468 | |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 469 | option(IREE_ENABLE_CCACHE |
| 470 | "[DEPRECATED: Use CMAKE_<LANG>_COMPILER_LAUNCHER configure options or environment variables instead.] Use ccache if installed." |
| 471 | OFF) |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 472 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 473 | if(IREE_ENABLE_CCACHE) |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 474 | message(WARNING |
| 475 | "IREE_ENABLE_CCACHE is deprecated. Use CMAKE_<LANG>_COMPILER_LAUNCHER" |
| 476 | " configure options or environment variables instead.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 477 | find_program(CCACHE_PROGRAM ccache) |
| 478 | if(CCACHE_PROGRAM) |
| 479 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") |
Geoffrey Martin-Noble | 61ea1ed | 2022-11-23 16:25:57 -0800 | [diff] [blame] | 480 | else() |
| 481 | message(SEND_ERROR |
| 482 | "IREE_ENABLE_CCACHE was set, but executable `ccache` was not found.") |
bjacob | e694d95 | 2020-11-03 12:05:35 -0500 | [diff] [blame] | 483 | endif() |
| 484 | endif() |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 485 | |
Gyungmin Myung | 00c9fc2 | 2024-03-02 23:51:46 +0900 | [diff] [blame] | 486 | set (CMAKE_POSITION_INDEPENDENT_CODE ${IREE_ENABLE_POSITION_INDEPENDENT_CODE}) |
| 487 | |
Geoffrey Martin-Noble | 3fa4f8d | 2021-09-10 09:25:27 -0700 | [diff] [blame] | 488 | 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] | 489 | |
| 490 | #------------------------------------------------------------------------------- |
| 491 | # IREE assertions |
| 492 | # We don't love the way this is done, but we have to line it up with how LLVM |
| 493 | # does it and not diverge, since all implementations and all header users must |
| 494 | # have the same definition of NDEBUG. |
| 495 | # |
| 496 | # LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then |
| 497 | # conditions itself to only update flags if not building Debug. We just let |
| 498 | # IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the |
| 499 | # flags in appropriate build types. |
| 500 | # |
| 501 | # If IREE_ENABLE_ASSERTIONS is set ON manually, then |
| 502 | # - NDEBUG must be undefined |
| 503 | # - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties |
| 504 | # from mucking with globals. |
| 505 | # |
| 506 | # Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done |
| 507 | # at the top level to avoid divergence. |
| 508 | #------------------------------------------------------------------------------- |
| 509 | |
| 510 | option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF) |
| 511 | |
| 512 | # Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if |
| 513 | # CMAKE_BUILD_TYPE is not Debug). |
| 514 | function(iree_fix_ndebug) |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 515 | string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE) |
| 516 | if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") |
Ben Vanik | a6043e2 | 2024-10-03 08:49:55 -0700 | [diff] [blame] | 517 | # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. |
| 518 | foreach(_FLAGS_VAR_TO_SCRUB |
| 519 | CMAKE_CXX_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE} |
| 520 | CMAKE_C_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE}) |
| 521 | set(_ORIGINAL_FLAGS "${${_FLAGS_VAR_TO_SCRUB}}") |
| 522 | string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " _ALTERED_FLAGS "${_ORIGINAL_FLAGS}") |
| 523 | if(NOT "${_ORIGINAL_FLAGS}" STREQUAL "${_ALTERED_FLAGS}") |
| 524 | message(STATUS |
| 525 | "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${_FLAGS_VAR_TO_SCRUB}: '${_ORIGINAL_FLAGS}' -> '${_ALTERED_FLAGS}'") |
| 526 | set(${_FLAGS_VAR_TO_SCRUB} "${_ALTERED_FLAGS}" PARENT_SCOPE) |
| 527 | endif() |
| 528 | endforeach() |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 529 | |
Ben Vanik | a6043e2 | 2024-10-03 08:49:55 -0700 | [diff] [blame] | 530 | # Make sure that LLVM doesn't add its own logic for assertion disabling. |
| 531 | # We'd like to make sure that we are not dueling over globals. |
| 532 | set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE) |
Stella Laurenzo | 5b63912 | 2021-06-18 14:44:10 -0700 | [diff] [blame] | 533 | endif() |
| 534 | endfunction() |
| 535 | iree_fix_ndebug() |
| 536 | |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 537 | #------------------------------------------------------------------------------- |
Lei Zhang | 7e253da | 2020-06-10 07:51:19 -0700 | [diff] [blame] | 538 | # IREE utility definitions |
Lei Zhang | 0d281b7 | 2020-06-01 20:00:23 -0400 | [diff] [blame] | 539 | #------------------------------------------------------------------------------- |
| 540 | |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 541 | list(APPEND CMAKE_MODULE_PATH |
| 542 | ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/ |
Scott Todd | d1620f0 | 2021-12-22 14:55:38 -0800 | [diff] [blame] | 543 | ) |
| 544 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 545 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 546 | include(iree_copts) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 547 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 548 | include(iree_cc_library) |
| 549 | include(iree_cc_test) |
Scott Todd | 20d746a | 2023-01-12 09:11:59 -0800 | [diff] [blame] | 550 | include(iree_import_binary) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 551 | include(iree_install_support) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 552 | include(iree_external_cmake_options) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 553 | include(iree_tablegen_library) |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 554 | include(iree_tablegen_doc) |
CindyLiu | 40ed02d | 2021-04-22 16:16:28 +0000 | [diff] [blame] | 555 | include(iree_c_embed_data) |
Ben Vanik | 7f6c57c | 2023-02-07 18:04:32 -0800 | [diff] [blame] | 556 | include(iree_bitcode_library) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 557 | include(iree_bytecode_module) |
Marius Brehler | 46e8331 | 2021-03-25 00:11:39 +0100 | [diff] [blame] | 558 | include(iree_c_module) |
Stella Laurenzo | 94363e2 | 2020-12-15 13:46:14 -0800 | [diff] [blame] | 559 | include(iree_python) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 560 | include(iree_lit_test) |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 561 | include(iree_llvm) |
Geoffrey Martin-Noble | 4526dcc | 2020-03-09 11:59:52 -0700 | [diff] [blame] | 562 | include(iree_add_all_subdirs) |
Geoffrey Martin-Noble | e5fd5b5 | 2020-03-31 11:31:30 -0700 | [diff] [blame] | 563 | include(iree_check_test) |
Prashant Kumar | 3cce7fc | 2024-04-04 23:32:36 +0530 | [diff] [blame] | 564 | include(iree_e2e_generated_runner_test) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 565 | include(iree_native_test) |
Geoffrey Martin-Noble | 2811e50 | 2022-01-25 09:44:40 -0800 | [diff] [blame] | 566 | include(iree_cc_binary_benchmark) |
Scott Todd | 434ff0e | 2021-12-21 10:38:36 -0800 | [diff] [blame] | 567 | include(iree_hal_cts_test_suite) |
CindyLiu | ae72b95 | 2022-08-23 15:26:08 -0700 | [diff] [blame] | 568 | include(iree_static_linker_test) |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 569 | include(iree_plugin_register) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 570 | |
Stella Laurenzo | be0f1e1 | 2023-04-03 13:34:38 -0700 | [diff] [blame] | 571 | # Default any sub-tree which doesn't provide its own package namespacing |
| 572 | # to derive it relative to this directory and prefixed with iree/. |
| 573 | set(IREE_PACKAGE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}") |
Lei Zhang | 923535d | 2023-04-06 18:07:43 -0400 | [diff] [blame] | 574 | set(IREE_PACKAGE_ROOT_PREFIX "iree") |
Stella Laurenzo | be0f1e1 | 2023-04-03 13:34:38 -0700 | [diff] [blame] | 575 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 576 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 577 | # Experimental WebGPU HAL driver |
| 578 | # Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=webgpu |
| 579 | #------------------------------------------------------------------------------- |
| 580 | |
| 581 | iree_register_external_hal_driver( |
| 582 | NAME |
| 583 | webgpu |
Peyman B | 66b10cc | 2023-11-15 17:14:14 +0100 | [diff] [blame] | 584 | SOURCE_DIR |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 585 | "${CMAKE_CURRENT_SOURCE_DIR}/experimental/webgpu" |
Scott Todd | 50aa2cc | 2023-11-27 10:28:47 -0800 | [diff] [blame] | 586 | BINARY_DIR |
| 587 | "${CMAKE_CURRENT_BINARY_DIR}/experimental/webgpu" |
Stella Laurenzo | 2eb6862 | 2023-11-10 17:04:46 -0800 | [diff] [blame] | 588 | DRIVER_TARGET |
| 589 | iree::experimental::webgpu::registration |
| 590 | REGISTER_FN |
| 591 | iree_hal_webgpu_driver_module_register |
| 592 | ) |
| 593 | |
| 594 | #------------------------------------------------------------------------------- |
Lei Zhang | e88470f | 2020-09-08 13:21:09 -0400 | [diff] [blame] | 595 | # IREE compilation flags |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 596 | #------------------------------------------------------------------------------- |
| 597 | |
Lei Zhang | dd21f32 | 2020-09-10 10:47:33 -0400 | [diff] [blame] | 598 | iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST}) |
| 599 | 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] | 600 | |
| 601 | set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE) |
| 602 | set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE) |
| 603 | set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE) |
| 604 | set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE) |
| 605 | mark_as_advanced( |
| 606 | CMAKE_CXX_FLAGS_FASTBUILD |
| 607 | CMAKE_C_FLAGS_FASTBUILD |
| 608 | CMAKE_EXE_LINKER_FLAGS_FASTBUILD |
| 609 | CMAKE_SHARED_LINKER_FLAGS_FASTBUILD |
| 610 | ) |
| 611 | |
Scott Todd | 7649dee | 2022-07-18 11:31:46 -0700 | [diff] [blame] | 612 | # Override the system's default linker. |
| 613 | # See also: https://llvm.org/docs/CMake.html#llvm-use-linker. |
| 614 | set(IREE_USE_LINKER "" CACHE STRING "") |
| 615 | # Equivalent to setting -DIREE_USE_LINKER=lld. |
| 616 | # Note that unlike LLVM's LLVM_ENABLE_LLD, this does _not_ build lld. You will |
| 617 | # need to either install a recent version of lld or build it from source prior |
| 618 | # to setting this option. See also: https://lld.llvm.org/#using-lld. |
| 619 | # This option is disabled on Apple platforms, where lld is not supported. |
| 620 | cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF) |
| 621 | |
Scott Todd | 29d654e | 2020-06-11 15:24:17 -0700 | [diff] [blame] | 622 | include(iree_setup_toolchain) |
| 623 | |
| 624 | #------------------------------------------------------------------------------- |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 625 | # Python |
| 626 | # If building features that require Python development, find them early in |
| 627 | # one invocation (some CMake versions are sensitive to resolving out of order). |
| 628 | # Otherwise, for features that just require the interpreter, find that alone. |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 629 | #------------------------------------------------------------------------------- |
| 630 | |
Stella Laurenzo | 29032b8 | 2021-10-14 15:21:44 -0700 | [diff] [blame] | 631 | if(IREE_BUILD_PYTHON_BINDINGS) |
| 632 | # After CMake 3.18, we are able to limit the scope of the search to just |
| 633 | # Development.Module. Searching for Development will fail in situations where |
| 634 | # the Python libraries are not available. When possible, limit to just |
| 635 | # Development.Module. |
| 636 | # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode |
Scott Todd | a24c8c5 | 2022-05-17 09:22:47 -0700 | [diff] [blame] | 637 | # |
| 638 | # Configuring the Development.Module is flaky in multi-project setups. |
| 639 | # "Bootstrapping" by first looking for the optional Development component |
| 640 | # seems to be robust generally. |
| 641 | # See: https://reviews.llvm.org/D118148 |
Han-Chung Wang | 9ed3dab | 2023-08-30 14:25:24 -0700 | [diff] [blame] | 642 | # If building Python packages, we have a hard requirement on 3.9+. |
| 643 | find_package(Python3 3.9 COMPONENTS Interpreter Development NumPy) |
| 644 | find_package(Python3 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED) |
Stella Laurenzo | acf0b27 | 2023-06-26 21:25:48 -0700 | [diff] [blame] | 645 | # Some parts of the build use FindPython instead of FindPython3. Why? No |
| 646 | # one knows, but they are different. So make sure to bootstrap this one too. |
| 647 | # Not doing this here risks them diverging, which on multi-Python systems, |
Marius Brehler | 258cdb8 | 2024-10-17 20:20:44 +0200 | [diff] [blame] | 648 | # can be troublesome. Note that pybind11 and nanobind require FindPython. |
Stella Laurenzo | acf0b27 | 2023-06-26 21:25:48 -0700 | [diff] [blame] | 649 | set(Python_EXECUTABLE "${Python3_EXECUTABLE}") |
Han-Chung Wang | 9ed3dab | 2023-08-30 14:25:24 -0700 | [diff] [blame] | 650 | find_package(Python 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED) |
Stella Laurenzo | 3149b6d | 2021-10-24 18:45:17 -0700 | [diff] [blame] | 651 | elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS) |
Stella Laurenzo | a3e97f1 | 2020-12-05 23:29:13 -0800 | [diff] [blame] | 652 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
Stella Laurenzo | acf0b27 | 2023-06-26 21:25:48 -0700 | [diff] [blame] | 653 | set(Python_EXECUTABLE "${Python3_EXECUTABLE}") |
| 654 | find_package(Python COMPONENTS Interpreter REQUIRED) |
| 655 | endif() |
| 656 | |
| 657 | if(NOT "${Python_EXECUTABLE}" STREQUAL "${Python3_EXECUTABLE}") |
| 658 | 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] | 659 | endif() |
| 660 | |
| 661 | #------------------------------------------------------------------------------- |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 662 | # Check if git submodules have been initialized. |
| 663 | # This will only run if python3 is available. |
| 664 | #------------------------------------------------------------------------------- |
| 665 | |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 666 | option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON) |
| 667 | |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 668 | find_package(Python3 COMPONENTS Interpreter QUIET) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 669 | find_package(Git) |
Marius Brehler | 776d7e6 | 2021-12-21 22:50:52 +0100 | [diff] [blame] | 670 | if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND) |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 671 | # Only check submodule status when the git commit changes. |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 672 | execute_process( |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 673 | COMMAND git rev-parse --short HEAD |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 674 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 675 | RESULT_VARIABLE SHORT_HASH_RESULT |
| 676 | OUTPUT_VARIABLE SHORT_HASH) |
| 677 | string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}") |
Scott Todd | 2a8cd3b | 2021-12-13 11:58:44 -0800 | [diff] [blame] | 678 | 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] | 679 | if(NOT IREE_BUILD_COMPILER) |
| 680 | set(CHECK_SUBMODULE_ARGS "--runtime_only") |
| 681 | endif() |
Scott Todd | e5b269a | 2021-11-16 15:25:02 -0800 | [diff] [blame] | 682 | execute_process( |
CindyLiu | 0e8fdc6 | 2022-10-14 09:35:44 -0700 | [diff] [blame] | 683 | 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] | 684 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 685 | RESULT_VARIABLE SUBMODULE_INIT_RESULT |
| 686 | ) |
| 687 | if(NOT SUBMODULE_INIT_RESULT EQUAL "0") |
| 688 | message(FATAL_ERROR "check_submodule_init.py failed, see the logs above") |
| 689 | else() |
| 690 | set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE) |
| 691 | endif() |
Niloy Sikdar | 47238df | 2021-07-28 23:37:33 +0530 | [diff] [blame] | 692 | endif() |
| 693 | endif() |
| 694 | |
| 695 | #------------------------------------------------------------------------------- |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 696 | # IREE top-level targets |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 697 | # We define these here because various things in the build tree adds |
| 698 | # dependencies to them. |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 699 | #------------------------------------------------------------------------------- |
| 700 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 701 | if(IREE_BUILD_DOCS) |
Scott Todd | 96d9213 | 2023-06-12 15:45:19 -0700 | [diff] [blame] | 702 | # Define a top-level custom target to drive generating documentation files. |
| 703 | # Add to the default target given that docs were explicitly requested. |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 704 | add_custom_target(iree-doc ALL) |
| 705 | endif() |
| 706 | |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 707 | # Samples may require additional files to be built/configured and will add |
| 708 | # dependencies to this target. |
| 709 | # Note: These will be automatically built with test dependencies |
| 710 | # (`iree-test-deps`). |
| 711 | add_custom_target(iree-sample-deps |
| 712 | COMMENT |
| 713 | "Building IREE sample data targets" |
| 714 | ) |
| 715 | |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 716 | # Testing rules that require generation will add dependencies to this target. |
| 717 | # This allows them to be EXCLUDE_FROM_ALL but still invokable. |
Jakub Kuderski | 3f76468 | 2023-02-07 17:14:23 -0500 | [diff] [blame] | 718 | add_custom_target(iree-test-deps |
| 719 | COMMENT |
| 720 | "Building IREE test deps" |
| 721 | DEPENDS |
| 722 | iree-sample-deps |
| 723 | ) |
Stella Laurenzo | 74b04b7 | 2022-03-02 10:21:11 -0800 | [diff] [blame] | 724 | |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 725 | # Testing rules that generate test scripts for iree-run-module-test will add |
| 726 | # dependencies to this target. It is a subset of `iree-test-deps`. |
| 727 | add_custom_target(iree-run-module-test-deps |
| 728 | COMMENT |
| 729 | "Building IREE run module test targets" |
| 730 | ) |
| 731 | |
Stella Laurenzo | e2dfc65 | 2023-02-15 18:12:03 -0800 | [diff] [blame] | 732 | # Convenience target for running IREE tests. |
| 733 | add_custom_target(iree-run-tests |
| 734 | COMMENT |
| 735 | "Run IREE unit tests" |
| 736 | WORKING_DIRECTORY |
| 737 | "${CMAKE_CURRENT_BINARY_DIR}" |
| 738 | USES_TERMINAL |
| 739 | COMMAND |
| 740 | "${CMAKE_COMMAND}" -E echo |
| 741 | "The 'iree-run-tests' target is a helper for running ctest. For advanced" |
| 742 | "options, build dependencies and invoke ctest independently as in:" |
| 743 | COMMAND |
| 744 | "${CMAKE_COMMAND}" -E echo |
| 745 | " \\(cd ${CMAKE_CURRENT_BINARY_DIR} \\&\\& cmake --build . --target iree-test-deps \\&\\& ctest --output-on-failure\\)" |
| 746 | COMMAND |
| 747 | "${CMAKE_COMMAND}" -E echo |
| 748 | "Run tests in parallel by setting a variable like CTEST_PARALLEL_LEVEL=25." |
| 749 | COMMAND |
| 750 | "${CMAKE_CTEST_COMMAND}" |
| 751 | --output-on-failure |
| 752 | ) |
| 753 | add_dependencies(iree-run-tests iree-test-deps) |
| 754 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 755 | #------------------------------------------------------------------------------- |
| 756 | # CUDA configuration for both the compiler and runtime. |
| 757 | # We do this at the top level so that we can fail fast and make global |
| 758 | # decisions that effect both compiler and runtime. It also helps with error |
| 759 | # messaging to do this all in one place, since we can provide very targeted |
| 760 | # advice. |
| 761 | #------------------------------------------------------------------------------- |
| 762 | |
| 763 | set(IREE_CUDA_LIBDEVICE_PATH "" CACHE FILEPATH "Absolute path to an appropriate libdevice.*.bc (needed to build the IREE cuda compiler target)") |
| 764 | |
| 765 | # If any CUDA features are being built, try to locate a CUDA SDK. We will fall |
| 766 | # back to this as needed for specific features. |
| 767 | if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA) |
| 768 | add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL) |
| 769 | endif() |
| 770 | |
| 771 | #------------------------------------------------------------------------------- |
| 772 | # MLIR/LLVM Dependency |
| 773 | #------------------------------------------------------------------------------- |
| 774 | |
Stella Laurenzo | 9c5b57a | 2024-10-23 22:57:45 -0700 | [diff] [blame] | 775 | # Both the IREE and MLIR Python bindings require pybind11. We initialize it here |
| 776 | # at the top level so that everything uses ours consistently. |
| 777 | if(IREE_BUILD_PYTHON_BINDINGS AND IREE_BUILD_COMPILER) |
| 778 | set(pybind11_VERSION 2.13.6) |
| 779 | include(FetchContent) |
| 780 | FetchContent_Declare( |
| 781 | pybind11 |
| 782 | GIT_REPOSITORY https://github.com/pybind/pybind11 |
| 783 | GIT_TAG v${pybind11_VERSION} |
| 784 | ) |
| 785 | set(PYBIND11_FINDPYTHON ON) |
| 786 | FetchContent_MakeAvailable(pybind11) |
| 787 | # pybind11 source fetches do not include find_package integration, which is |
| 788 | # a shame since sub-projects can require that to work. If we were using |
| 789 | # CMake 3.24, we could just add OVERRIDE_FIND_PACKAGE to the |
| 790 | # FetchContent_Declare call above and it would take care of doing the |
| 791 | # following to let subsequent sub-project find_package calls to resolve |
| 792 | # successfully. |
| 793 | set(pybind11_DIR "${pybind11_BINARY_DIR}") |
| 794 | file(WRITE "${pybind11_BINARY_DIR}/pybind11Config.cmake" "") |
| 795 | file(WRITE "${pybind11_BINARY_DIR}/pybind11ConfigVersion.cmake" |
| 796 | "set(PACKAGE_VERSION ${pybind11_VERSION})\nset(PACKAGE_VERSION_COMPATIBLE TRUE)") |
| 797 | endif() |
| 798 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 799 | if(NOT IREE_BUILD_COMPILER) |
| 800 | message(STATUS "Not adding LLVM/MLIR because the configuration does not require it") |
| 801 | else() |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 802 | # Force enable BUILD_SHARED_LIBS for the compiler if instructed. |
| 803 | set(_IREE_ORIG_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) |
| 804 | if(IREE_COMPILER_BUILD_SHARED_LIBS) |
| 805 | set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) |
| 806 | endif() |
| 807 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 808 | # Get the main LLVM deps. |
| 809 | if(IREE_BUILD_BUNDLED_LLVM) |
| 810 | iree_llvm_configure_bundled() |
| 811 | else() |
| 812 | iree_llvm_configure_installed() |
| 813 | endif() |
| 814 | |
| 815 | # Also add a library that can be depended on to get LLVM includes setup |
| 816 | # properly. bazel_to_cmake targets this for some header only pseudo deps. |
| 817 | add_library(IREELLVMIncludeSetup INTERFACE) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 818 | foreach(_d ${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS} ${LLD_INCLUDE_DIRS}) |
| 819 | # BUILD_INTERFACE only works one at a time. |
| 820 | target_include_directories(IREELLVMIncludeSetup INTERFACE |
| 821 | $<BUILD_INTERFACE:${_d}> |
| 822 | ) |
| 823 | endforeach() |
| 824 | iree_install_targets( |
| 825 | TARGETS IREELLVMIncludeSetup |
| 826 | COMPONENT IREEPublicLibraries-Compiler |
| 827 | EXPORT_SET Compiler |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 828 | ) |
| 829 | |
| 830 | # Splice the includes setup into base LLVM libraries so that using them |
| 831 | # gets everything nice and tidy. It would be super if some day, LLVM |
| 832 | # libraries set their right usage requirements for includes. In the meantime |
| 833 | # we add usage requirements to libraries at the root of all things LLVM. |
| 834 | iree_llvm_add_usage_requirements(LLVMSupport IREELLVMIncludeSetup) |
| 835 | iree_llvm_add_usage_requirements(MLIRSupport IREELLVMIncludeSetup) |
| 836 | |
Scott Todd | 53af681 | 2023-11-27 10:33:08 -0800 | [diff] [blame] | 837 | # Add external projects. |
| 838 | |
| 839 | message(STATUS "Configuring llvm-external-projects/mlir-iree-dialects") |
| 840 | list(APPEND CMAKE_MESSAGE_INDENT " ") |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 841 | 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] | 842 | list(POP_BACK CMAKE_MESSAGE_INDENT) |
| 843 | |
Stella Laurenzo | fd9cd2f | 2023-11-01 16:22:00 -0700 | [diff] [blame] | 844 | if(IREE_INPUT_STABLEHLO) |
Scott Todd | 53af681 | 2023-11-27 10:33:08 -0800 | [diff] [blame] | 845 | message(STATUS "Configuring third_party/stablehlo") |
| 846 | list(APPEND CMAKE_MESSAGE_INDENT " ") |
Stella Laurenzo | fd9cd2f | 2023-11-01 16:22:00 -0700 | [diff] [blame] | 847 | 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] | 848 | list(POP_BACK CMAKE_MESSAGE_INDENT) |
Stella Laurenzo | fd9cd2f | 2023-11-01 16:22:00 -0700 | [diff] [blame] | 849 | endif() |
Ben Vanik | e3578d5 | 2023-09-12 09:35:11 -0700 | [diff] [blame] | 850 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 851 | # Ensure that LLVM-based dependencies needed for testing are included. |
| 852 | add_dependencies(iree-test-deps FileCheck) |
| 853 | if(IREE_LLD_TARGET) |
| 854 | add_dependencies(iree-test-deps ${IREE_LLD_TARGET}) |
| 855 | endif() |
| 856 | if(IREE_CLANG_TARGET) |
| 857 | add_dependencies(iree-test-deps ${IREE_CLANG_TARGET}) |
| 858 | endif() |
Stella Laurenzo | 289b9a1 | 2023-02-24 13:06:32 -0800 | [diff] [blame] | 859 | |
| 860 | set(BUILD_SHARED_LIBS ${_IREE_ORIG_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 861 | endif() |
| 862 | |
| 863 | #------------------------------------------------------------------------------- |
| 864 | # Other dependencies |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 865 | # By default we bundle a number of dependencies needed to build the project. |
| 866 | # When bundled like this, they are installed into the IREEBundledLibraries |
| 867 | # component and exported to their subsystem which requires them (if a static |
| 868 | # dep from the public API): "Runtime" or "Compiler". |
| 869 | # |
| 870 | # Some deps have a usable CMake build, and we add_subdirectory these, manually |
| 871 | # using iree_install_targets to include them in our installation. Others require |
| 872 | # custom CMake and these are in the build_tools/third_party directory. |
| 873 | # |
| 874 | # TODO: We should have a mode that purely uses find_package for OS friendly |
| 875 | # packaging/externalizing deps. |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 876 | #------------------------------------------------------------------------------- |
| 877 | |
| 878 | include(external_cc_library) |
| 879 | include(flatbuffer_c_library) |
| 880 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 881 | add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL) |
Scott Todd | 3d6a8ee | 2024-05-23 14:49:54 -0700 | [diff] [blame] | 882 | |
| 883 | if((IREE_ENABLE_RUNTIME_TRACING OR IREE_ENABLE_COMPILER_TRACING) AND |
| 884 | IREE_TRACING_PROVIDER STREQUAL "tracy") |
| 885 | message(STATUS "Configuring third_party/tracy") |
| 886 | list(APPEND CMAKE_MESSAGE_INDENT " ") |
| 887 | add_subdirectory(third_party/tracy EXCLUDE_FROM_ALL) |
| 888 | list(POP_BACK CMAKE_MESSAGE_INDENT) |
| 889 | iree_install_targets( |
| 890 | TARGETS TracyClient |
| 891 | COMPONENT IREEBundledLibraries |
| 892 | EXPORT_SET Runtime |
| 893 | ) |
| 894 | endif() |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 895 | |
| 896 | iree_set_googletest_cmake_options() |
| 897 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
| 898 | |
| 899 | if(IREE_ENABLE_THREADING) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 900 | # Benchmark. |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 901 | iree_set_benchmark_cmake_options() |
| 902 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 903 | iree_install_targets( |
| 904 | TARGETS benchmark |
| 905 | COMPONENT IREEBundledLibraries |
| 906 | EXPORT_SET Runtime |
| 907 | ) |
| 908 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 909 | if(IREE_ENABLE_CPUINFO) |
| 910 | iree_set_cpuinfo_cmake_options() |
| 911 | add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 912 | iree_install_targets( |
| 913 | TARGETS cpuinfo |
| 914 | COMPONENT IREEBundledLibraries |
| 915 | EXPORT_SET Runtime |
| 916 | ) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 917 | endif() |
| 918 | endif() |
| 919 | |
| 920 | # This defines the iree-flatcc-cli target, so we don't use EXCLUDE_FROM_ALL. |
| 921 | add_subdirectory(build_tools/third_party/flatcc) |
| 922 | |
| 923 | if(IREE_HAL_DRIVER_CUDA) |
| 924 | add_subdirectory(build_tools/third_party/nccl EXCLUDE_FROM_ALL) |
| 925 | endif() |
| 926 | |
Boian Petkantchin | 4132d2e | 2024-05-17 08:47:33 -0700 | [diff] [blame] | 927 | if(IREE_HAL_DRIVER_HIP) |
| 928 | add_subdirectory(build_tools/third_party/rccl EXCLUDE_FROM_ALL) |
| 929 | endif() |
| 930 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 931 | if(IREE_HAL_DRIVER_VULKAN) |
| 932 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 933 | iree_install_targets( |
| 934 | TARGETS Vulkan-Headers |
| 935 | COMPONENT IREEBundledLibraries |
| 936 | EXPORT_SET Runtime |
| 937 | ) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 938 | endif() |
| 939 | |
| 940 | if(IREE_BUILD_COMPILER) |
Jakub Kuderski | 3546f2a | 2023-06-14 13:18:44 -0400 | [diff] [blame] | 941 | add_subdirectory(build_tools/third_party/stablehlo EXCLUDE_FROM_ALL) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 942 | endif() |
| 943 | |
| 944 | if(IREE_BUILD_TESTS) |
| 945 | include(iree_configure_testing) |
| 946 | endif() |
| 947 | |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 948 | if(IREE_TARGET_BACKEND_METAL_SPIRV) |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 949 | # 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] | 950 | iree_set_spirv_cross_cmake_options() |
Stella Laurenzo | 9be15aa | 2023-02-21 17:00:29 -0800 | [diff] [blame] | 951 | add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL) |
| 952 | endif() |
| 953 | |
Lei Zhang | 22f0e24 | 2020-03-30 12:09:20 -0700 | [diff] [blame] | 954 | #------------------------------------------------------------------------------- |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 955 | # IREE top-level libraries |
| 956 | #------------------------------------------------------------------------------- |
| 957 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 958 | if(IREE_ENABLE_CLANG_TIDY) |
| 959 | set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*) |
| 960 | endif() |
| 961 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 962 | add_subdirectory(build_tools/embed_data/) |
| 963 | |
Jacques Pienaar | 702929a | 2022-12-30 14:46:22 -0800 | [diff] [blame] | 964 | # tools/ can depend on compiler/ and runtime/. |
| 965 | # Note: tools sub directory is added before compiler/ so that phony targets for |
| 966 | # files with the same names from different rules are disambiguated towards |
| 967 | # those in tools/. |
| 968 | add_subdirectory(tools) |
Stella Laurenzo | 309dc5b | 2023-02-22 23:07:43 -0800 | [diff] [blame] | 969 | add_subdirectory(compiler) |
Scott Todd | 4f16b99 | 2022-05-17 10:33:53 -0700 | [diff] [blame] | 970 | add_subdirectory(runtime) |
| 971 | |
Scott Todd | 315e238 | 2024-01-30 13:35:51 -0800 | [diff] [blame] | 972 | # Note: Test deps are not built as part of all (use the iree-test-deps target). |
| 973 | add_subdirectory(tests EXCLUDE_FROM_ALL) |
| 974 | |
Rob Suderman | d42e002 | 2022-06-08 16:38:45 -0700 | [diff] [blame] | 975 | if(IREE_ENABLE_CLANG_TIDY) |
| 976 | set(CMAKE_CXX_CLANG_TIDY "") |
| 977 | endif() |
| 978 | |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 979 | if(IREE_BUILD_TRACY) |
Ben Vanik | 77a8741 | 2023-10-09 14:46:28 -0700 | [diff] [blame] | 980 | if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux") |
| 981 | 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] | 982 | endif() |
| 983 | add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy) |
| 984 | if(NOT TARGET IREETracyCaptureServer) |
| 985 | message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.") |
| 986 | endif() |
| 987 | endif() |
| 988 | |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 989 | # Order constraint: The python bindings install tools targets from tools/ |
Stella Laurenzo | d3770ff | 2021-10-18 22:54:18 -0700 | [diff] [blame] | 990 | # and tracy, and must come after it. |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 991 | if(IREE_BUILD_PYTHON_BINDINGS) |
Stella Laurenzo | 6012859 | 2022-04-17 21:52:09 -0700 | [diff] [blame] | 992 | # Write out a .env file to make IDEs and developers happy. |
| 993 | # 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] | 994 | # it gets clobbered, it is fine (it is also ignored in .gitignore). |
Stella Laurenzo | 41a2ceb | 2022-04-29 12:49:36 -0700 | [diff] [blame] | 995 | 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] | 996 | file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
| 997 | file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}") |
Scott Todd | 2fe00a5 | 2023-11-09 10:46:49 -0800 | [diff] [blame] | 998 | # Similarly, write out .env.bat and .env.ps1 for Windows. |
Scott Todd | fe9cb17 | 2022-12-08 09:17:52 -0800 | [diff] [blame] | 999 | set(_PYTHONPATH_ENV_BAT "set PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n") |
| 1000 | 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] | 1001 | set(_PYTHONPATH_ENV_PS1 "$env:PYTHONPATH = '$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>'\n") |
| 1002 | 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] | 1003 | endif() |
| 1004 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 1005 | if(IREE_BUILD_BINDINGS_TFLITE) |
Scott Todd | ada25e6 | 2022-05-03 16:16:15 -0700 | [diff] [blame] | 1006 | add_subdirectory(runtime/bindings/tflite) |
Ben Vanik | cd1132f | 2021-01-29 15:58:17 -0800 | [diff] [blame] | 1007 | endif() |
| 1008 | |
Scott Todd | 1a1aea6 | 2022-04-28 09:12:11 -0700 | [diff] [blame] | 1009 | if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES) |
Scott Todd | 15fce0a | 2022-02-14 12:43:23 -0800 | [diff] [blame] | 1010 | add_subdirectory(experimental/web) |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 1011 | endif() |
| 1012 | |
Benoit Jacob | 655b71a | 2024-04-23 11:07:38 -0400 | [diff] [blame] | 1013 | if(IREE_BUILD_EXPERIMENTAL_HAL_EXECUTABLE_LIBRARY_CALL_HOOKS) |
| 1014 | add_subdirectory(experimental/hal_executable_library_call_hooks) |
| 1015 | endif() |
| 1016 | |
Stella Laurenzo | 03e48db | 2020-06-11 18:35:13 -0700 | [diff] [blame] | 1017 | set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}" |
| 1018 | CACHE INTERNAL "IREE: Include Directories" FORCE) |
Stella Laurenzo | 688670f | 2021-09-24 18:16:25 -0700 | [diff] [blame] | 1019 | |
Jerry Wu | 623d174 | 2022-03-31 18:16:02 +0000 | [diff] [blame] | 1020 | #------------------------------------------------------------------------------- |
Stella Laurenzo | c6092c4 | 2023-03-25 19:55:37 -0700 | [diff] [blame] | 1021 | # Optional features |
Stella Laurenzo | 3b44a0a | 2022-04-18 19:57:57 -0700 | [diff] [blame] | 1022 | #------------------------------------------------------------------------------- |
| 1023 | |
Scott Todd | 4c022df | 2022-05-10 16:55:18 -0700 | [diff] [blame] | 1024 | # samples/ can depend on anything, so we include it last |
Stella Laurenzo | 1e8d1fa | 2022-04-22 09:50:43 -0700 | [diff] [blame] | 1025 | if(IREE_BUILD_SAMPLES) |
| 1026 | add_subdirectory(samples) |
| 1027 | endif() |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 1028 | |
| 1029 | if(IREE_BUILD_TESTS) |
| 1030 | iree_create_ctest_customization() |
| 1031 | endif() |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 1032 | |
| 1033 | #------------------------------------------------------------------------------- |
| 1034 | # Install/exports |
Stella Laurenzo | 3e0583f | 2023-12-29 13:09:15 -0800 | [diff] [blame] | 1035 | # Note that with no further options, install convenience targets install to |
CindyLiu | 8869777 | 2024-01-05 04:22:30 +0800 | [diff] [blame] | 1036 | # CMAKE_INSTALL_PREFIX. Per usual, this can be further prefixed with an |
Stella Laurenzo | 3e0583f | 2023-12-29 13:09:15 -0800 | [diff] [blame] | 1037 | # environment variable "DESTDIST" on a per invocation basis (i.e. to place under |
| 1038 | # a versioned path, etc). |
| 1039 | # |
| 1040 | # The `iree-install-dist` target includes everthing that is typically included in |
| 1041 | # a distribution tarball. |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 1042 | #------------------------------------------------------------------------------- |
| 1043 | |
| 1044 | add_subdirectory(build_tools/cmake ${IREE_BINARY_DIR}/lib/cmake/IREE) |
| 1045 | |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 1046 | # Convenience installation targets. |
Stella Laurenzo | 3e0583f | 2023-12-29 13:09:15 -0800 | [diff] [blame] | 1047 | iree_add_install_target(NAME iree-install-dist) |
| 1048 | iree_add_install_target( |
| 1049 | NAME iree-install-dev-libraries |
| 1050 | ADD_TO iree-install-dist |
| 1051 | ) |
| 1052 | iree_add_install_target( |
| 1053 | NAME iree-install-runtime-libraries |
| 1054 | ADD_TO iree-install-dist |
| 1055 | ) |
| 1056 | iree_add_install_target( |
| 1057 | NAME iree-install-tools |
| 1058 | ADD_TO iree-install-dist |
| 1059 | ) |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 1060 | |
| 1061 | iree_add_install_target( |
| 1062 | NAME iree-install-cmake-exports |
| 1063 | COMPONENT IREECMakeExports |
| 1064 | ADD_TO iree-install-dev-libraries |
| 1065 | ) |
| 1066 | |
| 1067 | iree_add_install_target( |
| 1068 | NAME iree-install-dev-libraries-runtime |
| 1069 | COMPONENT IREEDevLibraries-Runtime |
| 1070 | ADD_TO iree-install-dev-libraries |
| 1071 | ) |
| 1072 | |
| 1073 | iree_add_install_target( |
| 1074 | NAME iree-install-bundled-libraries |
| 1075 | COMPONENT IREEBundledLibraries |
| 1076 | ADD_TO iree-install-dev-libraries-runtime |
| 1077 | ) |
| 1078 | |
| 1079 | if(IREE_BUILD_COMPILER) |
| 1080 | iree_add_install_target( |
| 1081 | NAME iree-install-dev-libraries-compiler |
| 1082 | COMPONENT IREEDevLibraries-Compiler |
| 1083 | ADD_TO iree-install-dev-libraries |
| 1084 | ) |
| 1085 | |
| 1086 | iree_add_install_target( |
| 1087 | NAME iree-install-tools-compiler |
| 1088 | COMPONENT IREETools-Compiler |
| 1089 | ADD_TO iree-install-tools |
| 1090 | ) |
| 1091 | |
| 1092 | iree_add_install_target( |
Stella Laurenzo | 3e0583f | 2023-12-29 13:09:15 -0800 | [diff] [blame] | 1093 | NAME iree-install-tools-compiler-dev |
| 1094 | COMPONENT IREETools-CompilerDev |
| 1095 | ADD_TO iree-install-tools |
| 1096 | ) |
| 1097 | |
| 1098 | iree_add_install_target( |
CindyLiu | 8869777 | 2024-01-05 04:22:30 +0800 | [diff] [blame] | 1099 | NAME iree-install-tools-compiler-extra |
| 1100 | COMPONENT IREETools-CompilerExtra |
| 1101 | # TODO: Remove the ADD_TO here and include the component in the iree-dist |
| 1102 | # tarball build stage. |
| 1103 | ADD_TO iree-install-tools |
| 1104 | ) |
| 1105 | |
| 1106 | iree_add_install_target( |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 1107 | NAME iree-install-runtime-libraries-compiler |
| 1108 | COMPONENT IREERuntimeLibraries-Compiler |
CindyLiu | 8869777 | 2024-01-05 04:22:30 +0800 | [diff] [blame] | 1109 | ADD_TO |
Stella Laurenzo | 15c306f | 2023-12-28 19:03:20 -0800 | [diff] [blame] | 1110 | iree-install-runtime-libraries |
| 1111 | iree-install-tools-compiler |
| 1112 | iree-install-dev-libraries-compiler |
| 1113 | ) |
| 1114 | endif() |
| 1115 | |
| 1116 | iree_add_install_target( |
| 1117 | NAME iree-install-tools-runtime |
| 1118 | COMPONENT IREETools-Runtime |
| 1119 | ADD_TO iree-install-tools |
| 1120 | ) |