[Hexagon] Better detection of impossible completions to perfect shuffles
[llvm-project.git] / mlir / CMakeLists.txt
blob651ec1a8c979e53781128263d2bf4d74106ea9bb
1 # MLIR project.
2 cmake_minimum_required(VERSION 3.13.4)
4 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
5   set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
6 endif()
7 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
8   NO_POLICY_SCOPE)
10 # Check if MLIR is built as a standalone project.
11 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
12   project(mlir)
13   set(MLIR_STANDALONE_BUILD TRUE)
14 endif()
16 # Must go below project(..)
17 include(GNUInstallDirs)
19 if(MLIR_STANDALONE_BUILD)
20   find_package(LLVM CONFIG REQUIRED)
21   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
22   include(HandleLLVMOptions)
23   include(AddLLVM)
24   include(TableGen)
26   include_directories(${LLVM_INCLUDE_DIRS})
28   set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
29   if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
30     add_subdirectory(${UNITTEST_DIR} third-party/unittest)
31   endif()
33   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
34     "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
35   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
37   set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit")
38 endif()
40 set(MLIR_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
41     "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
42 mark_as_advanced(MLIR_TOOLS_INSTALL_DIR)
44 set(MLIR_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  )
45 set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include )
47 set(MLIR_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
48 set(MLIR_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
49 set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
50 set(MLIR_TOOLS_DIR   ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
52 # Make sure that our source directory is on the current cmake module path so
53 # that we can include cmake files from this directory.
54 list(INSERT CMAKE_MODULE_PATH 0
55   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
56   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
57   )
59 include(AddMLIR)
61 # -BSymbolic is incompatible with TypeID
62 if("${CMAKE_SHARED_LINKER_FLAGS}" MATCHES "-Bsymbolic[^-]")
63   message(FATAL_ERROR " MLIR does not support `-Bsymbolic` (see http://llvm.org/pr51420 ),"
64           " try `-Bsymbolic-functions` instead.")
65 endif()
67 # Forbid implicit function declaration: this may lead to subtle bugs and we
68 # don't have a reason to support this.
69 check_c_compiler_flag("-Werror=implicit-function-declaration" C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION)
70 append_if(C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION "-Werror=implicit-function-declaration" CMAKE_C_FLAGS)
72 # Forbid mismatch between declaration and definition for class vs struct. This is
73 # harmless on Unix systems, but it'll be a ticking bomb for MSVC/Windows systems
74 # where it creeps into the ABI.
75 check_c_compiler_flag("-Werror=mismatched-tags" C_SUPPORTS_WERROR_MISMATCHED_TAGS)
76 append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_C_FLAGS)
77 append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_CXX_FLAGS)
79 # Installing the headers and docs needs to depend on generating any public
80 # tablegen'd targets.
81 # mlir-generic-headers are dialect-independent.
82 add_custom_target(mlir-generic-headers)
83 set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc")
84 # mlir-headers may be dialect-dependent.
85 add_custom_target(mlir-headers)
86 set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
87 add_dependencies(mlir-headers mlir-generic-headers)
88 add_custom_target(mlir-doc)
90 # Only enable execution engine if the native target is available.
91 if(${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD)
92   set(MLIR_ENABLE_EXECUTION_ENGINE 1)
93 else()
94   set(MLIR_ENABLE_EXECUTION_ENGINE 0)
95 endif()
97 # Build the CUDA conversions and run according tests if the NVPTX backend
98 # is available
99 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD AND MLIR_ENABLE_EXECUTION_ENGINE)
100   set(MLIR_ENABLE_CUDA_CONVERSIONS 1)
101 else()
102   set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
103 endif()
104 # TODO: we should use a config.h file like LLVM does
105 add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})
107 # Build the ROCm conversions and run according tests if the AMDGPU backend
108 # is available.
109 if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD AND MLIR_ENABLE_EXECUTION_ENGINE)
110   set(MLIR_ENABLE_ROCM_CONVERSIONS 1)
111 else()
112   set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
113 endif()
114 add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS})
116 set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA runner")
117 set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner")
118 set(MLIR_ENABLE_SPIRV_CPU_RUNNER 0 CACHE BOOL "Enable building the mlir SPIR-V cpu runner")
119 set(MLIR_ENABLE_VULKAN_RUNNER 0 CACHE BOOL "Enable building the mlir Vulkan runner")
121 option(MLIR_INCLUDE_TESTS
122        "Generate build targets for the MLIR unit tests."
123        ${LLVM_INCLUDE_TESTS})
125 option(MLIR_INCLUDE_INTEGRATION_TESTS
126        "Generate build targets for the MLIR integration tests.")
128 set(MLIR_INSTALL_AGGREGATE_OBJECTS 1 CACHE BOOL
129     "Installs object files needed for add_mlir_aggregate to work out of \
130     tree. Package maintainers can disable this to exclude these assets if \
131     not desired. Enabling this will result in object files being written \
132     under lib/objects-{CMAKE_BUILD_TYPE}.")
134 set(MLIR_BUILD_MLIR_C_DYLIB 0 CACHE BOOL "Builds libMLIR-C shared library.")
136 #-------------------------------------------------------------------------------
137 # Python Bindings Configuration
138 # Requires:
139 #   The pybind11 library can be found (set with -DPYBIND_DIR=...)
140 #   The python executable is correct (set with -DPython3_EXECUTABLE=...)
141 #-------------------------------------------------------------------------------
143 set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
144        "Enables building of Python bindings.")
145 set(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH 1 CACHE BOOL
146        "Prime the python detection by searching for a full 'Development' \
147        component first (temporary while diagnosing environment specific Python \
148        detection issues)")
149 if(MLIR_ENABLE_BINDINGS_PYTHON)
150   include(MLIRDetectPythonEnv)
151   mlir_configure_python_dev_packages()
152 endif()
154 set(CMAKE_INCLUDE_CURRENT_DIR ON)
156 include_directories( "include")
157 include_directories( ${MLIR_INCLUDE_DIR})
159 # Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
160 # MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
161 # from another directory like tools
162 add_subdirectory(tools/mlir-tblgen)
163 add_subdirectory(tools/mlir-linalg-ods-gen)
164 add_subdirectory(tools/mlir-pdll)
166 set(MLIR_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}" CACHE INTERNAL "")
167 set(MLIR_TABLEGEN_TARGET "${MLIR_TABLEGEN_TARGET}" CACHE INTERNAL "")
168 set(MLIR_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}" CACHE INTERNAL "")
169 set(MLIR_PDLL_TABLEGEN_TARGET "${MLIR_PDLL_TABLEGEN_TARGET}" CACHE INTERNAL "")
171 add_subdirectory(include/mlir)
172 add_subdirectory(lib)
173 # C API needs all dialects for registration, but should be built before tests.
174 add_subdirectory(lib/CAPI)
176 if (MLIR_INCLUDE_TESTS)
177   add_definitions(-DMLIR_INCLUDE_TESTS)
178   add_custom_target(MLIRUnitTests)
179   if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h)
180     add_subdirectory(unittests)
181   else()
182     message(WARNING "gtest not found, unittests will not be available")
183   endif()
184   add_subdirectory(test)
185 endif()
186 # Tools needs to come late to ensure that MLIR_ALL_LIBS is populated.
187 # Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
188 add_subdirectory(tools)
190 if(MLIR_ENABLE_BINDINGS_PYTHON)
191   # Python sources: built extensions come in via lib/Bindings/Python
192   add_subdirectory(python)
193 endif()
195 if( LLVM_INCLUDE_EXAMPLES )
196   add_subdirectory(examples)
197 endif()
199 option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs."
200   ${LLVM_INCLUDE_DOCS})
201 if (MLIR_INCLUDE_DOCS)
202   add_subdirectory(docs)
203 endif()
205 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
206   install(DIRECTORY include/mlir include/mlir-c
207     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
208     COMPONENT mlir-headers
209     FILES_MATCHING
210     PATTERN "*.def"
211     PATTERN "*.h"
212     PATTERN "*.inc"
213     PATTERN "*.td"
214     PATTERN "LICENSE.TXT"
215     )
217   install(DIRECTORY ${MLIR_INCLUDE_DIR}/mlir ${MLIR_INCLUDE_DIR}/mlir-c
218     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
219     COMPONENT mlir-headers
220     FILES_MATCHING
221     PATTERN "*.def"
222     PATTERN "*.h"
223     PATTERN "*.gen"
224     PATTERN "*.inc"
225     PATTERN "*.td"
226     PATTERN "CMakeFiles" EXCLUDE
227     PATTERN "config.h" EXCLUDE
228     )
230   if (NOT LLVM_ENABLE_IDE)
231     add_llvm_install_targets(install-mlir-headers
232                              DEPENDS mlir-headers
233                              COMPONENT mlir-headers)
234   endif()
235 endif()
237 # Custom target to install all mlir libraries
238 add_custom_target(mlir-libraries)
239 set_target_properties(mlir-libraries PROPERTIES FOLDER "Misc")
241 if (NOT LLVM_ENABLE_IDE)
242   add_llvm_install_targets(install-mlir-libraries
243                            DEPENDS mlir-libraries
244                            COMPONENT mlir-libraries)
245 endif()
247 get_property(MLIR_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS)
248 if(MLIR_LIBS)
249   list(REMOVE_DUPLICATES MLIR_LIBS)
250   foreach(lib ${MLIR_LIBS})
251     add_dependencies(mlir-libraries ${lib})
252     if(NOT LLVM_ENABLE_IDE)
253       add_dependencies(install-mlir-libraries install-${lib})
254       add_dependencies(install-mlir-libraries-stripped install-${lib}-stripped)
255     endif()
256   endforeach()
257 endif()
259 add_subdirectory(cmake/modules)
261 if (MLIR_ENABLE_PYTHON_BENCHMARKS)
262   add_subdirectory(utils/mbr)
263 endif()
265 if(MLIR_STANDALONE_BUILD)
266   llvm_distribution_add_targets()
267 endif()