blob: a8a9b70bfa448228946b1dacedb0cd258518fe0e [file] [log] [blame]
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07001# Copyright 2019 The IREE Authors
Ben Vanik185d30c2019-09-19 14:24:11 -07002#
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07003# 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 Vanik185d30c2019-09-19 14:24:11 -07006
Geoffrey Martin-Noble4fd7a1d2022-11-17 15:09:49 -08007cmake_minimum_required(VERSION 3.21...3.24)
Ben Vanik552c5f42021-06-21 17:39:14 -07008
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
12set(CMAKE_POLICY_DEFAULT_CMP0116 OLD)
Ben Vanika49a5f52023-02-21 12:19:17 -080013if(POLICY CMP0116)
14 cmake_policy(SET CMP0116 OLD)
15endif()
Ben Vanik552c5f42021-06-21 17:39:14 -070016
Ben Vanik512d2d32019-09-20 13:22:34 -070017set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Ben Vanik185d30c2019-09-19 14:24:11 -070018
Stella Laurenzo688670f2021-09-24 18:16:25 -070019project(IREE ASM C CXX)
Lei Zhang6c5907b2020-06-02 09:06:08 -070020set(CMAKE_C_STANDARD 11)
Scott Todd07349fa2022-07-27 12:16:05 -070021set(CMAKE_CXX_STANDARD 17)
Stella Laurenzobc09f0e2022-07-27 16:22:39 -070022# 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
27set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to" FORCE)
Ben Vanik185d30c2019-09-19 14:24:11 -070028set(IREE_IDE_FOLDER IREE)
29set_property(GLOBAL PROPERTY USE_FOLDERS ON)
30
Scott Todd1a1aea62022-04-28 09:12:11 -070031if(MSVC)
Ben Vanik96fd2772021-04-19 20:30:56 -070032 enable_language(ASM_MASM)
33else()
34 enable_language(ASM)
35endif()
36
Cindy Liub1bfb9c2022-06-27 10:46:13 -070037# 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 Liu23dafd02022-06-22 15:36:21 -070039set(DEFAULT_CMAKE_BUILD_TYPE "Release")
40if(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)
43endif()
44
Scott Todd99e9f5b2021-12-30 10:56:12 -080045include(CMakeDependentOption)
46
Lei Zhang7e253da2020-06-10 07:51:19 -070047#-------------------------------------------------------------------------------
48# Project component configuration
49#-------------------------------------------------------------------------------
50
Ben Vanik56d44bf2020-05-15 13:20:50 -070051option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF)
Scott Todd1cd9f0a2021-07-29 10:05:44 -070052option(IREE_ENABLE_COMPILER_TRACING "Enables instrumented compiler tracing." OFF)
Ben Vanik2d79c202022-10-24 15:08:57 -070053option(IREE_ENABLE_RENDERDOC_PROFILING "Enables profiling HAL devices with the RenderDoc tool." OFF)
Geoffrey Martin-Noblefe74bd42021-10-27 22:17:13 -070054option(IREE_ENABLE_THREADING "Builds IREE in with thread library support." ON)
Rob Sudermand42e0022022-06-08 16:38:45 -070055option(IREE_ENABLE_CLANG_TIDY "Builds IREE in with clang tidy enabled on IREE's libraries." OFF)
Ben Vanik512d2d32019-09-20 13:22:34 -070056
Ben Vanik7ed4f4b2023-06-14 13:33:54 -070057set(IREE_TRACING_PROVIDER_DEFAULT "tracy" CACHE STRING "Default tracing implementation.")
58set(IREE_TRACING_PROVIDER ${IREE_TRACING_PROVIDER_DEFAULT} CACHE STRING "Chooses which built-in tracing implementation is used when tracing is enabled.")
59set(IREE_TRACING_PROVIDER_H "" CACHE STRING "Header file for custom tracing providers.")
60set(IREE_TRACING_MODE_DEFAULT "2" CACHE STRING "Default tracing feature/verbosity mode. See iree/base/tracing.h for more.")
61set(IREE_TRACING_MODE ${IREE_TRACING_MODE_DEFAULT} CACHE STRING "Tracing feature/verbosity mode. See iree/base/tracing.h for more.")
62
Jakub Kuderskie9424062024-03-27 23:42:29 -040063if(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")
67endif()
68
Ben Vanik4aae0032022-04-19 15:49:26 -070069# TODO(#8469): remove the dependency on cpuinfo entirely.
Ben Vanikcbe93c02023-08-08 10:12:08 -070070set(IREE_ENABLE_CPUINFO_DEFAULT ON)
Ben Vanik62c4f982023-12-12 18:01:52 -080071if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Emscripten|Windows|WindowsStore")
Ben Vanikcbe93c02023-08-08 10:12:08 -070072 set(IREE_ENABLE_CPUINFO_DEFAULT OFF)
73endif()
74option(IREE_ENABLE_CPUINFO "Enables runtime use of cpuinfo for processor topology detection." ${IREE_ENABLE_CPUINFO_DEFAULT})
Ben Vanik4aae0032022-04-19 15:49:26 -070075
Marius Brehleredfc57f2019-12-18 11:19:38 -080076option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON)
Ben Vanik512d2d32019-09-20 13:22:34 -070077option(IREE_BUILD_TESTS "Builds IREE unit tests." ON)
Scott Todd96d92132023-06-12 15:45:19 -070078option(IREE_BUILD_DOCS "Builds IREE documentation files." OFF)
Ben Vanik6b112ef2019-10-03 10:45:14 -070079option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON)
Scott Todd382fc632022-06-06 10:57:24 -070080option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF)
Scott Todd3d6a8ee2024-05-23 14:49:54 -070081option(IREE_BUILD_TRACY "Enables building the 'iree-tracy-capture' CLI tool and includes it in runtime Python bindings." OFF)
Stella Laurenzo96d959e2023-02-19 11:58:14 -080082option(IREE_BUILD_BUNDLED_LLVM "Builds the bundled llvm-project (vs using installed)" ON)
Ben Vanikcd1132f2021-01-29 15:58:17 -080083
Stella Laurenzobb1de962021-01-05 08:18:33 -080084# Properties controlling version and naming of release artifacts.
Stella Laurenzof33f5b52022-01-08 17:49:52 +000085set(IREE_RELEASE_PACKAGE_SUFFIX "" CACHE STRING "Suffix to append to distributed package names")
Stella Laurenzobb1de962021-01-05 08:18:33 -080086set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages")
87set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages")
Cullen Rhodes5f4235a2024-08-20 08:28:10 +010088option(IREE_EMBEDDED_RELEASE_INFO "Embed the IREE version information in built artifacts." OFF)
Stella Laurenzobb1de962021-01-05 08:18:33 -080089
Scott Toddde426de2023-01-13 08:26:02 -080090# Using already built host binaries, such as for cross-compilation.
91set(IREE_HOST_BIN_DIR_DEFAULT "")
92if(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")
97endif()
98set(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 Vanikcd1132f2021-01-29 15:58:17 -0800100option(IREE_BUILD_BINDINGS_TFLITE "Builds the IREE TFLite C API compatibility shim" ON)
Kojo Acquah5bf39942021-04-22 16:01:28 -0700101option(IREE_BUILD_BINDINGS_TFLITE_JAVA "Builds the IREE TFLite Java bindings with the C API compatibility shim" ON)
Ben Vanikcd1132f2021-01-29 15:58:17 -0800102
Scott Todd46e12062024-02-02 10:54:59 -0800103option(IREE_BUILD_ALL_CHECK_TEST_MODULES "Builds all modules for iree_check_test, regardless of which would be tested" ON)
104
Boian Petkantchind4e39682023-07-31 10:09:16 -0700105option(IREE_ENABLE_COLLECTIVE_RUNTIME_TESTS "Enable runtime tests for collective operations." OFF)
Jerry Wu57404972023-03-02 22:16:11 +0000106
Stella Laurenzo289b9a12023-02-24 13:06:32 -0800107# 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.
113option(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.
119option(BUILD_SHARED_LIBS "Instructs CMake to build libraries as shared if possible" OFF)
120
Stella Laurenzob61a9182024-03-18 12:52:22 -0700121# Control of LTO settings for the runtime build.
Jakub Kuderskie9424062024-03-27 23:42:29 -0400122set(IREE_RUNTIME_OPTIMIZATION_PROFILE "" CACHE STRING
Stella Laurenzob61a9182024-03-18 12:52:22 -0700123 "Build optimization profile to apply. One of '', 'lto', 'size'.")
124set(IREE_LTO_MODE "full" CACHE STRING "LTO type, 'thin' or 'full'. Only consulted on clang-like compilers.")
125
Stella Laurenzo0f005e52020-12-27 11:54:33 -0800126#-------------------------------------------------------------------------------
Ben Vanik5363ea32023-05-02 15:47:58 -0700127# 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.
138set(IREE_EXTERNAL_TOOLING_MODULES "" CACHE STRING "")
139
140#-------------------------------------------------------------------------------
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800141# IREE out of tree plugins
Stella Laurenzoc6092c42023-03-25 19:55:37 -0700142#
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800143# 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 Laurenzoc6092c42023-03-25 19:55:37 -0700147#
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800148# iree_compiler_plugin.cmake : Included in the context of the compiler/
149# directory before sources and bindings. Will execute with source and
Peyman B66b10cc2023-11-15 17:14:14 +0100150# binary dir ${IREE_BUILD_DIR}/compiler/plugins (shared with all other
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800151# dirs).
152# iree_runtime_plugin.cmake : Included in the context of the runtime/
Peyman B66b10cc2023-11-15 17:14:14 +0100153# directory before sources. Will execute with source and binary dir
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800154# ${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 Laurenzo62a7f352023-07-10 17:59:15 -0700161# statically configure more plugin directories to be used.
162#
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800163# 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 Laurenzoc6092c42023-03-25 19:55:37 -0700168#
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800169# External HAL Driver Plugins
170# ---------------------------
171# HAL driver implementations are advertised to the build system via
Peyman B66b10cc2023-11-15 17:14:14 +0100172# iree_register_external_hal_driver(), which specifies the name, target,
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800173# registration function and optional source/binary directory.
Stella Laurenzoc6092c42023-03-25 19:55:37 -0700174#-------------------------------------------------------------------------------
175
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800176set(IREE_CMAKE_PLUGIN_PATHS "" CACHE STRING "Paths to be scanned for IREE CMake plugin includes")
177list(APPEND IREE_CMAKE_BUILTIN_PLUGIN_PATHS "compiler/plugins")
Stella Laurenzoc6092c42023-03-25 19:55:37 -0700178if(IREE_BUILD_SAMPLES)
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800179 list(APPEND IREE_CMAKE_BUILTIN_PLUGIN_PATHS "samples/compiler_plugins")
Stella Laurenzoc6092c42023-03-25 19:55:37 -0700180endif()
181
182#-------------------------------------------------------------------------------
Stella Laurenzo0f005e52020-12-27 11:54:33 -0800183# Experimental project flags
184#-------------------------------------------------------------------------------
185
Scott Toddf237b5e2022-01-28 11:02:25 -0800186option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." OFF)
Benoit Jacob655b71a2024-04-23 11:07:38 -0400187option(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 Laurenzo0f005e52020-12-27 11:54:33 -0800188
189#-------------------------------------------------------------------------------
Scott Todd18a54852023-01-27 08:52:12 -0800190# 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 Todd9fa5de72023-01-23 14:40:18 -0800195#-------------------------------------------------------------------------------
196
Scott Todd18a54852023-01-27 08:52:12 -0800197set(IREE_CUDA_AVAILABLE OFF)
Lei Zhang41583ca2024-01-27 10:31:21 -0800198# The IREE cuda driver requires CUDA >= 12.
Boian Petkantchin58cd1122024-01-18 13:40:48 -0800199set(IREE_CUDA_MIN_VERSION_REQUIRED 12)
200find_package(CUDAToolkit ${IREE_CUDA_MIN_VERSION_REQUIRED})
Scott Todd18a54852023-01-27 08:52:12 -0800201if(CUDAToolkit_FOUND)
202 set(IREE_CUDA_AVAILABLE ON)
203else()
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 Todd9fa5de72023-01-23 14:40:18 -0800210 endif()
211endif()
212
213#-------------------------------------------------------------------------------
Lei Zhang5f2743b2024-03-20 16:39:24 -0700214# 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
221set(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 Laurenzo74b04b72022-03-02 10:21:11 -0800226# 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 Vanik185d30c2019-09-19 14:24:11 -0700230#-------------------------------------------------------------------------------
231
Ben Vanik4e6af052022-06-07 17:10:20 -0700232# External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more
233# information on how to declare external drivers.
234set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "")
235
Ben Vanik89160272022-09-26 16:44:11 -0700236# 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.
241set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "")
242
Ben Vanike19fc8e2023-04-14 16:08:01 -0700243# 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.
248set(IREE_HAL_EXECUTABLE_PLUGIN_EXTRA_DEPS "" CACHE STRING "")
249
Scott Toddd1620f02021-12-22 14:55:38 -0800250option(IREE_HAL_DRIVER_DEFAULTS "Sets the default value for all runtime HAL drivers" ON)
Ben Vanika9aaebe2022-12-16 09:14:53 -0800251
maxbartelf2bf6022024-09-04 17:53:38 +0200252# CUDA support is disabled by default. Note: a CUDA-compatible GPU with drivers is still
Scott Todd9fa5de72023-01-23 14:40:18 -0800253# required to actually run CUDA workloads.
maxbartelf2bf6022024-09-04 17:53:38 +0200254set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF)
Scott Todd9fa5de72023-01-23 14:40:18 -0800255
maxbartelf2bf6022024-09-04 17:53:38 +0200256# HIP support is disabled by default. Note: a HIP-compatible GPU with drivers is still
257# required to actually run HIP workloads.
258set(IREE_HAL_DRIVER_HIP_DEFAULT OFF)
Lei Zhang5f2743b2024-03-20 16:39:24 -0700259
Lei Zhangd1d03cb2023-08-07 13:52:56 -0400260# Metal support is enabled if it's one of the Apple platforms.
261set(IREE_HAL_DRIVER_METAL_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS})
262# Right now only support Apple silicon devices.
263if(NOT APPLE OR NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
264 set(IREE_HAL_DRIVER_METAL_DEFAULT OFF)
265endif()
266
Ben Vanika6043e22024-10-03 08:49:55 -0700267# 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.
270set(IREE_HAL_DRIVER_NULL_DEFAULT OFF)
271string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE)
272if (IREE_DEV_MODE OR (_UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "DEBUG"))
273 set(IREE_HAL_DRIVER_NULL_DEFAULT ON)
274endif()
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.
278set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS})
279if(APPLE)
280 set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF)
281endif()
282
Scott Toddd1620f02021-12-22 14:55:38 -0800283option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT})
Lei Zhang5f2743b2024-03-20 16:39:24 -0700284option(IREE_HAL_DRIVER_HIP "Enables the 'hip' runtime HAL driver" ${IREE_HAL_DRIVER_HIP_DEFAULT})
Ben Vanike3058072022-06-06 19:21:44 -0700285option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
286option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
Lei Zhangd1d03cb2023-08-07 13:52:56 -0400287option(IREE_HAL_DRIVER_METAL "Enables the 'metal' runtime HAL driver" ${IREE_HAL_DRIVER_METAL_DEFAULT})
Ben Vanika6043e22024-10-03 08:49:55 -0700288option(IREE_HAL_DRIVER_NULL "Enables the 'null' runtime HAL driver" ${IREE_HAL_DRIVER_NULL_DEFAULT})
289option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT})
Ben Vanike3058072022-06-06 19:21:44 -0700290
Ben Vanik6e64b6e2022-06-07 09:14:53 -0700291option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON)
292set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS})
293set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS})
294set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS})
Ben Vanike3058072022-06-06 19:21:44 -0700295
Ben Vanike19fc8e2023-04-14 16:08:01 -0700296option(IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS "Sets the default value for all runtime HAL executable plugin mechanisms" ON)
297set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS})
298set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS})
299
Ben Vanike3058072022-06-06 19:21:44 -0700300# Emscripten builds don't support embedded ELF libraries.
301if(EMSCRIPTEN)
Ben Vanik2e8540e2022-06-06 20:39:34 -0700302 set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF)
Ben Vanike19fc8e2023-04-14 16:08:01 -0700303 set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF)
Ben Vanike3058072022-06-06 19:21:44 -0700304endif()
305
Ben Vanike19fc8e2023-04-14 16:08:01 -0700306# 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 Vanik6e64b6e2022-06-07 09:14:53 -0700309if(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 Vanike19fc8e2023-04-14 16:08:01 -0700313 set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF)
314 set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT OFF)
Ben Vanik6e64b6e2022-06-07 09:14:53 -0700315endif()
316
Ben Vanik2e8540e2022-06-06 20:39:34 -0700317option(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF "Enables the embedded dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT})
Ben Vanike3058072022-06-06 19:21:44 -0700318option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT})
319option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT})
320
Ben Vanike19fc8e2023-04-14 16:08:01 -0700321option(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF "Enables the embedded dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT})
322option(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 Todd0f1f8eb2022-06-10 15:53:30 -0700324if(IREE_BUILD_COMPILER)
Scott Toddf5660ee2024-04-22 16:16:37 -0700325 # 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 Todd0f1f8eb2022-06-10 15:53:30 -0700328 set(IREE_HAL_DRIVER_LOCAL_TASK ON)
Scott Toddf5660ee2024-04-22 16:16:37 -0700329 set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF ON)
Scott Todd0f1f8eb2022-06-10 15:53:30 -0700330endif()
331
Ben Vanike3058072022-06-06 19:21:44 -0700332message(STATUS "IREE HAL drivers:")
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800333if(IREE_HAL_DRIVER_CUDA)
334 message(STATUS " - cuda")
335endif()
Lei Zhang5f2743b2024-03-20 16:39:24 -0700336if(IREE_HAL_DRIVER_HIP)
337 message(STATUS " - hip")
338endif()
Ben Vanike3058072022-06-06 19:21:44 -0700339if(IREE_HAL_DRIVER_LOCAL_SYNC)
340 message(STATUS " - local-sync")
341endif()
342if(IREE_HAL_DRIVER_LOCAL_TASK)
343 message(STATUS " - local-task")
344endif()
Lei Zhangd1d03cb2023-08-07 13:52:56 -0400345if(IREE_HAL_DRIVER_METAL)
346 message(STATUS " - metal")
347endif()
Ben Vanika6043e22024-10-03 08:49:55 -0700348if(IREE_HAL_DRIVER_NULL)
349 message(STATUS " - null")
350endif()
351if(IREE_HAL_DRIVER_VULKAN)
352 message(STATUS " - vulkan")
353endif()
Ben Vanik4e6af052022-06-07 17:10:20 -0700354if(IREE_EXTERNAL_HAL_DRIVERS)
355 message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}")
356endif()
Ben Vanik512d2d32019-09-20 13:22:34 -0700357
Ben Vanike3058072022-06-06 19:21:44 -0700358message(STATUS "IREE HAL local executable library loaders:")
Ben Vanik2e8540e2022-06-06 20:39:34 -0700359if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF)
360 message(STATUS " - embedded-elf")
Ben Vanike3058072022-06-06 19:21:44 -0700361endif()
362if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY)
363 message(STATUS " - system-library")
364endif()
365if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE)
366 message(STATUS " - vmvx-module")
367endif()
368
Ben Vanike19fc8e2023-04-14 16:08:01 -0700369message(STATUS "IREE HAL local executable plugin mechanisms:")
370if(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF)
371 message(STATUS " - embedded-elf")
372endif()
373if(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY)
374 message(STATUS " - system-library")
375endif()
376
Lei Zhang0d281b72020-06-01 20:00:23 -0400377#-------------------------------------------------------------------------------
Scott Todd382fc632022-06-06 10:57:24 -0700378# Compiler Target Options
maxbartelf2bf6022024-09-04 17:53:38 +0200379# 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 Todd382fc632022-06-06 10:57:24 -0700382# -DIREE_TARGET_BACKEND_DEFAULTS=OFF
383#-------------------------------------------------------------------------------
384
385option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON)
386
387# The VMVX backend is always enabled.
388cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
389
390# Supported default target backends.
Scott Todd352da3f2022-07-20 15:25:11 -0700391cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
392cmake_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 Todd382fc632022-06-06 10:57:24 -0700393cmake_dependent_option(IREE_TARGET_BACKEND_METAL_SPIRV "Enables the 'metal-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
Scott Todd382fc632022-06-06 10:57:24 -0700394cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
395
Stella Laurenzo58b56702023-10-05 15:05:58 -0700396# Default target backends that are not yet fully supported but are being brought up.
maxbartelf2bf6022024-09-04 17:53:38 +0200397cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
Stella Laurenzo58b56702023-10-05 15:05:58 -0700398
maxbartelf2bf6022024-09-04 17:53:38 +0200399# Supported target backends that are only available on certain platforms.
Scott Todd9fa5de72023-01-23 14:40:18 -0800400set(IREE_TARGET_BACKEND_CUDA_DEFAULT ${IREE_TARGET_BACKEND_DEFAULTS})
Scott Todd18a54852023-01-27 08:52:12 -0800401if(NOT IREE_CUDA_AVAILABLE)
Scott Todd9fa5de72023-01-23 14:40:18 -0800402 set(IREE_TARGET_BACKEND_CUDA_DEFAULT OFF)
403endif()
maxbartelf2bf6022024-09-04 17:53:38 +0200404cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
Scott Todd9fa5de72023-01-23 14:40:18 -0800405
Scott Todd382fc632022-06-06 10:57:24 -0700406# Non-default target backends either have additional dependencies or are
407# experimental/niche in some fashion.
Scott Todd382fc632022-06-06 10:57:24 -0700408# Disable WebGPU by default - it has complex deps and is under development.
Ben Vanikeeda5ca2024-02-27 14:18:32 -0800409cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU_SPIRV "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
Scott Todd382fc632022-06-06 10:57:24 -0700410
411#-------------------------------------------------------------------------------
Scott Todde23d4a72022-07-27 14:16:39 -0700412# Compiler Input Dialects
413#-------------------------------------------------------------------------------
414
Jakub Kuderski0dbf0862023-06-12 14:33:06 -0400415cmake_dependent_option(IREE_INPUT_STABLEHLO "Builds support for compiling StableHLO programs" ON ${IREE_BUILD_COMPILER} OFF)
Scott Todde23d4a72022-07-27 14:16:39 -0700416cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF)
417cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF)
418
Marius Brehler36f24512022-08-04 17:39:03 +0200419if(IREE_BUILD_COMPILER)
420 message(STATUS "IREE compiler input dialects:")
Jakub Kuderski0dbf0862023-06-12 14:33:06 -0400421 if(IREE_INPUT_STABLEHLO)
422 message(STATUS " - StableHLO")
Marius Brehler36f24512022-08-04 17:39:03 +0200423 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 Todde23d4a72022-07-27 14:16:39 -0700430endif()
431
432#-------------------------------------------------------------------------------
Scott Todd2a1925c2022-06-13 10:03:52 -0700433# Compiler Output Formats
434#-------------------------------------------------------------------------------
435
Scott Todd2a1925c2022-06-13 10:03:52 -0700436cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF)
437
Marius Brehler36f24512022-08-04 17:39:03 +0200438if(IREE_BUILD_COMPILER)
439 message(STATUS "IREE compiler output formats:")
440 if(IREE_OUTPUT_FORMAT_C)
Ben Vanik09630d62023-04-13 14:21:40 -0700441 message(STATUS " - 'vm-c': textual C source module")
Marius Brehler36f24512022-08-04 17:39:03 +0200442 endif()
443 # The 'vm-bytecode' and 'vm-asm' formats are always enabled.
Ben Vanik09630d62023-04-13 14:21:40 -0700444 message(STATUS " - 'vm-bytecode': VM bytecode")
445 message(STATUS " - 'vm-asm': VM MLIR assembly")
Scott Todde23d4a72022-07-27 14:16:39 -0700446endif()
Scott Todde23d4a72022-07-27 14:16:39 -0700447
Scott Todd2a1925c2022-06-13 10:03:52 -0700448#-------------------------------------------------------------------------------
Lei Zhange88470f2020-09-08 13:21:09 -0400449# IREE compilation toolchain configuration
450#-------------------------------------------------------------------------------
451
Lei Zhange88470f2020-09-08 13:21:09 -0400452option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF)
453option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF)
454option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF)
Jakub Kuderski068b1722022-07-27 18:14:59 -0400455option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF)
Stella Laurenzodeb48052022-11-25 10:41:46 -0800456option(IREE_ENABLE_SPLIT_DWARF "Enable gsplit-dwarf for debug information if the platform supports it" OFF)
457option(IREE_ENABLE_THIN_ARCHIVES "Enables thin ar archives (elf systems only). Disable for released static archives" OFF)
Ben Vanikadadd032022-11-28 23:18:16 -0800458option(IREE_LINK_COMPILER_SHARED_LIBRARY "Links IREE tools using the compiler compiled into a shared library" ON)
Rechie Khodd176122024-01-17 06:40:18 +0800459option(IREE_ENABLE_WERROR_FLAG "Enable `-Werror` flag, treat error as warning" ON)
Gyungmin Myung00c9fc22024-03-02 23:51:46 +0900460option(IREE_ENABLE_POSITION_INDEPENDENT_CODE "Enable position independent code" TRUE)
bjacob7cf5b842022-04-04 16:48:04 -0400461
Scott Todd86781382023-02-07 14:11:52 -0800462if(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)")
467endif()
468
Geoffrey Martin-Noble61ea1ed2022-11-23 16:25:57 -0800469option(IREE_ENABLE_CCACHE
470 "[DEPRECATED: Use CMAKE_<LANG>_COMPILER_LAUNCHER configure options or environment variables instead.] Use ccache if installed."
471 OFF)
bjacobe694d952020-11-03 12:05:35 -0500472
Scott Todd1a1aea62022-04-28 09:12:11 -0700473if(IREE_ENABLE_CCACHE)
Geoffrey Martin-Noble61ea1ed2022-11-23 16:25:57 -0800474 message(WARNING
475 "IREE_ENABLE_CCACHE is deprecated. Use CMAKE_<LANG>_COMPILER_LAUNCHER"
476 " configure options or environment variables instead.")
bjacobe694d952020-11-03 12:05:35 -0500477 find_program(CCACHE_PROGRAM ccache)
478 if(CCACHE_PROGRAM)
479 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
Geoffrey Martin-Noble61ea1ed2022-11-23 16:25:57 -0800480 else()
481 message(SEND_ERROR
482 "IREE_ENABLE_CCACHE was set, but executable `ccache` was not found.")
bjacobe694d952020-11-03 12:05:35 -0500483 endif()
484endif()
Lei Zhange88470f2020-09-08 13:21:09 -0400485
Gyungmin Myung00c9fc22024-03-02 23:51:46 +0900486set (CMAKE_POSITION_INDEPENDENT_CODE ${IREE_ENABLE_POSITION_INDEPENDENT_CODE})
487
Geoffrey Martin-Noble3fa4f8d2021-09-10 09:25:27 -0700488option(IREE_DEV_MODE "Configure settings to optimize for IREE development (as opposed to CI or release)" OFF)
Stella Laurenzo5b639122021-06-18 14:44:10 -0700489
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
510option(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).
514function(iree_fix_ndebug)
Scott Todd1a1aea62022-04-28 09:12:11 -0700515 string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE)
516 if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
Ben Vanika6043e22024-10-03 08:49:55 -0700517 # 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 Laurenzo5b639122021-06-18 14:44:10 -0700529
Ben Vanika6043e22024-10-03 08:49:55 -0700530 # 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 Laurenzo5b639122021-06-18 14:44:10 -0700533 endif()
534endfunction()
535iree_fix_ndebug()
536
Lei Zhange88470f2020-09-08 13:21:09 -0400537#-------------------------------------------------------------------------------
Lei Zhang7e253da2020-06-10 07:51:19 -0700538# IREE utility definitions
Lei Zhang0d281b72020-06-01 20:00:23 -0400539#-------------------------------------------------------------------------------
540
Scott Toddd1620f02021-12-22 14:55:38 -0800541list(APPEND CMAKE_MODULE_PATH
542 ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
Scott Toddd1620f02021-12-22 14:55:38 -0800543)
544
Ben Vanik512d2d32019-09-20 13:22:34 -0700545include(iree_macros)
Ben Vanik185d30c2019-09-19 14:24:11 -0700546include(iree_copts)
Ben Vanik6b112ef2019-10-03 10:45:14 -0700547include(iree_cc_binary)
Ben Vanik185d30c2019-09-19 14:24:11 -0700548include(iree_cc_library)
549include(iree_cc_test)
Scott Todd20d746a2023-01-12 09:11:59 -0800550include(iree_import_binary)
Stella Laurenzo15c306f2023-12-28 19:03:20 -0800551include(iree_install_support)
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800552include(iree_external_cmake_options)
Ben Vanikcc2aff92019-09-24 10:23:55 -0700553include(iree_tablegen_library)
Lei Zhang22f0e242020-03-30 12:09:20 -0700554include(iree_tablegen_doc)
CindyLiu40ed02d2021-04-22 16:16:28 +0000555include(iree_c_embed_data)
Ben Vanik7f6c57c2023-02-07 18:04:32 -0800556include(iree_bitcode_library)
Scott Todd11adcab2019-12-18 14:10:44 -0800557include(iree_bytecode_module)
Marius Brehler46e83312021-03-25 00:11:39 +0100558include(iree_c_module)
Stella Laurenzo94363e22020-12-15 13:46:14 -0800559include(iree_python)
Geoffrey Martin-Noblef0eaf372020-01-28 10:03:14 -0800560include(iree_lit_test)
Stella Laurenzo96d959e2023-02-19 11:58:14 -0800561include(iree_llvm)
Geoffrey Martin-Noble4526dcc2020-03-09 11:59:52 -0700562include(iree_add_all_subdirs)
Geoffrey Martin-Noblee5fd5b52020-03-31 11:31:30 -0700563include(iree_check_test)
Prashant Kumar3cce7fc2024-04-04 23:32:36 +0530564include(iree_e2e_generated_runner_test)
Geoffrey Martin-Noble435c2702022-01-24 15:56:56 -0800565include(iree_native_test)
Geoffrey Martin-Noble2811e502022-01-25 09:44:40 -0800566include(iree_cc_binary_benchmark)
Scott Todd434ff0e2021-12-21 10:38:36 -0800567include(iree_hal_cts_test_suite)
CindyLiuae72b952022-08-23 15:26:08 -0700568include(iree_static_linker_test)
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800569include(iree_plugin_register)
Ben Vanik185d30c2019-09-19 14:24:11 -0700570
Stella Laurenzobe0f1e12023-04-03 13:34:38 -0700571# Default any sub-tree which doesn't provide its own package namespacing
572# to derive it relative to this directory and prefixed with iree/.
573set(IREE_PACKAGE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
Lei Zhang923535d2023-04-06 18:07:43 -0400574set(IREE_PACKAGE_ROOT_PREFIX "iree")
Stella Laurenzobe0f1e12023-04-03 13:34:38 -0700575
Ben Vanik185d30c2019-09-19 14:24:11 -0700576#-------------------------------------------------------------------------------
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800577# Experimental WebGPU HAL driver
578# Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=webgpu
579#-------------------------------------------------------------------------------
580
581iree_register_external_hal_driver(
582 NAME
583 webgpu
Peyman B66b10cc2023-11-15 17:14:14 +0100584 SOURCE_DIR
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800585 "${CMAKE_CURRENT_SOURCE_DIR}/experimental/webgpu"
Scott Todd50aa2cc2023-11-27 10:28:47 -0800586 BINARY_DIR
587 "${CMAKE_CURRENT_BINARY_DIR}/experimental/webgpu"
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800588 DRIVER_TARGET
589 iree::experimental::webgpu::registration
590 REGISTER_FN
591 iree_hal_webgpu_driver_module_register
592)
593
594#-------------------------------------------------------------------------------
Lei Zhange88470f2020-09-08 13:21:09 -0400595# IREE compilation flags
Scott Todd29d654e2020-06-11 15:24:17 -0700596#-------------------------------------------------------------------------------
597
Lei Zhangdd21f322020-09-10 10:47:33 -0400598iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST})
599iree_append_list_to_string(CMAKE_CXX_FLAGS_DEBUG ${IREE_CXX_FLAGS_DEBUG_LIST})
Scott Todd29d654e2020-06-11 15:24:17 -0700600
601set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE)
602set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE)
603set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE)
604set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE)
605mark_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 Todd7649dee2022-07-18 11:31:46 -0700612# Override the system's default linker.
613# See also: https://llvm.org/docs/CMake.html#llvm-use-linker.
614set(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.
620cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF)
621
Scott Todd29d654e2020-06-11 15:24:17 -0700622include(iree_setup_toolchain)
623
624#-------------------------------------------------------------------------------
Stella Laurenzo29032b82021-10-14 15:21:44 -0700625# 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 Laurenzoa3e97f12020-12-05 23:29:13 -0800629#-------------------------------------------------------------------------------
630
Stella Laurenzo29032b82021-10-14 15:21:44 -0700631if(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 Todda24c8c52022-05-17 09:22:47 -0700637 #
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 Wang9ed3dab2023-08-30 14:25:24 -0700642 # 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 Laurenzoacf0b272023-06-26 21:25:48 -0700645 # 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 Brehler258cdb82024-10-17 20:20:44 +0200648 # can be troublesome. Note that pybind11 and nanobind require FindPython.
Stella Laurenzoacf0b272023-06-26 21:25:48 -0700649 set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
Han-Chung Wang9ed3dab2023-08-30 14:25:24 -0700650 find_package(Python 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
Stella Laurenzo3149b6d2021-10-24 18:45:17 -0700651elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS)
Stella Laurenzoa3e97f12020-12-05 23:29:13 -0800652 find_package(Python3 COMPONENTS Interpreter REQUIRED)
Stella Laurenzoacf0b272023-06-26 21:25:48 -0700653 set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
654 find_package(Python COMPONENTS Interpreter REQUIRED)
655endif()
656
657if(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 Laurenzoa3e97f12020-12-05 23:29:13 -0800659endif()
660
661#-------------------------------------------------------------------------------
Niloy Sikdar47238df2021-07-28 23:37:33 +0530662# Check if git submodules have been initialized.
663# This will only run if python3 is available.
664#-------------------------------------------------------------------------------
665
Marius Brehler776d7e62021-12-21 22:50:52 +0100666option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON)
667
Niloy Sikdar47238df2021-07-28 23:37:33 +0530668find_package(Python3 COMPONENTS Interpreter QUIET)
Scott Todde5b269a2021-11-16 15:25:02 -0800669find_package(Git)
Marius Brehler776d7e62021-12-21 22:50:52 +0100670if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND)
Scott Todde5b269a2021-11-16 15:25:02 -0800671 # Only check submodule status when the git commit changes.
Niloy Sikdar47238df2021-07-28 23:37:33 +0530672 execute_process(
Scott Todde5b269a2021-11-16 15:25:02 -0800673 COMMAND git rev-parse --short HEAD
Niloy Sikdar47238df2021-07-28 23:37:33 +0530674 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Scott Todde5b269a2021-11-16 15:25:02 -0800675 RESULT_VARIABLE SHORT_HASH_RESULT
676 OUTPUT_VARIABLE SHORT_HASH)
677 string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}")
Scott Todd2a8cd3b2021-12-13 11:58:44 -0800678 if(SHORT_HASH_RESULT EQUAL "0" AND NOT "${IREE_GIT_SHORT_HASH}" STREQUAL "${SHORT_HASH}")
CindyLiu0e8fdc62022-10-14 09:35:44 -0700679 if(NOT IREE_BUILD_COMPILER)
680 set(CHECK_SUBMODULE_ARGS "--runtime_only")
681 endif()
Scott Todde5b269a2021-11-16 15:25:02 -0800682 execute_process(
CindyLiu0e8fdc62022-10-14 09:35:44 -0700683 COMMAND ${Python3_EXECUTABLE} build_tools/scripts/git/check_submodule_init.py ${CHECK_SUBMODULE_ARGS}
Scott Todde5b269a2021-11-16 15:25:02 -0800684 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 Sikdar47238df2021-07-28 23:37:33 +0530692 endif()
693endif()
694
695#-------------------------------------------------------------------------------
Lei Zhang22f0e242020-03-30 12:09:20 -0700696# IREE top-level targets
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800697# We define these here because various things in the build tree adds
698# dependencies to them.
Lei Zhang22f0e242020-03-30 12:09:20 -0700699#-------------------------------------------------------------------------------
700
Scott Todd1a1aea62022-04-28 09:12:11 -0700701if(IREE_BUILD_DOCS)
Scott Todd96d92132023-06-12 15:45:19 -0700702 # Define a top-level custom target to drive generating documentation files.
703 # Add to the default target given that docs were explicitly requested.
Lei Zhang22f0e242020-03-30 12:09:20 -0700704 add_custom_target(iree-doc ALL)
705endif()
706
Jakub Kuderski3f764682023-02-07 17:14:23 -0500707# 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`).
711add_custom_target(iree-sample-deps
712 COMMENT
713 "Building IREE sample data targets"
714)
715
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800716# Testing rules that require generation will add dependencies to this target.
717# This allows them to be EXCLUDE_FROM_ALL but still invokable.
Jakub Kuderski3f764682023-02-07 17:14:23 -0500718add_custom_target(iree-test-deps
719 COMMENT
720 "Building IREE test deps"
721 DEPENDS
722 iree-sample-deps
723)
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800724
CindyLiu99373e02022-10-12 09:22:24 -0700725# 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`.
727add_custom_target(iree-run-module-test-deps
728 COMMENT
729 "Building IREE run module test targets"
730)
731
Stella Laurenzoe2dfc652023-02-15 18:12:03 -0800732# Convenience target for running IREE tests.
733add_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)
753add_dependencies(iree-run-tests iree-test-deps)
754
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800755#-------------------------------------------------------------------------------
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
763set(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.
767if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA)
768 add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL)
769endif()
770
771#-------------------------------------------------------------------------------
772# MLIR/LLVM Dependency
773#-------------------------------------------------------------------------------
774
Stella Laurenzo9c5b57a2024-10-23 22:57:45 -0700775# Both the IREE and MLIR Python bindings require pybind11. We initialize it here
776# at the top level so that everything uses ours consistently.
777if(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)")
797endif()
798
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800799if(NOT IREE_BUILD_COMPILER)
800 message(STATUS "Not adding LLVM/MLIR because the configuration does not require it")
801else()
Stella Laurenzo289b9a12023-02-24 13:06:32 -0800802 # 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 Laurenzo9be15aa2023-02-21 17:00:29 -0800808 # 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 Laurenzo15c306f2023-12-28 19:03:20 -0800818 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 Laurenzo9be15aa2023-02-21 17:00:29 -0800828 )
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 Todd53af6812023-11-27 10:33:08 -0800837 # Add external projects.
838
839 message(STATUS "Configuring llvm-external-projects/mlir-iree-dialects")
840 list(APPEND CMAKE_MESSAGE_INDENT " ")
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800841 iree_llvm_add_external_project(mlir-iree-dialects ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects)
Scott Todd53af6812023-11-27 10:33:08 -0800842 list(POP_BACK CMAKE_MESSAGE_INDENT)
843
Stella Laurenzofd9cd2f2023-11-01 16:22:00 -0700844 if(IREE_INPUT_STABLEHLO)
Scott Todd53af6812023-11-27 10:33:08 -0800845 message(STATUS "Configuring third_party/stablehlo")
846 list(APPEND CMAKE_MESSAGE_INDENT " ")
Stella Laurenzofd9cd2f2023-11-01 16:22:00 -0700847 iree_llvm_add_external_project(stablehlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stablehlo)
Scott Todd53af6812023-11-27 10:33:08 -0800848 list(POP_BACK CMAKE_MESSAGE_INDENT)
Stella Laurenzofd9cd2f2023-11-01 16:22:00 -0700849 endif()
Ben Vanike3578d52023-09-12 09:35:11 -0700850
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800851 # 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 Laurenzo289b9a12023-02-24 13:06:32 -0800859
860 set(BUILD_SHARED_LIBS ${_IREE_ORIG_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800861endif()
862
863#-------------------------------------------------------------------------------
864# Other dependencies
Stella Laurenzo15c306f2023-12-28 19:03:20 -0800865# 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 Laurenzo9be15aa2023-02-21 17:00:29 -0800876#-------------------------------------------------------------------------------
877
878include(external_cc_library)
879include(flatbuffer_c_library)
880
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800881add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL)
Scott Todd3d6a8ee2024-05-23 14:49:54 -0700882
883if((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 )
894endif()
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800895
896iree_set_googletest_cmake_options()
897add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
898
899if(IREE_ENABLE_THREADING)
Stella Laurenzo15c306f2023-12-28 19:03:20 -0800900 # Benchmark.
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800901 iree_set_benchmark_cmake_options()
902 add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL)
Stella Laurenzo15c306f2023-12-28 19:03:20 -0800903 iree_install_targets(
904 TARGETS benchmark
905 COMPONENT IREEBundledLibraries
906 EXPORT_SET Runtime
907 )
908
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800909 if(IREE_ENABLE_CPUINFO)
910 iree_set_cpuinfo_cmake_options()
911 add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL)
Stella Laurenzo15c306f2023-12-28 19:03:20 -0800912 iree_install_targets(
913 TARGETS cpuinfo
914 COMPONENT IREEBundledLibraries
915 EXPORT_SET Runtime
916 )
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800917 endif()
918endif()
919
920# This defines the iree-flatcc-cli target, so we don't use EXCLUDE_FROM_ALL.
921add_subdirectory(build_tools/third_party/flatcc)
922
923if(IREE_HAL_DRIVER_CUDA)
924 add_subdirectory(build_tools/third_party/nccl EXCLUDE_FROM_ALL)
925endif()
926
Boian Petkantchin4132d2e2024-05-17 08:47:33 -0700927if(IREE_HAL_DRIVER_HIP)
928 add_subdirectory(build_tools/third_party/rccl EXCLUDE_FROM_ALL)
929endif()
930
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800931if(IREE_HAL_DRIVER_VULKAN)
932 add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL)
Stella Laurenzo15c306f2023-12-28 19:03:20 -0800933 iree_install_targets(
934 TARGETS Vulkan-Headers
935 COMPONENT IREEBundledLibraries
936 EXPORT_SET Runtime
937 )
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800938endif()
939
940if(IREE_BUILD_COMPILER)
Jakub Kuderski3546f2a2023-06-14 13:18:44 -0400941 add_subdirectory(build_tools/third_party/stablehlo EXCLUDE_FROM_ALL)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800942endif()
943
944if(IREE_BUILD_TESTS)
945 include(iree_configure_testing)
946endif()
947
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800948if(IREE_TARGET_BACKEND_METAL_SPIRV)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800949 # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code.
Scott Toddad321b62023-06-05 14:39:30 -0700950 iree_set_spirv_cross_cmake_options()
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800951 add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL)
952endif()
953
Lei Zhang22f0e242020-03-30 12:09:20 -0700954#-------------------------------------------------------------------------------
Ben Vanik185d30c2019-09-19 14:24:11 -0700955# IREE top-level libraries
956#-------------------------------------------------------------------------------
957
Rob Sudermand42e0022022-06-08 16:38:45 -0700958if(IREE_ENABLE_CLANG_TIDY)
959 set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*)
960endif()
961
Marius Brehlerf5022e82019-12-13 15:20:25 -0800962add_subdirectory(build_tools/embed_data/)
963
Jacques Pienaar702929a2022-12-30 14:46:22 -0800964# 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/.
968add_subdirectory(tools)
Stella Laurenzo309dc5b2023-02-22 23:07:43 -0800969add_subdirectory(compiler)
Scott Todd4f16b992022-05-17 10:33:53 -0700970add_subdirectory(runtime)
971
Scott Todd315e2382024-01-30 13:35:51 -0800972# Note: Test deps are not built as part of all (use the iree-test-deps target).
973add_subdirectory(tests EXCLUDE_FROM_ALL)
974
Rob Sudermand42e0022022-06-08 16:38:45 -0700975if(IREE_ENABLE_CLANG_TIDY)
976 set(CMAKE_CXX_CLANG_TIDY "")
977endif()
978
Stella Laurenzod3770ff2021-10-18 22:54:18 -0700979if(IREE_BUILD_TRACY)
Ben Vanik77a87412023-10-09 14:46:28 -0700980 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 Laurenzod3770ff2021-10-18 22:54:18 -0700982 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()
987endif()
988
Scott Toddf57ab752022-05-23 10:36:44 -0700989# Order constraint: The python bindings install tools targets from tools/
Stella Laurenzod3770ff2021-10-18 22:54:18 -0700990# and tracy, and must come after it.
Stella Laurenzo3b44a0a2022-04-18 19:57:57 -0700991if(IREE_BUILD_PYTHON_BINDINGS)
Stella Laurenzo60128592022-04-17 21:52:09 -0700992 # 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 Toddfe9cb172022-12-08 09:17:52 -0800994 # it gets clobbered, it is fine (it is also ignored in .gitignore).
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -0700995 set(_PYTHONPATH_ENV "PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n")
Scott Toddfe9cb172022-12-08 09:17:52 -0800996 file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}")
997 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}")
Scott Todd2fe00a52023-11-09 10:46:49 -0800998 # Similarly, write out .env.bat and .env.ps1 for Windows.
Scott Toddfe9cb172022-12-08 09:17:52 -0800999 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 Todd2fe00a52023-11-09 10:46:49 -08001001 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 Laurenzo77a63cd2021-01-04 17:29:54 -08001003endif()
1004
Scott Todd1a1aea62022-04-28 09:12:11 -07001005if(IREE_BUILD_BINDINGS_TFLITE)
Scott Toddada25e62022-05-03 16:16:15 -07001006 add_subdirectory(runtime/bindings/tflite)
Ben Vanikcd1132f2021-01-29 15:58:17 -08001007endif()
1008
Scott Todd1a1aea62022-04-28 09:12:11 -07001009if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES)
Scott Todd15fce0a2022-02-14 12:43:23 -08001010 add_subdirectory(experimental/web)
Scott Toddf237b5e2022-01-28 11:02:25 -08001011endif()
1012
Benoit Jacob655b71a2024-04-23 11:07:38 -04001013if(IREE_BUILD_EXPERIMENTAL_HAL_EXECUTABLE_LIBRARY_CALL_HOOKS)
1014 add_subdirectory(experimental/hal_executable_library_call_hooks)
1015endif()
1016
Stella Laurenzo03e48db2020-06-11 18:35:13 -07001017set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}"
1018 CACHE INTERNAL "IREE: Include Directories" FORCE)
Stella Laurenzo688670f2021-09-24 18:16:25 -07001019
Jerry Wu623d1742022-03-31 18:16:02 +00001020#-------------------------------------------------------------------------------
Stella Laurenzoc6092c42023-03-25 19:55:37 -07001021# Optional features
Stella Laurenzo3b44a0a2022-04-18 19:57:57 -07001022#-------------------------------------------------------------------------------
1023
Scott Todd4c022df2022-05-10 16:55:18 -07001024# samples/ can depend on anything, so we include it last
Stella Laurenzo1e8d1fa2022-04-22 09:50:43 -07001025if(IREE_BUILD_SAMPLES)
1026 add_subdirectory(samples)
1027endif()
Geoffrey Martin-Noble10f18222022-06-09 16:00:13 -07001028
1029if(IREE_BUILD_TESTS)
1030 iree_create_ctest_customization()
1031endif()
Stella Laurenzo15c306f2023-12-28 19:03:20 -08001032
1033#-------------------------------------------------------------------------------
1034# Install/exports
Stella Laurenzo3e0583f2023-12-29 13:09:15 -08001035# Note that with no further options, install convenience targets install to
CindyLiu88697772024-01-05 04:22:30 +08001036# CMAKE_INSTALL_PREFIX. Per usual, this can be further prefixed with an
Stella Laurenzo3e0583f2023-12-29 13:09:15 -08001037# 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 Laurenzo15c306f2023-12-28 19:03:20 -08001042#-------------------------------------------------------------------------------
1043
1044add_subdirectory(build_tools/cmake ${IREE_BINARY_DIR}/lib/cmake/IREE)
1045
Stella Laurenzo15c306f2023-12-28 19:03:20 -08001046# Convenience installation targets.
Stella Laurenzo3e0583f2023-12-29 13:09:15 -08001047iree_add_install_target(NAME iree-install-dist)
1048iree_add_install_target(
1049 NAME iree-install-dev-libraries
1050 ADD_TO iree-install-dist
1051)
1052iree_add_install_target(
1053 NAME iree-install-runtime-libraries
1054 ADD_TO iree-install-dist
1055)
1056iree_add_install_target(
1057 NAME iree-install-tools
1058 ADD_TO iree-install-dist
1059)
Stella Laurenzo15c306f2023-12-28 19:03:20 -08001060
1061iree_add_install_target(
1062 NAME iree-install-cmake-exports
1063 COMPONENT IREECMakeExports
1064 ADD_TO iree-install-dev-libraries
1065)
1066
1067iree_add_install_target(
1068 NAME iree-install-dev-libraries-runtime
1069 COMPONENT IREEDevLibraries-Runtime
1070 ADD_TO iree-install-dev-libraries
1071)
1072
1073iree_add_install_target(
1074 NAME iree-install-bundled-libraries
1075 COMPONENT IREEBundledLibraries
1076 ADD_TO iree-install-dev-libraries-runtime
1077)
1078
1079if(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 Laurenzo3e0583f2023-12-29 13:09:15 -08001093 NAME iree-install-tools-compiler-dev
1094 COMPONENT IREETools-CompilerDev
1095 ADD_TO iree-install-tools
1096 )
1097
1098 iree_add_install_target(
CindyLiu88697772024-01-05 04:22:30 +08001099 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 Laurenzo15c306f2023-12-28 19:03:20 -08001107 NAME iree-install-runtime-libraries-compiler
1108 COMPONENT IREERuntimeLibraries-Compiler
CindyLiu88697772024-01-05 04:22:30 +08001109 ADD_TO
Stella Laurenzo15c306f2023-12-28 19:03:20 -08001110 iree-install-runtime-libraries
1111 iree-install-tools-compiler
1112 iree-install-dev-libraries-compiler
1113 )
1114endif()
1115
1116iree_add_install_target(
1117 NAME iree-install-tools-runtime
1118 COMPONENT IREETools-Runtime
1119 ADD_TO iree-install-tools
1120)