1# MLIR project. 2set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) 3set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include ) 4 5set(MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 6set(MLIR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 7set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) 8 9list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") 10 11include(AddMLIR) 12 13# Forbid implicit function declaration: this may lead to subtle bugs and we 14# don't have a reason to support this. 15check_c_compiler_flag("-Werror=implicit-function-declaration" C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION) 16append_if(C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION "-Werror=implicit-function-declaration" CMAKE_C_FLAGS) 17 18# Installing the headers and docs needs to depend on generating any public 19# tablegen'd targets. 20# mlir-generic-headers are dialect-independent. 21add_custom_target(mlir-generic-headers) 22set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc") 23# mlir-headers may be dialect-dependent. 24add_custom_target(mlir-headers) 25set_target_properties(mlir-headers PROPERTIES FOLDER "Misc") 26add_dependencies(mlir-headers mlir-generic-headers) 27add_custom_target(mlir-doc) 28 29# Build the CUDA conversions and run according tests if the NVPTX backend 30# is available 31if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD) 32 set(MLIR_CUDA_CONVERSIONS_ENABLED 1) 33else() 34 set(MLIR_CUDA_CONVERSIONS_ENABLED 0) 35endif() 36# TODO: we should use a config.h file like LLVM does 37add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_CUDA_CONVERSIONS_ENABLED}) 38 39# Build the ROCm conversions and run according tests if the AMDGPU backend 40# is available 41if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD) 42 set(MLIR_ROCM_CONVERSIONS_ENABLED 1) 43else() 44 set(MLIR_ROCM_CONVERSIONS_ENABLED 0) 45endif() 46add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ROCM_CONVERSIONS_ENABLED}) 47 48set(MLIR_CUDA_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir CUDA runner") 49set(MLIR_ROCM_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir ROCm runner") 50set(MLIR_SPIRV_CPU_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir SPIR-V cpu runner") 51set(MLIR_VULKAN_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir Vulkan runner") 52 53option(MLIR_INCLUDE_TESTS 54 "Generate build targets for the MLIR unit tests." 55 ${LLVM_INCLUDE_TESTS}) 56 57option(MLIR_INCLUDE_INTEGRATION_TESTS 58 "Generate build targets for the MLIR integration tests.") 59 60#------------------------------------------------------------------------------- 61# Python Bindings Configuration 62# Requires: 63# The pybind11 library can be found (set with -DPYBIND_DIR=...) 64# The python executable is correct (set with -DPython3_EXECUTABLE=...) 65# 66# Version locking 67# --------------- 68# By default, python extensions are version locked to specific Python libraries. 69# This linking mode is somewhat more consistent across platforms and surfaces 70# undefined symbols at link time (vs runtime). It is suitable for development 71# workflows but can be disabled for more flexible deployment by 72# setting -DMLIR_PYTHON_BINDINGS_VERSION_LOCKED=OFF 73#------------------------------------------------------------------------------- 74 75set(MLIR_BINDINGS_PYTHON_ENABLED 0 CACHE BOOL 76 "Enables building of Python bindings.") 77set(MLIR_PYTHON_BINDINGS_VERSION_LOCKED 1 CACHE BOOL 78 "Links to specific python libraries, resolving all symbols.") 79 80if(MLIR_BINDINGS_PYTHON_ENABLED) 81 include(MLIRDetectPythonEnv) 82 find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED) 83 message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}") 84 message(STATUS "Found python libraries: ${Python3_LIBRARIES}") 85 message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}") 86 mlir_detect_pybind11_install() 87 find_package(pybind11 2.6 CONFIG REQUIRED) 88 message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}") 89 message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', " 90 "suffix = '${PYTHON_MODULE_SUFFIX}', " 91 "extension = '${PYTHON_MODULE_EXTENSION}") 92endif() 93 94include_directories( "include") 95include_directories( ${MLIR_INCLUDE_DIR}) 96 97# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like 98# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included 99# from another directory like tools 100add_subdirectory(tools/mlir-tblgen) 101 102add_subdirectory(include/mlir) 103add_subdirectory(lib) 104# C API needs all dialects for registration, but should be built before tests. 105add_subdirectory(lib/CAPI) 106if (MLIR_INCLUDE_TESTS) 107 add_definitions(-DMLIR_INCLUDE_TESTS) 108 add_subdirectory(unittests) 109 add_subdirectory(test) 110endif() 111if (MLIR_INCLUDE_INTEGRATION_TESTS) 112 add_definitions(-DMLIR_INCLUDE_INTEGRATION_TESTS) 113 add_subdirectory(integration_test) 114endif() 115# Tools needs to come late to ensure that MLIR_ALL_LIBS is populated. 116# Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so. 117add_subdirectory(tools) 118 119if( LLVM_INCLUDE_EXAMPLES ) 120 add_subdirectory(examples) 121endif() 122 123option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs." 124 ${LLVM_INCLUDE_DOCS}) 125if (MLIR_INCLUDE_DOCS) 126 add_subdirectory(docs) 127endif() 128 129if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 130 install(DIRECTORY include/mlir include/mlir-c 131 DESTINATION include 132 COMPONENT mlir-headers 133 FILES_MATCHING 134 PATTERN "*.def" 135 PATTERN "*.h" 136 PATTERN "*.inc" 137 PATTERN "*.td" 138 PATTERN "LICENSE.TXT" 139 ) 140 141 install(DIRECTORY ${MLIR_INCLUDE_DIR}/mlir ${MLIR_INCLUDE_DIR}/mlir-c 142 DESTINATION include 143 COMPONENT mlir-headers 144 FILES_MATCHING 145 PATTERN "*.def" 146 PATTERN "*.h" 147 PATTERN "*.gen" 148 PATTERN "*.inc" 149 PATTERN "*.td" 150 PATTERN "CMakeFiles" EXCLUDE 151 PATTERN "config.h" EXCLUDE 152 ) 153 154 if (NOT LLVM_ENABLE_IDE) 155 add_llvm_install_targets(install-mlir-headers 156 DEPENDS mlir-headers 157 COMPONENT mlir-headers) 158 endif() 159endif() 160 161add_subdirectory(cmake/modules) 162