blob: 1017273f4057446e1c3895d2ed17424c4e44e866 [file] [log] [blame]
Ben Vanik185d30c2019-09-19 14:24:11 -07001# Copyright 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Geoffrey Martin-Noble98bbd962019-11-21 07:27:39 -080015cmake_minimum_required(VERSION 3.12)
16if(POLICY CMP0077)
17 cmake_policy(SET CMP0077 NEW)
18endif()
Ben Vanik512d2d32019-09-20 13:22:34 -070019set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Ben Vanik185d30c2019-09-19 14:24:11 -070020
21#-------------------------------------------------------------------------------
22# Project configuration
23#-------------------------------------------------------------------------------
24
Marius Brehler178c82a2019-12-27 15:00:04 -080025project(iree CXX C)
Ben Vanik185d30c2019-09-19 14:24:11 -070026set(IREE_IDE_FOLDER IREE)
27set_property(GLOBAL PROPERTY USE_FOLDERS ON)
28
Ben Vanik512d2d32019-09-20 13:22:34 -070029option(IREE_ENABLE_DEBUG "Enables debugging of the VM." ON)
Stella Laurenzo06034152020-01-03 11:26:31 -080030option(IREE_ENABLE_LLVM "Enables LLVM dependencies." ON)
Ben Vanik512d2d32019-09-20 13:22:34 -070031option(IREE_ENABLE_TRACING "Enables WTF tracing." OFF)
32
Marius Brehleredfc57f2019-12-18 11:19:38 -080033option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON)
Ben Vanik512d2d32019-09-20 13:22:34 -070034option(IREE_BUILD_TESTS "Builds IREE unit tests." ON)
Ben Vanik6b112ef2019-10-03 10:45:14 -070035option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON)
Ben Vanik512d2d32019-09-20 13:22:34 -070036option(IREE_BUILD_DEBUGGER "Builds the IREE debugger app." OFF)
37
Marius Brehleredfc57f2019-12-18 11:19:38 -080038if(${IREE_BUILD_SAMPLES})
39 set(IREE_BUILD_COMPILER ON CACHE BOOL "Build the IREE compiler for sample projects." FORCE)
40endif()
41
Stella Laurenzo06034152020-01-03 11:26:31 -080042if(${IREE_BUILD_COMPILER})
43 set(IREE_ENABLE_LLVM ON CACHE BOOL "Enable LLVM dependencies if the IREE compiler is build." FORCE)
44endif()
45
Ben Vanik185d30c2019-09-19 14:24:11 -070046#-------------------------------------------------------------------------------
47# IREE-specific CMake configuration
48#-------------------------------------------------------------------------------
49
50list(APPEND CMAKE_MODULE_PATH
51 ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
52 ${CMAKE_CURRENT_LIST_DIR}/third_party/abseil-cpp/absl/copts/
53)
Ben Vanik512d2d32019-09-20 13:22:34 -070054
55include(iree_macros)
Ben Vanik185d30c2019-09-19 14:24:11 -070056include(iree_copts)
Ben Vanik6b112ef2019-10-03 10:45:14 -070057include(iree_cc_binary)
Ben Vanik185d30c2019-09-19 14:24:11 -070058include(iree_cc_library)
59include(iree_cc_test)
Ben Vanikcc2aff92019-09-24 10:23:55 -070060include(iree_tablegen_library)
Scott Todd11adcab2019-12-18 14:10:44 -080061include(iree_cc_embed_data)
62include(iree_bytecode_module)
Marius Brehler9dd6c662020-01-10 13:20:33 -080063include(iree_glslang)
64include(iree_glsl_vulkan)
65include(iree_spirv_kernel_cc_library)
Ben Vanik185d30c2019-09-19 14:24:11 -070066
Ben Vanikb8fe0862019-09-25 09:26:03 -070067string(JOIN " " CMAKE_CXX_FLAGS ${IREE_DEFAULT_COPTS})
68
Ben Vanik185d30c2019-09-19 14:24:11 -070069#-------------------------------------------------------------------------------
70# Third-party dependencies
71#-------------------------------------------------------------------------------
72
Scott Todd4af17b62019-12-17 16:47:00 -080073if(${IREE_BUILD_COMPILER})
74 # Compiler dependencies require Python.
75 # Find version 3+ first, so CMake doesn't find a lower version like 2.7 first.
76 find_package(PythonInterp 3 REQUIRED)
77 find_package(PythonLibs 3 REQUIRED)
78endif()
79
Ben Vanikcc2aff92019-09-24 10:23:55 -070080list(APPEND CMAKE_MODULE_PATH
81 ${CMAKE_CURRENT_LIST_DIR}/third_party/flatbuffers/CMake/
82)
83
Ben Vanik512d2d32019-09-20 13:22:34 -070084include(external_cc_library)
85include(flatbuffer_cc_library)
86
87add_subdirectory(build_tools/third_party/ruy EXCLUDE_FROM_ALL)
Ben Vanik512d2d32019-09-20 13:22:34 -070088
Marius Brehlerf5022e82019-12-13 15:20:25 -080089add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
Ben Vanik512d2d32019-09-20 13:22:34 -070090add_subdirectory(third_party/abseil-cpp EXCLUDE_FROM_ALL)
91add_subdirectory(third_party/flatbuffers EXCLUDE_FROM_ALL)
Ben Vanik512d2d32019-09-20 13:22:34 -070092add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL)
Ben Vanik185d30c2019-09-19 14:24:11 -070093
Stella Laurenzo06034152020-01-03 11:26:31 -080094if(${IREE_ENABLE_LLVM})
Ben Vanikcc2aff92019-09-24 10:23:55 -070095 add_subdirectory(third_party/llvm-project/llvm EXCLUDE_FROM_ALL)
Ben Vanik6b112ef2019-10-03 10:45:14 -070096 include(external_tablegen_library)
Stella Laurenzo06034152020-01-03 11:26:31 -080097endif()
98
99if(${IREE_BUILD_COMPILER})
Ben Vanik6b112ef2019-10-03 10:45:14 -0700100 add_subdirectory(build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla EXCLUDE_FROM_ALL)
Ben Vanikcc2aff92019-09-24 10:23:55 -0700101endif()
102
Scott Toddf7003552019-11-11 09:14:19 -0800103if(${IREE_BUILD_DEBUGGER} OR ${IREE_BUILD_SAMPLES})
104 add_subdirectory(third_party/sdl2 EXCLUDE_FROM_ALL)
Scott Todd0d416202019-11-12 16:22:05 -0800105 add_subdirectory(build_tools/third_party/dear_imgui EXCLUDE_FROM_ALL)
Scott Toddf7003552019-11-11 09:14:19 -0800106endif()
107
Marius Brehler29676502019-12-27 17:07:10 -0800108if(${IREE_BUILD_TESTS})
109 add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL)
Marius Brehler575b63a2020-01-07 09:39:24 -0800110 enable_testing(iree)
Marius Brehler29676502019-12-27 17:07:10 -0800111endif()
112
Ben Vanik185d30c2019-09-19 14:24:11 -0700113#-------------------------------------------------------------------------------
114# IREE top-level libraries
115#-------------------------------------------------------------------------------
116
Marius Brehlerf5022e82019-12-13 15:20:25 -0800117add_subdirectory(build_tools/embed_data/)
118
Ben Vanik185d30c2019-09-19 14:24:11 -0700119add_subdirectory(iree/base)
Ben Vanik512d2d32019-09-20 13:22:34 -0700120add_subdirectory(iree/hal)
Marius Brehler9317d1f2020-01-08 10:34:11 -0800121add_subdirectory(iree/modules)
Ben Vanik512d2d32019-09-20 13:22:34 -0700122add_subdirectory(iree/schemas)
Marius Brehler29676502019-12-27 17:07:10 -0800123add_subdirectory(iree/testing)
Stella Laurenzo06034152020-01-03 11:26:31 -0800124
125if(${IREE_ENABLE_LLVM})
126 # The VM requires LLVM to build its op definitions.
127 add_subdirectory(iree/vm)
128endif()
Ben Vanikcc2aff92019-09-24 10:23:55 -0700129
130if(${IREE_BUILD_COMPILER})
Marius Brehlerefd003f2019-12-10 16:33:41 -0800131 add_subdirectory(third_party/glslang EXCLUDE_FROM_ALL)
Ben Vanikcc2aff92019-09-24 10:23:55 -0700132 add_subdirectory(iree/compiler)
Stella Laurenzo06034152020-01-03 11:26:31 -0800133elseif(${IREE_ENABLE_LLVM})
134 # If not building the compiler, tablegen is still needed
135 # to generate vm ops so deep include it only.
136 add_subdirectory(iree/compiler/Dialect/VM/Tools)
Ben Vanikcc2aff92019-09-24 10:23:55 -0700137endif()
Ben Vanik6b112ef2019-10-03 10:45:14 -0700138
139add_subdirectory(iree/tools)
140
141if(${IREE_BUILD_SAMPLES})
142 add_subdirectory(iree/samples)
143endif()