blob: 25d9a6556464f359d0c0b758d5f45b72725f5516 [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
Ben Vanik4aae0032022-04-19 15:49:26 -070063# TODO(#8469): remove the dependency on cpuinfo entirely.
Ben Vanikcbe93c02023-08-08 10:12:08 -070064set(IREE_ENABLE_CPUINFO_DEFAULT ON)
Ben Vanik62c4f982023-12-12 18:01:52 -080065if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Emscripten|Windows|WindowsStore")
Ben Vanikcbe93c02023-08-08 10:12:08 -070066 set(IREE_ENABLE_CPUINFO_DEFAULT OFF)
67endif()
68option(IREE_ENABLE_CPUINFO "Enables runtime use of cpuinfo for processor topology detection." ${IREE_ENABLE_CPUINFO_DEFAULT})
Ben Vanik4aae0032022-04-19 15:49:26 -070069
Marius Brehleredfc57f2019-12-18 11:19:38 -080070option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON)
Ben Vanik512d2d32019-09-20 13:22:34 -070071option(IREE_BUILD_TESTS "Builds IREE unit tests." ON)
Scott Todd96d92132023-06-12 15:45:19 -070072option(IREE_BUILD_DOCS "Builds IREE documentation files." OFF)
Ben Vanik6b112ef2019-10-03 10:45:14 -070073option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON)
Scott Todd382fc632022-06-06 10:57:24 -070074option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF)
Stella Laurenzod3770ff2021-10-18 22:54:18 -070075option(IREE_BUILD_TRACY "Builds tracy server tools." OFF)
Stella Laurenzo96d959e2023-02-19 11:58:14 -080076option(IREE_BUILD_BUNDLED_LLVM "Builds the bundled llvm-project (vs using installed)" ON)
Ben Vanikcd1132f2021-01-29 15:58:17 -080077
Scott Todd352da3f2022-07-20 15:25:11 -070078option(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER "Use the system linker when generating IREE modules in tests/samples/benchmarks (useful for Tracy)." OFF)
bjacob1af90ee2022-03-28 22:10:53 -040079
Stella Laurenzobb1de962021-01-05 08:18:33 -080080# Properties controlling version and naming of release artifacts.
Stella Laurenzof33f5b52022-01-08 17:49:52 +000081set(IREE_RELEASE_PACKAGE_SUFFIX "" CACHE STRING "Suffix to append to distributed package names")
Stella Laurenzobb1de962021-01-05 08:18:33 -080082set(IREE_RELEASE_VERSION "0.1a1" CACHE STRING "Version to embed in distributed packages")
83set(IREE_RELEASE_REVISION "HEAD" CACHE STRING "Version control revision information to embed in distributed packages")
Jacques Pienaar27779b22022-12-22 15:37:56 -080084option(IREE_EMBED_RELEASE_INFO "Embed the IREE version information in built artifacts." OFF)
Stella Laurenzobb1de962021-01-05 08:18:33 -080085
Scott Toddde426de2023-01-13 08:26:02 -080086# Using already built host binaries, such as for cross-compilation.
87set(IREE_HOST_BIN_DIR_DEFAULT "")
88if(IREE_HOST_BINARY_ROOT)
89 message(WARNING "IREE_HOST_BINARY_ROOT is deprecated. Use IREE_HOST_BIN_DIR"
90 " pointing directly to the directory containing binaries"
91 " instead.")
92 set(IREE_HOST_BIN_DIR_DEFAULT "${IREE_HOST_BINARY_ROOT}/bin")
93endif()
94set(IREE_HOST_BIN_DIR "${IREE_HOST_BIN_DIR_DEFAULT}" CACHE STRING "Path to directory containing IREE binary tools to use instead of building them from source.")
95
Ben Vanikcd1132f2021-01-29 15:58:17 -080096option(IREE_BUILD_BINDINGS_TFLITE "Builds the IREE TFLite C API compatibility shim" ON)
Kojo Acquah5bf39942021-04-22 16:01:28 -070097option(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 -080098
Jerry Wub6b1dee2022-06-01 13:45:16 +000099option(IREE_BUILD_MICROBENCHMARKS "Builds IREE microbenchmark suites." OFF)
100
Jerry Wu57404972023-03-02 22:16:11 +0000101option(IREE_BUILD_E2E_TEST_ARTIFACTS "Builds IREE E2E test artifacts suite generated by the e2e test framework." "${IREE_BUILD_EXPERIMENTAL_E2E_TEST_ARTIFACTS}")
Jerry Wufed372c2023-10-19 12:05:32 -0700102set(IREE_E2E_TEST_ARTIFACTS_DIR "" CACHE STRING "Set external prebuilt E2E test artifacts directory")
103if(IREE_BUILD_E2E_TEST_ARTIFACTS AND NOT "${IREE_E2E_TEST_ARTIFACTS_DIR}" STREQUAL "")
104 message(SEND_ERROR
105 "IREE_E2E_TEST_ARTIFACTS_DIR and IREE_BUILD_E2E_TEST_ARTIFACTS can't be"
106 " set at the same time."
107 )
108endif()
109
Boian Petkantchind4e39682023-07-31 10:09:16 -0700110option(IREE_ENABLE_COLLECTIVE_RUNTIME_TESTS "Enable runtime tests for collective operations." OFF)
Jerry Wu57404972023-03-02 22:16:11 +0000111
Stella Laurenzo289b9a12023-02-24 13:06:32 -0800112# For development, builds LLVM (and in the future) the whole compiler as
113# individual shared libraries similar to if passing -DBUILD_SHARED_LIBS=ON
114# to a standalone LLVM build. This can dramatically reduce linking time and
115# makes the management of some dependencies more strict.
116# This option is considered experimental and should not be relied on until
117# CI coverage is established.
118option(IREE_COMPILER_BUILD_SHARED_LIBS "Enables BUILD_SHARED_LIBS CMake mode for LLVM and the compiler (this is only suitable for development)" OFF)
119
120# Must be defined as an option (CMake does not do it automatically), even though
121# we override it for different parts of the tree.
122# This option is considered experimental and should not be relied on until
123# CI coverage is established.
124option(BUILD_SHARED_LIBS "Instructs CMake to build libraries as shared if possible" OFF)
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
bjacob2eda7672023-11-14 14:23:13 -0500186option(IREE_BUILD_EXPERIMENTAL_CPU_UKERNEL_PLUGINS "Build experimental plugins making builtin ukernels available to llvm-cpu modules compiled with --iree-llvmcpu-enable-ukernels" OFF)
Scott Toddf237b5e2022-01-28 11:02:25 -0800187option(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES "Builds experimental web samples." 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)
198find_package(CUDAToolkit)
199if(CUDAToolkit_FOUND)
200 set(IREE_CUDA_AVAILABLE ON)
201else()
202 # We can download the SDK in build_tools/third_party/cuda/CMakeLists.txt, if
203 # on a supported platform/arch.
204 if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR WIN32)
205 if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)")
206 set(IREE_CUDA_AVAILABLE ON)
207 endif()
Scott Todd9fa5de72023-01-23 14:40:18 -0800208 endif()
209endif()
210
211#-------------------------------------------------------------------------------
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800212# Runtime HAL Driver Options
213# By default, all runtime drivers supported by the current platform which do
214# not require external deps are enabled by default. This can be changed with:
215# -DIREE_HAL_DRIVER_DEFAULTS=OFF
Ben Vanik185d30c2019-09-19 14:24:11 -0700216#-------------------------------------------------------------------------------
217
Ben Vanik4e6af052022-06-07 17:10:20 -0700218# External HAL drivers; see runtime/src/iree/hal/drivers/CMakeLists.txt for more
219# information on how to declare external drivers.
220set(IREE_EXTERNAL_HAL_DRIVERS "" CACHE STRING "")
221
Ben Vanik89160272022-09-26 16:44:11 -0700222# Additional executable loader deps to add dependent libraries to any target
223# using the default executable loader registration utilities.
224# TODO(benvanik): extend the deps to encompass the built-in loaders too so that
225# we have one flag. We could also support a list of deps and automatically
226# generate the registration from that via a configure file.
227set(IREE_HAL_EXECUTABLE_LOADER_EXTRA_DEPS "" CACHE STRING "")
228
Ben Vanike19fc8e2023-04-14 16:08:01 -0700229# Additional executable import provider deps to add dependent libraries to any
230# target using the default executable import registration utilities.
231# TODO(benvanik): extend the deps to encompass the built-in imports too so that
232# we have one flag. We could also support a list of deps and automatically
233# generate the registration from that via a configure file.
234set(IREE_HAL_EXECUTABLE_PLUGIN_EXTRA_DEPS "" CACHE STRING "")
235
Scott Toddd1620f02021-12-22 14:55:38 -0800236option(IREE_HAL_DRIVER_DEFAULTS "Sets the default value for all runtime HAL drivers" ON)
Ben Vanika9aaebe2022-12-16 09:14:53 -0800237
Scott Todd9fa5de72023-01-23 14:40:18 -0800238# CUDA support is enabled by default if the platform supports the CUDA SDK and
239# not cross compiling. Note: a CUDA-compatible GPU with drivers is still
240# required to actually run CUDA workloads.
241set(IREE_HAL_DRIVER_CUDA_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS})
Scott Todd18a54852023-01-27 08:52:12 -0800242if(NOT IREE_CUDA_AVAILABLE OR CMAKE_CROSSCOMPILING)
Scott Todd9fa5de72023-01-23 14:40:18 -0800243 set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF)
244endif()
245
246# Vulkan support is enabled by default if the platform might support Vulkan.
247# Apple platforms support Metal instead of Vulkan, though MoltenVK may work.
248set(IREE_HAL_DRIVER_VULKAN_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS})
Scott Todd1a1aea62022-04-28 09:12:11 -0700249if(APPLE)
Scott Toddd1620f02021-12-22 14:55:38 -0800250 set(IREE_HAL_DRIVER_VULKAN_DEFAULT OFF)
Scott Toddd1620f02021-12-22 14:55:38 -0800251endif()
Marius Brehler0a4b67f2020-05-08 13:19:16 -0700252
Lei Zhangd1d03cb2023-08-07 13:52:56 -0400253# Metal support is enabled if it's one of the Apple platforms.
254set(IREE_HAL_DRIVER_METAL_DEFAULT ${IREE_HAL_DRIVER_DEFAULTS})
255# Right now only support Apple silicon devices.
256if(NOT APPLE OR NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
257 set(IREE_HAL_DRIVER_METAL_DEFAULT OFF)
258endif()
259
Scott Toddd1620f02021-12-22 14:55:38 -0800260option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT})
Ben Vanike3058072022-06-06 19:21:44 -0700261option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
262option(IREE_HAL_DRIVER_LOCAL_TASK "Enables the 'local-task' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
263option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT})
Lei Zhangd1d03cb2023-08-07 13:52:56 -0400264option(IREE_HAL_DRIVER_METAL "Enables the 'metal' runtime HAL driver" ${IREE_HAL_DRIVER_METAL_DEFAULT})
Ben Vanike3058072022-06-06 19:21:44 -0700265
Ben Vanik6e64b6e2022-06-07 09:14:53 -0700266option(IREE_HAL_EXECUTABLE_LOADER_DEFAULTS "Sets the default value for all runtime HAL executable loaders" ON)
267set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS})
268set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS})
269set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT ${IREE_HAL_EXECUTABLE_LOADER_DEFAULTS})
Ben Vanike3058072022-06-06 19:21:44 -0700270
Ben Vanike19fc8e2023-04-14 16:08:01 -0700271option(IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS "Sets the default value for all runtime HAL executable plugin mechanisms" ON)
272set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS})
273set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ${IREE_HAL_EXECUTABLE_PLUGIN_DEFAULTS})
274
Ben Vanike3058072022-06-06 19:21:44 -0700275# Emscripten builds don't support embedded ELF libraries.
276if(EMSCRIPTEN)
Ben Vanik2e8540e2022-06-06 20:39:34 -0700277 set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF)
Ben Vanike19fc8e2023-04-14 16:08:01 -0700278 set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF)
Ben Vanike3058072022-06-06 19:21:44 -0700279endif()
280
281# If forcing system libraries (for TSAN/debugging tools/etc) then ensure the
282# system library loader is linked in.
Scott Todd352da3f2022-07-20 15:25:11 -0700283if(IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER)
Ben Vanike3058072022-06-06 19:21:44 -0700284 set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT ON)
Ben Vanike19fc8e2023-04-14 16:08:01 -0700285 set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT ON)
Ben Vanike3058072022-06-06 19:21:44 -0700286endif()
287
Ben Vanike19fc8e2023-04-14 16:08:01 -0700288# If no local driver is enabled then we force all the loaders/imports off; this
289# allows for simpler checks that don't need to see if both the driver and
290# feature is available.
Ben Vanik6e64b6e2022-06-07 09:14:53 -0700291if(NOT IREE_HAL_DRIVER_LOCAL_SYNC AND NOT IREE_HAL_DRIVER_LOCAL_TASK)
292 set(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF_DEFAULT OFF)
293 set(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT OFF)
294 set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT OFF)
Ben Vanike19fc8e2023-04-14 16:08:01 -0700295 set(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT OFF)
296 set(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT OFF)
Ben Vanik6e64b6e2022-06-07 09:14:53 -0700297endif()
298
Ben Vanik2e8540e2022-06-06 20:39:34 -0700299option(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 -0700300option(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY "Enables the system dynamic library loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY_DEFAULT})
301option(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE "Enables the VMVX module loader for local HAL drivers" ${IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE_DEFAULT})
302
Ben Vanike19fc8e2023-04-14 16:08:01 -0700303option(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF "Enables the embedded dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF_DEFAULT})
304option(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY "Enables the system dynamic library plugin mechanism for local HAL drivers" ${IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY_DEFAULT})
305
Scott Todd0f1f8eb2022-06-10 15:53:30 -0700306if(IREE_BUILD_COMPILER)
307 # The compiler requires the local task driver with the VMVX loader.
308 set(IREE_HAL_DRIVER_LOCAL_TASK ON)
309 set(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE ON)
310endif()
311
Ben Vanike3058072022-06-06 19:21:44 -0700312message(STATUS "IREE HAL drivers:")
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800313if(IREE_HAL_DRIVER_CUDA)
314 message(STATUS " - cuda")
315endif()
Ben Vanike3058072022-06-06 19:21:44 -0700316if(IREE_HAL_DRIVER_LOCAL_SYNC)
317 message(STATUS " - local-sync")
318endif()
319if(IREE_HAL_DRIVER_LOCAL_TASK)
320 message(STATUS " - local-task")
321endif()
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800322if(IREE_HAL_DRIVER_VULKAN)
323 message(STATUS " - vulkan")
324endif()
Lei Zhangd1d03cb2023-08-07 13:52:56 -0400325if(IREE_HAL_DRIVER_METAL)
326 message(STATUS " - metal")
327endif()
Ben Vanik4e6af052022-06-07 17:10:20 -0700328if(IREE_EXTERNAL_HAL_DRIVERS)
329 message(STATUS " + external: ${IREE_EXTERNAL_HAL_DRIVERS}")
330endif()
Ben Vanik512d2d32019-09-20 13:22:34 -0700331
Ben Vanike3058072022-06-06 19:21:44 -0700332message(STATUS "IREE HAL local executable library loaders:")
Ben Vanik2e8540e2022-06-06 20:39:34 -0700333if(IREE_HAL_EXECUTABLE_LOADER_EMBEDDED_ELF)
334 message(STATUS " - embedded-elf")
Ben Vanike3058072022-06-06 19:21:44 -0700335endif()
336if(IREE_HAL_EXECUTABLE_LOADER_SYSTEM_LIBRARY)
337 message(STATUS " - system-library")
338endif()
339if(IREE_HAL_EXECUTABLE_LOADER_VMVX_MODULE)
340 message(STATUS " - vmvx-module")
341endif()
342
Ben Vanike19fc8e2023-04-14 16:08:01 -0700343message(STATUS "IREE HAL local executable plugin mechanisms:")
344if(IREE_HAL_EXECUTABLE_PLUGIN_EMBEDDED_ELF)
345 message(STATUS " - embedded-elf")
346endif()
347if(IREE_HAL_EXECUTABLE_PLUGIN_SYSTEM_LIBRARY)
348 message(STATUS " - system-library")
349endif()
350
Lei Zhang0d281b72020-06-01 20:00:23 -0400351#-------------------------------------------------------------------------------
Scott Todd382fc632022-06-06 10:57:24 -0700352# Compiler Target Options
Scott Todd9fa5de72023-01-23 14:40:18 -0800353# By default, all compiler targets supported by the current platform are
354# enabled. Some compiler targets like CUDA will install external deps as
355# needed at configure time. This can be changed with:
Scott Todd382fc632022-06-06 10:57:24 -0700356# -DIREE_TARGET_BACKEND_DEFAULTS=OFF
357#-------------------------------------------------------------------------------
358
359option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ON)
360
361# The VMVX backend is always enabled.
362cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
363
364# Supported default target backends.
Scott Todd352da3f2022-07-20 15:25:11 -0700365cmake_dependent_option(IREE_TARGET_BACKEND_LLVM_CPU "Enables the 'llvm-cpu' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
366cmake_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 -0700367cmake_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 -0700368cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
369
Stella Laurenzo58b56702023-10-05 15:05:58 -0700370# Default target backends that are not yet fully supported but are being brought up.
371cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
372
Scott Todd9fa5de72023-01-23 14:40:18 -0800373# Supported default target backends that are only available on certain
374# platforms.
375set(IREE_TARGET_BACKEND_CUDA_DEFAULT ${IREE_TARGET_BACKEND_DEFAULTS})
Scott Todd18a54852023-01-27 08:52:12 -0800376if(NOT IREE_CUDA_AVAILABLE)
Scott Todd9fa5de72023-01-23 14:40:18 -0800377 set(IREE_TARGET_BACKEND_CUDA_DEFAULT OFF)
378endif()
379cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" ${IREE_TARGET_BACKEND_CUDA_DEFAULT} ${IREE_BUILD_COMPILER} OFF)
380
Scott Todd382fc632022-06-06 10:57:24 -0700381# Non-default target backends either have additional dependencies or are
382# experimental/niche in some fashion.
Scott Todd382fc632022-06-06 10:57:24 -0700383# Disable WebGPU by default - it has complex deps and is under development.
384cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
385
386#-------------------------------------------------------------------------------
Scott Todde23d4a72022-07-27 14:16:39 -0700387# Compiler Input Dialects
388#-------------------------------------------------------------------------------
389
Jakub Kuderski0dbf0862023-06-12 14:33:06 -0400390cmake_dependent_option(IREE_INPUT_STABLEHLO "Builds support for compiling StableHLO programs" ON ${IREE_BUILD_COMPILER} OFF)
Scott Todde23d4a72022-07-27 14:16:39 -0700391cmake_dependent_option(IREE_INPUT_TORCH "Builds support for compiling Torch MLIR programs" ON ${IREE_BUILD_COMPILER} OFF)
392cmake_dependent_option(IREE_INPUT_TOSA "Builds support for compiling TOSA programs" ON ${IREE_BUILD_COMPILER} OFF)
393
Marius Brehler36f24512022-08-04 17:39:03 +0200394if(IREE_BUILD_COMPILER)
395 message(STATUS "IREE compiler input dialects:")
Jakub Kuderski0dbf0862023-06-12 14:33:06 -0400396 if(IREE_INPUT_STABLEHLO)
397 message(STATUS " - StableHLO")
Marius Brehler36f24512022-08-04 17:39:03 +0200398 endif()
399 if(IREE_INPUT_TORCH)
400 message(STATUS " - Torch MLIR")
401 endif()
402 if(IREE_INPUT_TOSA)
403 message(STATUS " - TOSA")
404 endif()
Scott Todde23d4a72022-07-27 14:16:39 -0700405endif()
406
407#-------------------------------------------------------------------------------
Scott Todd2a1925c2022-06-13 10:03:52 -0700408# Compiler Output Formats
409#-------------------------------------------------------------------------------
410
Scott Todd2a1925c2022-06-13 10:03:52 -0700411cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, using MLIR EmitC" ON ${IREE_BUILD_COMPILER} OFF)
412
Marius Brehler36f24512022-08-04 17:39:03 +0200413if(IREE_BUILD_COMPILER)
414 message(STATUS "IREE compiler output formats:")
415 if(IREE_OUTPUT_FORMAT_C)
Ben Vanik09630d62023-04-13 14:21:40 -0700416 message(STATUS " - 'vm-c': textual C source module")
Marius Brehler36f24512022-08-04 17:39:03 +0200417 endif()
418 # The 'vm-bytecode' and 'vm-asm' formats are always enabled.
Ben Vanik09630d62023-04-13 14:21:40 -0700419 message(STATUS " - 'vm-bytecode': VM bytecode")
420 message(STATUS " - 'vm-asm': VM MLIR assembly")
Scott Todde23d4a72022-07-27 14:16:39 -0700421endif()
Scott Todde23d4a72022-07-27 14:16:39 -0700422
Scott Todd2a1925c2022-06-13 10:03:52 -0700423#-------------------------------------------------------------------------------
Lei Zhange88470f2020-09-08 13:21:09 -0400424# IREE compilation toolchain configuration
425#-------------------------------------------------------------------------------
426
Lei Zhange88470f2020-09-08 13:21:09 -0400427option(IREE_ENABLE_ASAN "Enable address sanitizer" OFF)
428option(IREE_ENABLE_MSAN "Enable memory sanitizer" OFF)
429option(IREE_ENABLE_TSAN "Enable thread sanitizer" OFF)
bjacob0e038522023-06-08 18:16:32 -0400430option(IREE_BYTECODE_MODULE_ENABLE_ASAN "Enable address sanitizer in IREE modules in tests" OFF)
bjacob7cf5b842022-04-04 16:48:04 -0400431option(IREE_BYTECODE_MODULE_ENABLE_TSAN "Enable thread sanitizer in IREE modules in tests" OFF)
Jakub Kuderski068b1722022-07-27 18:14:59 -0400432option(IREE_ENABLE_UBSAN "Enable undefined behavior sanitizer" OFF)
Stella Laurenzodeb48052022-11-25 10:41:46 -0800433option(IREE_ENABLE_SPLIT_DWARF "Enable gsplit-dwarf for debug information if the platform supports it" OFF)
434option(IREE_ENABLE_THIN_ARCHIVES "Enables thin ar archives (elf systems only). Disable for released static archives" OFF)
Ben Vanikadadd032022-11-28 23:18:16 -0800435option(IREE_LINK_COMPILER_SHARED_LIBRARY "Links IREE tools using the compiler compiled into a shared library" ON)
bjacob7cf5b842022-04-04 16:48:04 -0400436
437# STREQUAL feels wrong here - we don't care about the exact true-value used,
438# ON or TRUE or something else. But we haven't been able to think of a less bad
Scott Toddc7b29122023-02-21 17:33:35 -0800439# alternative. https://github.com/openxla/iree/pull/8474#discussion_r840790062
bjacob7cf5b842022-04-04 16:48:04 -0400440if(NOT IREE_ENABLE_TSAN STREQUAL IREE_BYTECODE_MODULE_ENABLE_TSAN)
441 message(SEND_ERROR
442 "IREE_ENABLE_TSAN and IREE_BYTECODE_MODULE_ENABLE_TSAN must be "
443 "simultaneously ON or OFF. "
444 "A discrepancy between the two would cause tests to crash as IREE "
445 "runtime code (controlled by IREE_ENABLE_TSAN) calls into test IREE "
446 "modules (controlled by IREE_BYTECODE_MODULE_ENABLE_TSAN)")
447endif()
448
Peyman B66b10cc2023-11-15 17:14:14 +0100449if(IREE_BUILD_COMPILER)
450 if(IREE_BYTECODE_MODULE_ENABLE_ASAN OR IREE_BYTECODE_MODULE_ENABLE_TSAN)
451 if(NOT IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER)
452 message(SEND_ERROR
453 "When IREE_BYTECODE_MODULE_ENABLE_ASAN or IREE_BYTECODE_MODULE_ENABLE_TSAN is ON, "
454 "IREE_BYTECODE_MODULE_FORCE_LLVM_SYSTEM_LINKER must also be ON. "
455 "ASAN/TSAN instrumentation is not currently supported in embedded modules.")
456 endif()
bjacob7cf5b842022-04-04 16:48:04 -0400457 endif()
458endif()
459
Scott Todd86781382023-02-07 14:11:52 -0800460if(IREE_LINK_COMPILER_SHARED_LIBRARY AND IREE_ENABLE_COMPILER_TRACING)
461 message(SEND_ERROR
462 "IREE_ENABLE_COMPILER_TRACING requires "
463 "-DIREE_LINK_COMPILER_SHARED_LIBRARY=OFF (the compiler library must not "
464 "be unloaded before Tracy finishes, static linking is one workaround)")
465endif()
466
Geoffrey Martin-Noble61ea1ed2022-11-23 16:25:57 -0800467option(IREE_ENABLE_CCACHE
468 "[DEPRECATED: Use CMAKE_<LANG>_COMPILER_LAUNCHER configure options or environment variables instead.] Use ccache if installed."
469 OFF)
bjacobe694d952020-11-03 12:05:35 -0500470
Scott Todd1a1aea62022-04-28 09:12:11 -0700471if(IREE_ENABLE_CCACHE)
Geoffrey Martin-Noble61ea1ed2022-11-23 16:25:57 -0800472 message(WARNING
473 "IREE_ENABLE_CCACHE is deprecated. Use CMAKE_<LANG>_COMPILER_LAUNCHER"
474 " configure options or environment variables instead.")
bjacobe694d952020-11-03 12:05:35 -0500475 find_program(CCACHE_PROGRAM ccache)
476 if(CCACHE_PROGRAM)
477 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
Geoffrey Martin-Noble61ea1ed2022-11-23 16:25:57 -0800478 else()
479 message(SEND_ERROR
480 "IREE_ENABLE_CCACHE was set, but executable `ccache` was not found.")
bjacobe694d952020-11-03 12:05:35 -0500481 endif()
482endif()
Lei Zhange88470f2020-09-08 13:21:09 -0400483
Geoffrey Martin-Noble3fa4f8d2021-09-10 09:25:27 -0700484option(IREE_DEV_MODE "Configure settings to optimize for IREE development (as opposed to CI or release)" OFF)
Stella Laurenzo5b639122021-06-18 14:44:10 -0700485
486#-------------------------------------------------------------------------------
487# IREE assertions
488# We don't love the way this is done, but we have to line it up with how LLVM
489# does it and not diverge, since all implementations and all header users must
490# have the same definition of NDEBUG.
491#
492# LLVM defaults LLVM_ENABLE_ASSERTIONS to ON for Debug builds only but then
493# conditions itself to only update flags if not building Debug. We just let
494# IREE_ENABLE_ASSERTIONS be not conditioned on anything and only update the
495# flags in appropriate build types.
496#
497# If IREE_ENABLE_ASSERTIONS is set ON manually, then
498# - NDEBUG must be undefined
499# - LLVM_ENABLE_ASSERTIONS is forced off in order to keep multiple parties
500# from mucking with globals.
501#
502# Since CMake forces NDEBUG for !Debug builds, some surgery needs to be done
503# at the top level to avoid divergence.
504#-------------------------------------------------------------------------------
505
506option(IREE_ENABLE_ASSERTIONS "Force unset of NDEBUG compile option" OFF)
507
508# Filter -DNDEBUG from CMAKE_CXX_FLAGS_* and CMAKE_C_FLAGS_* (if
509# CMAKE_BUILD_TYPE is not Debug).
510function(iree_fix_ndebug)
Scott Todd1a1aea62022-04-28 09:12:11 -0700511 string(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPERCASE_CMAKE_BUILD_TYPE)
512 if(IREE_ENABLE_ASSERTIONS AND NOT "${_UPPERCASE_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
Stella Laurenzo5b639122021-06-18 14:44:10 -0700513 # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
Scott Todd1a1aea62022-04-28 09:12:11 -0700514 foreach(_FLAGS_VAR_TO_SCRUB
515 CMAKE_CXX_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE}
516 CMAKE_C_FLAGS_${_UPPERCASE_CMAKE_BUILD_TYPE})
517 set(_ORIGINAL_FLAGS "${${_FLAGS_VAR_TO_SCRUB}}")
518 string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " _ALTERED_FLAGS "${_ORIGINAL_FLAGS}")
519 if(NOT "${_ORIGINAL_FLAGS}" STREQUAL "${_ALTERED_FLAGS}")
Stella Laurenzo5b639122021-06-18 14:44:10 -0700520 message(STATUS
Scott Todd1a1aea62022-04-28 09:12:11 -0700521 "IREE_ENABLE_ASSERTIONS force disabled NDEBUG for ${_FLAGS_VAR_TO_SCRUB}: '${_ORIGINAL_FLAGS}' -> '${_ALTERED_FLAGS}'")
522 set(${_FLAGS_VAR_TO_SCRUB} "${_ALTERED_FLAGS}" PARENT_SCOPE)
Stella Laurenzo5b639122021-06-18 14:44:10 -0700523 endif()
524 endforeach()
525
526 # Make sure that LLVM doesn't add its own logic for assertion disabling.
527 # We'd like to make sure that we are not dueling over globals.
528 set(LLVM_ENABLE_ASSERTIONS OFF PARENT_SCOPE)
529 endif()
530endfunction()
531iree_fix_ndebug()
532
Lei Zhange88470f2020-09-08 13:21:09 -0400533#-------------------------------------------------------------------------------
Lei Zhang7e253da2020-06-10 07:51:19 -0700534# IREE utility definitions
Lei Zhang0d281b72020-06-01 20:00:23 -0400535#-------------------------------------------------------------------------------
536
Scott Toddd1620f02021-12-22 14:55:38 -0800537list(APPEND CMAKE_MODULE_PATH
538 ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
Scott Toddd1620f02021-12-22 14:55:38 -0800539)
540
Ben Vanik512d2d32019-09-20 13:22:34 -0700541include(iree_macros)
Ben Vanik185d30c2019-09-19 14:24:11 -0700542include(iree_copts)
Ben Vanik6b112ef2019-10-03 10:45:14 -0700543include(iree_cc_binary)
Ben Vanik185d30c2019-09-19 14:24:11 -0700544include(iree_cc_library)
545include(iree_cc_test)
Scott Todd20d746a2023-01-12 09:11:59 -0800546include(iree_import_binary)
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800547include(iree_external_cmake_options)
Ben Vanikcc2aff92019-09-24 10:23:55 -0700548include(iree_tablegen_library)
Lei Zhang22f0e242020-03-30 12:09:20 -0700549include(iree_tablegen_doc)
CindyLiu40ed02d2021-04-22 16:16:28 +0000550include(iree_c_embed_data)
Ben Vanik7f6c57c2023-02-07 18:04:32 -0800551include(iree_bitcode_library)
Scott Todd11adcab2019-12-18 14:10:44 -0800552include(iree_bytecode_module)
Marius Brehler46e83312021-03-25 00:11:39 +0100553include(iree_c_module)
Stella Laurenzo94363e22020-12-15 13:46:14 -0800554include(iree_python)
Geoffrey Martin-Noblef0eaf372020-01-28 10:03:14 -0800555include(iree_lit_test)
Stella Laurenzo96d959e2023-02-19 11:58:14 -0800556include(iree_llvm)
Geoffrey Martin-Noble4526dcc2020-03-09 11:59:52 -0700557include(iree_add_all_subdirs)
Geoffrey Martin-Noblee5fd5b52020-03-31 11:31:30 -0700558include(iree_check_test)
bjacob5feef482021-10-21 16:53:58 -0400559include(iree_trace_runner_test)
Geoffrey Martin-Noble435c2702022-01-24 15:56:56 -0800560include(iree_native_test)
Geoffrey Martin-Noble2811e502022-01-25 09:44:40 -0800561include(iree_cc_binary_benchmark)
Geoffrey Martin-Noble66d48892021-10-29 12:24:58 -0700562include(iree_benchmark_suite)
Han-Chung Wanga6fbb762022-04-15 14:25:04 -0700563include(iree_microbenchmark_suite)
Scott Todd434ff0e2021-12-21 10:38:36 -0800564include(iree_hal_cts_test_suite)
CindyLiuae72b952022-08-23 15:26:08 -0700565include(iree_static_linker_test)
Jerry Wu116db872022-09-22 19:33:13 +0000566include(iree_fetch_artifact)
CindyLiu080198f2022-10-06 07:21:17 -0700567include(iree_run_module_test)
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800568include(iree_plugin_register)
Ben Vanik185d30c2019-09-19 14:24:11 -0700569
Stella Laurenzobe0f1e12023-04-03 13:34:38 -0700570# Default any sub-tree which doesn't provide its own package namespacing
571# to derive it relative to this directory and prefixed with iree/.
572set(IREE_PACKAGE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
Lei Zhang923535d2023-04-06 18:07:43 -0400573set(IREE_PACKAGE_ROOT_PREFIX "iree")
Stella Laurenzobe0f1e12023-04-03 13:34:38 -0700574
Marius Brehler06ac36e2020-01-10 14:44:11 -0800575set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
576
Ben Vanik185d30c2019-09-19 14:24:11 -0700577#-------------------------------------------------------------------------------
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800578# Experimental next-generation CUDA HAL driver
579# Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=cuda2
580#-------------------------------------------------------------------------------
581
582iree_register_external_hal_driver(
583 NAME
584 cuda2
Peyman B66b10cc2023-11-15 17:14:14 +0100585 SOURCE_DIR
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800586 "${CMAKE_CURRENT_SOURCE_DIR}/experimental/cuda2"
587 DRIVER_TARGET
588 iree::experimental::cuda2::registration
589 REGISTER_FN
590 iree_hal_cuda2_driver_module_register
591)
592
593#-------------------------------------------------------------------------------
594# Experimental ROCM HAL driver
595# Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=rocm
596#-------------------------------------------------------------------------------
597
598iree_register_external_hal_driver(
599 NAME
600 rocm
Peyman B66b10cc2023-11-15 17:14:14 +0100601 SOURCE_DIR
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800602 "${CMAKE_CURRENT_SOURCE_DIR}/experimental/rocm"
603 DRIVER_TARGET
604 iree::experimental::rocm::registration
605 REGISTER_FN
606 iree_hal_rocm_driver_module_register
607)
608
609#-------------------------------------------------------------------------------
Nithin Meganathanef51eb62023-11-30 14:32:40 -0800610# Experimental HIP HAL driver
611# Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=hip
612#-------------------------------------------------------------------------------
613
614iree_register_external_hal_driver(
615 NAME
616 hip
Ben Vanik62c4f982023-12-12 18:01:52 -0800617 SOURCE_DIR
Nithin Meganathanef51eb62023-11-30 14:32:40 -0800618 "${CMAKE_CURRENT_SOURCE_DIR}/experimental/hip"
619 DRIVER_TARGET
620 iree::experimental::hip::registration
621 REGISTER_FN
622 iree_hal_hip_driver_module_register
623)
624
625#-------------------------------------------------------------------------------
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800626# Experimental WebGPU HAL driver
627# Enable with: -DIREE_EXTERNAL_HAL_DRIVERS=webgpu
628#-------------------------------------------------------------------------------
629
630iree_register_external_hal_driver(
631 NAME
632 webgpu
Peyman B66b10cc2023-11-15 17:14:14 +0100633 SOURCE_DIR
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800634 "${CMAKE_CURRENT_SOURCE_DIR}/experimental/webgpu"
Scott Todd50aa2cc2023-11-27 10:28:47 -0800635 BINARY_DIR
636 "${CMAKE_CURRENT_BINARY_DIR}/experimental/webgpu"
Stella Laurenzo2eb68622023-11-10 17:04:46 -0800637 DRIVER_TARGET
638 iree::experimental::webgpu::registration
639 REGISTER_FN
640 iree_hal_webgpu_driver_module_register
641)
642
643#-------------------------------------------------------------------------------
Lei Zhange88470f2020-09-08 13:21:09 -0400644# IREE compilation flags
Scott Todd29d654e2020-06-11 15:24:17 -0700645#-------------------------------------------------------------------------------
646
Lei Zhangdd21f322020-09-10 10:47:33 -0400647iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST})
648iree_append_list_to_string(CMAKE_CXX_FLAGS_DEBUG ${IREE_CXX_FLAGS_DEBUG_LIST})
Scott Todd29d654e2020-06-11 15:24:17 -0700649
650set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE)
651set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE)
652set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE)
653set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE)
654mark_as_advanced(
655 CMAKE_CXX_FLAGS_FASTBUILD
656 CMAKE_C_FLAGS_FASTBUILD
657 CMAKE_EXE_LINKER_FLAGS_FASTBUILD
658 CMAKE_SHARED_LINKER_FLAGS_FASTBUILD
659)
660
Scott Todd7649dee2022-07-18 11:31:46 -0700661# Override the system's default linker.
662# See also: https://llvm.org/docs/CMake.html#llvm-use-linker.
663set(IREE_USE_LINKER "" CACHE STRING "")
664# Equivalent to setting -DIREE_USE_LINKER=lld.
665# Note that unlike LLVM's LLVM_ENABLE_LLD, this does _not_ build lld. You will
666# need to either install a recent version of lld or build it from source prior
667# to setting this option. See also: https://lld.llvm.org/#using-lld.
668# This option is disabled on Apple platforms, where lld is not supported.
669cmake_dependent_option(IREE_ENABLE_LLD "Override the system's default linker to lld" OFF "NOT APPLE" OFF)
670
Scott Todd29d654e2020-06-11 15:24:17 -0700671include(iree_setup_toolchain)
672
673#-------------------------------------------------------------------------------
Stella Laurenzo29032b82021-10-14 15:21:44 -0700674# Python
675# If building features that require Python development, find them early in
676# one invocation (some CMake versions are sensitive to resolving out of order).
677# Otherwise, for features that just require the interpreter, find that alone.
Stella Laurenzoa3e97f12020-12-05 23:29:13 -0800678#-------------------------------------------------------------------------------
679
Stella Laurenzo29032b82021-10-14 15:21:44 -0700680if(IREE_BUILD_PYTHON_BINDINGS)
681 # After CMake 3.18, we are able to limit the scope of the search to just
682 # Development.Module. Searching for Development will fail in situations where
683 # the Python libraries are not available. When possible, limit to just
684 # Development.Module.
685 # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
Scott Todda24c8c52022-05-17 09:22:47 -0700686 #
687 # Configuring the Development.Module is flaky in multi-project setups.
688 # "Bootstrapping" by first looking for the optional Development component
689 # seems to be robust generally.
690 # See: https://reviews.llvm.org/D118148
Han-Chung Wang9ed3dab2023-08-30 14:25:24 -0700691 # If building Python packages, we have a hard requirement on 3.9+.
692 find_package(Python3 3.9 COMPONENTS Interpreter Development NumPy)
693 find_package(Python3 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
Stella Laurenzoacf0b272023-06-26 21:25:48 -0700694 # Some parts of the build use FindPython instead of FindPython3. Why? No
695 # one knows, but they are different. So make sure to bootstrap this one too.
696 # Not doing this here risks them diverging, which on multi-Python systems,
697 # can be troublesome. Note that nanobind requires FindPython.
698 set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
Han-Chung Wang9ed3dab2023-08-30 14:25:24 -0700699 find_package(Python 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
Stella Laurenzo3149b6d2021-10-24 18:45:17 -0700700elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS)
Stella Laurenzoa3e97f12020-12-05 23:29:13 -0800701 find_package(Python3 COMPONENTS Interpreter REQUIRED)
Stella Laurenzoacf0b272023-06-26 21:25:48 -0700702 set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
703 find_package(Python COMPONENTS Interpreter REQUIRED)
704endif()
705
706if(NOT "${Python_EXECUTABLE}" STREQUAL "${Python3_EXECUTABLE}")
707 message(WARNING "FindPython and FindPython3 found different executables. You may need to pin -DPython_EXECUTABLE and -DPython3_EXECUTABLE (${Python_EXECUTABLE} vs ${Python3_EXECUTABLE})")
Stella Laurenzoa3e97f12020-12-05 23:29:13 -0800708endif()
709
Stella Laurenzo3149b6d2021-10-24 18:45:17 -0700710# Extended Python environment checks.
711if(Python3_FOUND)
712 iree_detect_pyyaml()
713endif()
714
715if(IREE_BUILD_TESTS AND NOT IREE_PYYAML_FOUND)
716 message(WARNING "IREE's regression test suite requires PyYAML to run all tests. It is not installed, so some tests will be disabled.")
717endif()
718
Stella Laurenzoa3e97f12020-12-05 23:29:13 -0800719#-------------------------------------------------------------------------------
Niloy Sikdar47238df2021-07-28 23:37:33 +0530720# Check if git submodules have been initialized.
721# This will only run if python3 is available.
722#-------------------------------------------------------------------------------
723
Marius Brehler776d7e62021-12-21 22:50:52 +0100724option(IREE_ERROR_ON_MISSING_SUBMODULES "Error if submodules have not been initialized." ON)
725
Niloy Sikdar47238df2021-07-28 23:37:33 +0530726find_package(Python3 COMPONENTS Interpreter QUIET)
Scott Todde5b269a2021-11-16 15:25:02 -0800727find_package(Git)
Marius Brehler776d7e62021-12-21 22:50:52 +0100728if(IREE_ERROR_ON_MISSING_SUBMODULES AND Python3_FOUND AND Git_FOUND)
Scott Todde5b269a2021-11-16 15:25:02 -0800729 # Only check submodule status when the git commit changes.
Niloy Sikdar47238df2021-07-28 23:37:33 +0530730 execute_process(
Scott Todde5b269a2021-11-16 15:25:02 -0800731 COMMAND git rev-parse --short HEAD
Niloy Sikdar47238df2021-07-28 23:37:33 +0530732 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Scott Todde5b269a2021-11-16 15:25:02 -0800733 RESULT_VARIABLE SHORT_HASH_RESULT
734 OUTPUT_VARIABLE SHORT_HASH)
735 string(REGEX REPLACE "\n$" "" SHORT_HASH "${SHORT_HASH}")
Scott Todd2a8cd3b2021-12-13 11:58:44 -0800736 if(SHORT_HASH_RESULT EQUAL "0" AND NOT "${IREE_GIT_SHORT_HASH}" STREQUAL "${SHORT_HASH}")
CindyLiu0e8fdc62022-10-14 09:35:44 -0700737 if(NOT IREE_BUILD_COMPILER)
738 set(CHECK_SUBMODULE_ARGS "--runtime_only")
739 endif()
Scott Todde5b269a2021-11-16 15:25:02 -0800740 execute_process(
CindyLiu0e8fdc62022-10-14 09:35:44 -0700741 COMMAND ${Python3_EXECUTABLE} build_tools/scripts/git/check_submodule_init.py ${CHECK_SUBMODULE_ARGS}
Scott Todde5b269a2021-11-16 15:25:02 -0800742 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
743 RESULT_VARIABLE SUBMODULE_INIT_RESULT
744 )
745 if(NOT SUBMODULE_INIT_RESULT EQUAL "0")
746 message(FATAL_ERROR "check_submodule_init.py failed, see the logs above")
747 else()
748 set(IREE_GIT_SHORT_HASH "${SHORT_HASH}" CACHE STRING "" FORCE)
749 endif()
Niloy Sikdar47238df2021-07-28 23:37:33 +0530750 endif()
751endif()
752
753#-------------------------------------------------------------------------------
Lei Zhang22f0e242020-03-30 12:09:20 -0700754# IREE top-level targets
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800755# We define these here because various things in the build tree adds
756# dependencies to them.
Lei Zhang22f0e242020-03-30 12:09:20 -0700757#-------------------------------------------------------------------------------
758
Scott Todd1a1aea62022-04-28 09:12:11 -0700759if(IREE_BUILD_MICROBENCHMARKS)
Han-Chung Wanga6fbb762022-04-15 14:25:04 -0700760 # Add top-level custom targets to drive generating microbenchmark suites.
761 add_custom_target(iree-microbenchmark-suites)
762endif()
763
Scott Todd1a1aea62022-04-28 09:12:11 -0700764if(IREE_BUILD_DOCS)
Scott Todd96d92132023-06-12 15:45:19 -0700765 # Define a top-level custom target to drive generating documentation files.
766 # Add to the default target given that docs were explicitly requested.
Lei Zhang22f0e242020-03-30 12:09:20 -0700767 add_custom_target(iree-doc ALL)
768endif()
769
Jakub Kuderski3f764682023-02-07 17:14:23 -0500770# Samples may require additional files to be built/configured and will add
771# dependencies to this target.
772# Note: These will be automatically built with test dependencies
773# (`iree-test-deps`).
774add_custom_target(iree-sample-deps
775 COMMENT
776 "Building IREE sample data targets"
777)
778
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800779# Testing rules that require generation will add dependencies to this target.
780# This allows them to be EXCLUDE_FROM_ALL but still invokable.
Jakub Kuderski3f764682023-02-07 17:14:23 -0500781add_custom_target(iree-test-deps
782 COMMENT
783 "Building IREE test deps"
784 DEPENDS
785 iree-sample-deps
786)
Stella Laurenzo74b04b72022-03-02 10:21:11 -0800787
CindyLiu99373e02022-10-12 09:22:24 -0700788# Testing rules that generate test scripts for iree-run-module-test will add
789# dependencies to this target. It is a subset of `iree-test-deps`.
790add_custom_target(iree-run-module-test-deps
791 COMMENT
792 "Building IREE run module test targets"
793)
794
Stella Laurenzoe2dfc652023-02-15 18:12:03 -0800795# Convenience target for running IREE tests.
796add_custom_target(iree-run-tests
797 COMMENT
798 "Run IREE unit tests"
799 WORKING_DIRECTORY
800 "${CMAKE_CURRENT_BINARY_DIR}"
801 USES_TERMINAL
802 COMMAND
803 "${CMAKE_COMMAND}" -E echo
804 "The 'iree-run-tests' target is a helper for running ctest. For advanced"
805 "options, build dependencies and invoke ctest independently as in:"
806 COMMAND
807 "${CMAKE_COMMAND}" -E echo
808 " \\(cd ${CMAKE_CURRENT_BINARY_DIR} \\&\\& cmake --build . --target iree-test-deps \\&\\& ctest --output-on-failure\\)"
809 COMMAND
810 "${CMAKE_COMMAND}" -E echo
811 "Run tests in parallel by setting a variable like CTEST_PARALLEL_LEVEL=25."
812 COMMAND
813 "${CMAKE_CTEST_COMMAND}"
814 --output-on-failure
815)
816add_dependencies(iree-run-tests iree-test-deps)
817
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800818#-------------------------------------------------------------------------------
819# CUDA configuration for both the compiler and runtime.
820# We do this at the top level so that we can fail fast and make global
821# decisions that effect both compiler and runtime. It also helps with error
822# messaging to do this all in one place, since we can provide very targeted
823# advice.
824#-------------------------------------------------------------------------------
825
826set(IREE_CUDA_LIBDEVICE_PATH "" CACHE FILEPATH "Absolute path to an appropriate libdevice.*.bc (needed to build the IREE cuda compiler target)")
827
828# If any CUDA features are being built, try to locate a CUDA SDK. We will fall
829# back to this as needed for specific features.
830if(IREE_TARGET_BACKEND_CUDA OR IREE_HAL_DRIVER_CUDA)
831 add_subdirectory(build_tools/third_party/cuda EXCLUDE_FROM_ALL)
832endif()
833
834#-------------------------------------------------------------------------------
835# MLIR/LLVM Dependency
836#-------------------------------------------------------------------------------
837
838if(NOT IREE_BUILD_COMPILER)
839 message(STATUS "Not adding LLVM/MLIR because the configuration does not require it")
840else()
Stella Laurenzo289b9a12023-02-24 13:06:32 -0800841 # Force enable BUILD_SHARED_LIBS for the compiler if instructed.
842 set(_IREE_ORIG_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
843 if(IREE_COMPILER_BUILD_SHARED_LIBS)
844 set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
845 endif()
846
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800847 # Get the main LLVM deps.
848 if(IREE_BUILD_BUNDLED_LLVM)
849 iree_llvm_configure_bundled()
850 else()
851 iree_llvm_configure_installed()
852 endif()
853
854 # Also add a library that can be depended on to get LLVM includes setup
855 # properly. bazel_to_cmake targets this for some header only pseudo deps.
856 add_library(IREELLVMIncludeSetup INTERFACE)
857 target_include_directories(IREELLVMIncludeSetup INTERFACE
858 ${LLVM_INCLUDE_DIRS}
859 ${MLIR_INCLUDE_DIRS}
860 ${LLD_INCLUDE_DIRS}
861 )
862
863 # Splice the includes setup into base LLVM libraries so that using them
864 # gets everything nice and tidy. It would be super if some day, LLVM
865 # libraries set their right usage requirements for includes. In the meantime
866 # we add usage requirements to libraries at the root of all things LLVM.
867 iree_llvm_add_usage_requirements(LLVMSupport IREELLVMIncludeSetup)
868 iree_llvm_add_usage_requirements(MLIRSupport IREELLVMIncludeSetup)
869
Scott Todd53af6812023-11-27 10:33:08 -0800870 # Add external projects.
871
872 message(STATUS "Configuring llvm-external-projects/mlir-iree-dialects")
873 list(APPEND CMAKE_MESSAGE_INDENT " ")
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800874 iree_llvm_add_external_project(mlir-iree-dialects ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects)
Scott Todd53af6812023-11-27 10:33:08 -0800875 list(POP_BACK CMAKE_MESSAGE_INDENT)
876
Stella Laurenzofd9cd2f2023-11-01 16:22:00 -0700877 if(IREE_INPUT_STABLEHLO)
Scott Todd53af6812023-11-27 10:33:08 -0800878 message(STATUS "Configuring third_party/stablehlo")
879 list(APPEND CMAKE_MESSAGE_INDENT " ")
Stella Laurenzofd9cd2f2023-11-01 16:22:00 -0700880 iree_llvm_add_external_project(stablehlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stablehlo)
Scott Todd53af6812023-11-27 10:33:08 -0800881 list(POP_BACK CMAKE_MESSAGE_INDENT)
Stella Laurenzofd9cd2f2023-11-01 16:22:00 -0700882 endif()
Ben Vanike3578d52023-09-12 09:35:11 -0700883
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800884 # Ensure that LLVM-based dependencies needed for testing are included.
885 add_dependencies(iree-test-deps FileCheck)
886 if(IREE_LLD_TARGET)
887 add_dependencies(iree-test-deps ${IREE_LLD_TARGET})
888 endif()
889 if(IREE_CLANG_TARGET)
890 add_dependencies(iree-test-deps ${IREE_CLANG_TARGET})
891 endif()
Stella Laurenzo289b9a12023-02-24 13:06:32 -0800892
893 set(BUILD_SHARED_LIBS ${_IREE_ORIG_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800894endif()
895
896#-------------------------------------------------------------------------------
897# Other dependencies
898#-------------------------------------------------------------------------------
899
900include(external_cc_library)
901include(flatbuffer_c_library)
902
903add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL)
904add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL)
905add_subdirectory(build_tools/third_party/tracy_client EXCLUDE_FROM_ALL)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800906
907iree_set_googletest_cmake_options()
908add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
909
910if(IREE_ENABLE_THREADING)
911 iree_set_benchmark_cmake_options()
912 add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL)
913 if(IREE_ENABLE_CPUINFO)
914 iree_set_cpuinfo_cmake_options()
915 add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL)
916 endif()
917endif()
918
919# This defines the iree-flatcc-cli target, so we don't use EXCLUDE_FROM_ALL.
920add_subdirectory(build_tools/third_party/flatcc)
921
922if(IREE_HAL_DRIVER_CUDA)
923 add_subdirectory(build_tools/third_party/nccl EXCLUDE_FROM_ALL)
924endif()
925
926if(IREE_HAL_DRIVER_VULKAN)
927 add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL)
928endif()
929
930if(IREE_BUILD_COMPILER)
Jakub Kuderski3546f2a2023-06-14 13:18:44 -0400931 add_subdirectory(build_tools/third_party/stablehlo EXCLUDE_FROM_ALL)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800932endif()
933
934if(IREE_BUILD_TESTS)
935 include(iree_configure_testing)
936endif()
937
938if(IREE_BUILD_PYTHON_BINDINGS)
Stella Laurenzoabe91fa2023-06-26 16:57:30 -0700939 # The compiler uses pybind11
940 if(IREE_BUILD_COMPILER)
941 if(NOT TARGET pybind11::module)
942 message(STATUS "Using bundled pybind11")
943 add_subdirectory(third_party/pybind11 EXCLUDE_FROM_ALL)
944 else()
945 message(STATUS "Not including bundled pybind11 (already configured)")
946 endif()
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800947 endif()
948endif()
949
950if(IREE_TARGET_BACKEND_METAL_SPIRV)
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800951 # SPIRV-Cross is needed to cross compile SPIR-V into MSL source code.
Scott Toddad321b62023-06-05 14:39:30 -0700952 iree_set_spirv_cross_cmake_options()
Stella Laurenzo9be15aa2023-02-21 17:00:29 -0800953 add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL)
954endif()
955
Lei Zhang22f0e242020-03-30 12:09:20 -0700956#-------------------------------------------------------------------------------
Ben Vanik185d30c2019-09-19 14:24:11 -0700957# IREE top-level libraries
958#-------------------------------------------------------------------------------
959
Rob Sudermand42e0022022-06-08 16:38:45 -0700960if(IREE_ENABLE_CLANG_TIDY)
961 set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=*)
962endif()
963
Marius Brehlerf5022e82019-12-13 15:20:25 -0800964add_subdirectory(build_tools/embed_data/)
965
Jerry Wu36641f92023-05-24 19:30:38 +0000966if(IREE_BUILD_E2E_TEST_ARTIFACTS)
Stella Laurenzoa6bf65c2022-01-11 20:47:51 -0800967 find_program(IREE_IMPORT_TFLITE_PATH iree-import-tflite)
968 if(IREE_IMPORT_TFLITE_PATH)
969 message(STATUS "Found ${IREE_IMPORT_TFLITE_PATH} to generate benchmark artifacts")
970 else()
971 message(STATUS "iree-import-tflite not found. Some benchmarks may not configure")
972 endif()
Jerry Wu60798ca2022-06-21 23:36:40 +0000973 find_program(IREE_IMPORT_TF_PATH iree-import-tf)
974 if(IREE_IMPORT_TF_PATH)
975 message(STATUS "Found ${IREE_IMPORT_TF_PATH} to generate benchmark artifacts")
976 else()
977 message(STATUS "iree-import-tf not found. Some benchmarks may not configure")
978 endif()
Jerry Wufed372c2023-10-19 12:05:32 -0700979
980 set(IREE_E2E_TEST_ARTIFACTS_DIR "${IREE_BINARY_DIR}/e2e_test_artifacts")
Jerry Wu16e2d9c2022-11-22 06:19:46 +0000981endif()
982
983# Note: Test deps are not built as part of all (use the iree-test-deps target).
984add_subdirectory(tests EXCLUDE_FROM_ALL)
985
Jacques Pienaar702929a2022-12-30 14:46:22 -0800986# tools/ can depend on compiler/ and runtime/.
987# Note: tools sub directory is added before compiler/ so that phony targets for
988# files with the same names from different rules are disambiguated towards
989# those in tools/.
990add_subdirectory(tools)
Stella Laurenzo309dc5b2023-02-22 23:07:43 -0800991add_subdirectory(compiler)
Scott Todd4f16b992022-05-17 10:33:53 -0700992add_subdirectory(runtime)
993
Rob Sudermand42e0022022-06-08 16:38:45 -0700994if(IREE_ENABLE_CLANG_TIDY)
995 set(CMAKE_CXX_CLANG_TIDY "")
996endif()
997
Stella Laurenzod3770ff2021-10-18 22:54:18 -0700998if(IREE_BUILD_TRACY)
Ben Vanik77a87412023-10-09 14:46:28 -0700999 if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux")
1000 message(WARNING "Building Tracy (IREE_BUILD_TRACY) on non-Darwin/Linux is unsupported and may fail below.")
Stella Laurenzod3770ff2021-10-18 22:54:18 -07001001 endif()
1002 add_subdirectory(build_tools/third_party/tracy ${CMAKE_CURRENT_BINARY_DIR}/tracy)
1003 if(NOT TARGET IREETracyCaptureServer)
1004 message(SEND_ERROR "Could not build Tracy. Either unset IREE_BUILD_TRACY or look for missing dependencies above and install them.")
1005 endif()
1006endif()
1007
Scott Toddf57ab752022-05-23 10:36:44 -07001008# Order constraint: The python bindings install tools targets from tools/
Stella Laurenzod3770ff2021-10-18 22:54:18 -07001009# and tracy, and must come after it.
Stella Laurenzo3b44a0a2022-04-18 19:57:57 -07001010if(IREE_BUILD_PYTHON_BINDINGS)
Stella Laurenzo60128592022-04-17 21:52:09 -07001011 # Write out a .env file to make IDEs and developers happy.
1012 # Yes, we are writing this to the source dir. It is only for IDEs and if
Scott Toddfe9cb172022-12-08 09:17:52 -08001013 # it gets clobbered, it is fine (it is also ignored in .gitignore).
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -07001014 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 -08001015 file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}")
1016 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}")
Scott Todd2fe00a52023-11-09 10:46:49 -08001017 # Similarly, write out .env.bat and .env.ps1 for Windows.
Scott Toddfe9cb172022-12-08 09:17:52 -08001018 set(_PYTHONPATH_ENV_BAT "set PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n")
1019 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.bat" CONTENT "${_PYTHONPATH_ENV_BAT}")
Scott Todd2fe00a52023-11-09 10:46:49 -08001020 set(_PYTHONPATH_ENV_PS1 "$env:PYTHONPATH = '$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>'\n")
1021 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.ps1" CONTENT "${_PYTHONPATH_ENV_PS1}")
Stella Laurenzo77a63cd2021-01-04 17:29:54 -08001022endif()
1023
Scott Todd1a1aea62022-04-28 09:12:11 -07001024if(IREE_BUILD_BINDINGS_TFLITE)
Scott Toddada25e62022-05-03 16:16:15 -07001025 add_subdirectory(runtime/bindings/tflite)
Ben Vanikcd1132f2021-01-29 15:58:17 -08001026endif()
1027
Scott Todd1a1aea62022-04-28 09:12:11 -07001028if(IREE_BUILD_EXPERIMENTAL_WEB_SAMPLES)
Scott Todd15fce0a2022-02-14 12:43:23 -08001029 add_subdirectory(experimental/web)
Scott Toddf237b5e2022-01-28 11:02:25 -08001030endif()
1031
bjacob3dc368e2023-05-09 12:50:18 -04001032if(IREE_BUILD_EXPERIMENTAL_CPU_UKERNEL_PLUGINS)
1033 add_subdirectory(experimental/cpu_ukernel)
1034endif()
1035
Stella Laurenzo03e48db2020-06-11 18:35:13 -07001036set(IREE_PUBLIC_INCLUDE_DIRS "${IREE_COMMON_INCLUDE_DIRS}"
1037 CACHE INTERNAL "IREE: Include Directories" FORCE)
Stella Laurenzo688670f2021-09-24 18:16:25 -07001038
Jerry Wu623d1742022-03-31 18:16:02 +00001039#-------------------------------------------------------------------------------
Jerry Wu161daa72023-05-22 22:08:49 +00001040# IREE build tools
Jerry Wu623d1742022-03-31 18:16:02 +00001041#-------------------------------------------------------------------------------
1042
1043add_subdirectory(build_tools/benchmarks)
Jerry Wu161daa72023-05-22 22:08:49 +00001044add_subdirectory(build_tools/github_actions)
Jerry Wu71562cc2022-09-20 18:56:41 -07001045add_subdirectory(build_tools/python)
1046
1047#-------------------------------------------------------------------------------
Stella Laurenzoc6092c42023-03-25 19:55:37 -07001048# Optional features
Stella Laurenzo3b44a0a2022-04-18 19:57:57 -07001049#-------------------------------------------------------------------------------
1050
Scott Todd4c022df2022-05-10 16:55:18 -07001051# samples/ can depend on anything, so we include it last
Stella Laurenzo1e8d1fa2022-04-22 09:50:43 -07001052if(IREE_BUILD_SAMPLES)
1053 add_subdirectory(samples)
1054endif()
Geoffrey Martin-Noble10f18222022-06-09 16:00:13 -07001055
1056if(IREE_BUILD_TESTS)
1057 iree_create_ctest_customization()
1058endif()