Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 1 | # 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-Noble | 98bbd96 | 2019-11-21 07:27:39 -0800 | [diff] [blame] | 15 | cmake_minimum_required(VERSION 3.12) |
| 16 | if(POLICY CMP0077) |
| 17 | cmake_policy(SET CMP0077 NEW) |
| 18 | endif() |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 19 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 20 | |
| 21 | #------------------------------------------------------------------------------- |
| 22 | # Project configuration |
| 23 | #------------------------------------------------------------------------------- |
| 24 | |
Marius Brehler | 178c82a | 2019-12-27 15:00:04 -0800 | [diff] [blame] | 25 | project(iree CXX C) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 26 | set(IREE_IDE_FOLDER IREE) |
| 27 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 28 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 29 | option(IREE_ENABLE_DEBUG "Enables debugging of the VM." ON) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 30 | option(IREE_ENABLE_LLVM "Enables LLVM dependencies." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 31 | option(IREE_ENABLE_TRACING "Enables WTF tracing." OFF) |
| 32 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 33 | option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 34 | option(IREE_BUILD_TESTS "Builds IREE unit tests." ON) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 35 | option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 36 | option(IREE_BUILD_DEBUGGER "Builds the IREE debugger app." OFF) |
| 37 | |
Marius Brehler | edfc57f | 2019-12-18 11:19:38 -0800 | [diff] [blame] | 38 | if(${IREE_BUILD_SAMPLES}) |
| 39 | set(IREE_BUILD_COMPILER ON CACHE BOOL "Build the IREE compiler for sample projects." FORCE) |
| 40 | endif() |
| 41 | |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 42 | if(${IREE_BUILD_COMPILER}) |
| 43 | set(IREE_ENABLE_LLVM ON CACHE BOOL "Enable LLVM dependencies if the IREE compiler is build." FORCE) |
| 44 | endif() |
| 45 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 46 | #------------------------------------------------------------------------------- |
| 47 | # IREE-specific CMake configuration |
| 48 | #------------------------------------------------------------------------------- |
| 49 | |
| 50 | list(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 Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 54 | |
| 55 | include(iree_macros) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 56 | include(iree_copts) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 57 | include(iree_cc_binary) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 58 | include(iree_cc_library) |
| 59 | include(iree_cc_test) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 60 | include(iree_tablegen_library) |
Scott Todd | 11adcab | 2019-12-18 14:10:44 -0800 | [diff] [blame] | 61 | include(iree_cc_embed_data) |
| 62 | include(iree_bytecode_module) |
Marius Brehler | 9dd6c66 | 2020-01-10 13:20:33 -0800 | [diff] [blame^] | 63 | include(iree_glslang) |
| 64 | include(iree_glsl_vulkan) |
| 65 | include(iree_spirv_kernel_cc_library) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 66 | |
Ben Vanik | b8fe086 | 2019-09-25 09:26:03 -0700 | [diff] [blame] | 67 | string(JOIN " " CMAKE_CXX_FLAGS ${IREE_DEFAULT_COPTS}) |
| 68 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 69 | #------------------------------------------------------------------------------- |
| 70 | # Third-party dependencies |
| 71 | #------------------------------------------------------------------------------- |
| 72 | |
Scott Todd | 4af17b6 | 2019-12-17 16:47:00 -0800 | [diff] [blame] | 73 | if(${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) |
| 78 | endif() |
| 79 | |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 80 | list(APPEND CMAKE_MODULE_PATH |
| 81 | ${CMAKE_CURRENT_LIST_DIR}/third_party/flatbuffers/CMake/ |
| 82 | ) |
| 83 | |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 84 | include(external_cc_library) |
| 85 | include(flatbuffer_cc_library) |
| 86 | |
| 87 | add_subdirectory(build_tools/third_party/ruy EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 88 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 89 | add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 90 | add_subdirectory(third_party/abseil-cpp EXCLUDE_FROM_ALL) |
| 91 | add_subdirectory(third_party/flatbuffers EXCLUDE_FROM_ALL) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 92 | add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL) |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 93 | |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 94 | if(${IREE_ENABLE_LLVM}) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 95 | add_subdirectory(third_party/llvm-project/llvm EXCLUDE_FROM_ALL) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 96 | include(external_tablegen_library) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 97 | endif() |
| 98 | |
| 99 | if(${IREE_BUILD_COMPILER}) |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 100 | add_subdirectory(build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla EXCLUDE_FROM_ALL) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 101 | endif() |
| 102 | |
Scott Todd | f700355 | 2019-11-11 09:14:19 -0800 | [diff] [blame] | 103 | if(${IREE_BUILD_DEBUGGER} OR ${IREE_BUILD_SAMPLES}) |
| 104 | add_subdirectory(third_party/sdl2 EXCLUDE_FROM_ALL) |
Scott Todd | 0d41620 | 2019-11-12 16:22:05 -0800 | [diff] [blame] | 105 | add_subdirectory(build_tools/third_party/dear_imgui EXCLUDE_FROM_ALL) |
Scott Todd | f700355 | 2019-11-11 09:14:19 -0800 | [diff] [blame] | 106 | endif() |
| 107 | |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 108 | if(${IREE_BUILD_TESTS}) |
| 109 | add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL) |
Marius Brehler | 575b63a | 2020-01-07 09:39:24 -0800 | [diff] [blame] | 110 | enable_testing(iree) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 111 | endif() |
| 112 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 113 | #------------------------------------------------------------------------------- |
| 114 | # IREE top-level libraries |
| 115 | #------------------------------------------------------------------------------- |
| 116 | |
Marius Brehler | f5022e8 | 2019-12-13 15:20:25 -0800 | [diff] [blame] | 117 | add_subdirectory(build_tools/embed_data/) |
| 118 | |
Ben Vanik | 185d30c | 2019-09-19 14:24:11 -0700 | [diff] [blame] | 119 | add_subdirectory(iree/base) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 120 | add_subdirectory(iree/hal) |
Marius Brehler | 9317d1f | 2020-01-08 10:34:11 -0800 | [diff] [blame] | 121 | add_subdirectory(iree/modules) |
Ben Vanik | 512d2d3 | 2019-09-20 13:22:34 -0700 | [diff] [blame] | 122 | add_subdirectory(iree/schemas) |
Marius Brehler | 2967650 | 2019-12-27 17:07:10 -0800 | [diff] [blame] | 123 | add_subdirectory(iree/testing) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 124 | |
| 125 | if(${IREE_ENABLE_LLVM}) |
| 126 | # The VM requires LLVM to build its op definitions. |
| 127 | add_subdirectory(iree/vm) |
| 128 | endif() |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 129 | |
| 130 | if(${IREE_BUILD_COMPILER}) |
Marius Brehler | efd003f | 2019-12-10 16:33:41 -0800 | [diff] [blame] | 131 | add_subdirectory(third_party/glslang EXCLUDE_FROM_ALL) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 132 | add_subdirectory(iree/compiler) |
Stella Laurenzo | 0603415 | 2020-01-03 11:26:31 -0800 | [diff] [blame] | 133 | elseif(${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 Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 137 | endif() |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 138 | |
| 139 | add_subdirectory(iree/tools) |
| 140 | |
| 141 | if(${IREE_BUILD_SAMPLES}) |
| 142 | add_subdirectory(iree/samples) |
| 143 | endif() |