[RISCV] Fix the code alignment for GroupFloatVectors. NFC
[llvm-project.git] / mlir / CMakeLists.txt
blob28018350cb43da8a1fcee217baf37f7e96a9bd6b
1 # MLIR project.
3 # Check if MLIR is built as a standalone project.
4 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
5   project(mlir)
6   cmake_minimum_required(VERSION 3.13.4)
8   find_package(LLVM CONFIG REQUIRED)
9   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
10   include(HandleLLVMOptions)
11   include(AddLLVM)
12   include(TableGen)
14   include_directories(${LLVM_INCLUDE_DIRS})
16   set(LLVM_MAIN_SRC_DIR ${CMAKE_SOURCE_DIR}/../llvm CACHE PATH
17       "Path to LLVM source tree")
18   set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
19   if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
20     add_subdirectory(${UNITTEST_DIR} utils/unittest)
21   endif()
23   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
24     "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
25   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
26 endif()
28 set(MLIR_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  )
29 set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include )
31 set(MLIR_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
32 set(MLIR_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
33 set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
34 set(MLIR_TOOLS_DIR   ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
36 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
38 include(AddMLIR)
40 # -BSymbolic is incompatible with TypeID
41 if("${CMAKE_SHARED_LINKER_FLAGS}" MATCHES "-Bsymbolic[^-]")
42   message(FATAL_ERROR " MLIR does not support `-Bsymbolic` (see http://llvm.org/pr51420 ),"
43           " try `-Bsymbolic-functions` instead.")
44 endif()
46 # Forbid implicit function declaration: this may lead to subtle bugs and we
47 # don't have a reason to support this.
48 check_c_compiler_flag("-Werror=implicit-function-declaration" C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION)
49 append_if(C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION "-Werror=implicit-function-declaration" CMAKE_C_FLAGS)
51 # Forbid mismatch between declaration and definition for class vs struct. This is
52 # harmless on Unix systems, but it'll be a ticking bomb for MSVC/Windows systems
53 # where it creeps into the ABI.
54 check_c_compiler_flag("-Werror=mismatched-tags" C_SUPPORTS_WERROR_MISMATCHED_TAGS)
55 append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_C_FLAGS)
56 append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_CXX_FLAGS)
58 # Installing the headers and docs needs to depend on generating any public
59 # tablegen'd targets.
60 # mlir-generic-headers are dialect-independent.
61 add_custom_target(mlir-generic-headers)
62 set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc")
63 # mlir-headers may be dialect-dependent.
64 add_custom_target(mlir-headers)
65 set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
66 add_dependencies(mlir-headers mlir-generic-headers)
67 add_custom_target(mlir-doc)
69 # Build the CUDA conversions and run according tests if the NVPTX backend
70 # is available
71 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
72   set(MLIR_ENABLE_CUDA_CONVERSIONS 1)
73 else()
74   set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
75 endif()
76 # TODO: we should use a config.h file like LLVM does
77 add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})
79 # Build the ROCm conversions and run according tests if the AMDGPU backend
80 # is available
81 if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
82   set(MLIR_ENABLE_ROCM_CONVERSIONS 1)
83 else()
84   set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
85 endif()
86 add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS})
88 set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA runner")
89 set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner")
90 set(MLIR_ENABLE_SPIRV_CPU_RUNNER 0 CACHE BOOL "Enable building the mlir SPIR-V cpu runner")
91 set(MLIR_ENABLE_VULKAN_RUNNER 0 CACHE BOOL "Enable building the mlir Vulkan runner")
93 option(MLIR_INCLUDE_TESTS
94        "Generate build targets for the MLIR unit tests."
95        ${LLVM_INCLUDE_TESTS})
97 option(MLIR_INCLUDE_INTEGRATION_TESTS
98        "Generate build targets for the MLIR integration tests.")
100 set(MLIR_INSTALL_AGGREGATE_OBJECTS 1 CACHE BOOL
101     "Installs object files needed for add_mlir_aggregate to work out of \
102     tree. Package maintainers can disable this to exclude these assets if \
103     not desired. Enabling this will result in object files being written \
104     under lib/objects-{CMAKE_BUILD_TYPE}.")
106 set(MLIR_BUILD_MLIR_C_DYLIB 0 CACHE BOOL "Builds libMLIR-C shared library.")
108 #-------------------------------------------------------------------------------
109 # Python Bindings Configuration
110 # Requires:
111 #   The pybind11 library can be found (set with -DPYBIND_DIR=...)
112 #   The python executable is correct (set with -DPython3_EXECUTABLE=...)
113 #-------------------------------------------------------------------------------
115 set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
116        "Enables building of Python bindings.")
117 if(MLIR_ENABLE_BINDINGS_PYTHON)
118   include(MLIRDetectPythonEnv)
119   mlir_configure_python_dev_packages()
120 endif()
122 include_directories( "include")
123 include_directories( ${MLIR_INCLUDE_DIR})
125 # Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
126 # MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
127 # from another directory like tools
128 add_subdirectory(tools/mlir-tblgen)
129 add_subdirectory(tools/mlir-linalg-ods-gen)
131 add_subdirectory(include/mlir)
132 add_subdirectory(lib)
133 # C API needs all dialects for registration, but should be built before tests.
134 add_subdirectory(lib/CAPI)
136 if (MLIR_INCLUDE_TESTS)
137   add_definitions(-DMLIR_INCLUDE_TESTS)
138   add_custom_target(MLIRUnitTests)
139   if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
140     add_subdirectory(unittests)
141   else()
142     message(WARNING "gtest not found, unittests will not be available")
143   endif()
144   add_subdirectory(test)
145 endif()
146 # Tools needs to come late to ensure that MLIR_ALL_LIBS is populated.
147 # Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
148 add_subdirectory(tools)
150 if(MLIR_ENABLE_BINDINGS_PYTHON)
151   # Python sources: built extensions come in via lib/Bindings/Python
152   add_subdirectory(python)
153 endif()
155 if( LLVM_INCLUDE_EXAMPLES )
156   add_subdirectory(examples)
157 endif()
159 option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs."
160   ${LLVM_INCLUDE_DOCS})
161 if (MLIR_INCLUDE_DOCS)
162   add_subdirectory(docs)
163 endif()
165 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
166   install(DIRECTORY include/mlir include/mlir-c
167     DESTINATION include
168     COMPONENT mlir-headers
169     FILES_MATCHING
170     PATTERN "*.def"
171     PATTERN "*.h"
172     PATTERN "*.inc"
173     PATTERN "*.td"
174     PATTERN "LICENSE.TXT"
175     )
177   install(DIRECTORY ${MLIR_INCLUDE_DIR}/mlir ${MLIR_INCLUDE_DIR}/mlir-c
178     DESTINATION include
179     COMPONENT mlir-headers
180     FILES_MATCHING
181     PATTERN "*.def"
182     PATTERN "*.h"
183     PATTERN "*.gen"
184     PATTERN "*.inc"
185     PATTERN "*.td"
186     PATTERN "CMakeFiles" EXCLUDE
187     PATTERN "config.h" EXCLUDE
188     )
190   if (NOT LLVM_ENABLE_IDE)
191     add_llvm_install_targets(install-mlir-headers
192                              DEPENDS mlir-headers
193                              COMPONENT mlir-headers)
194   endif()
195 endif()
197 add_subdirectory(cmake/modules)