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