2 set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
3 set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include )
5 set(MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
6 set(MLIR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
7 set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
9 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
13 # Installing the headers and docs needs to depend on generating any public
15 # mlir-generic-headers are dialect-independent.
16 add_custom_target(mlir-generic-headers)
17 set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc")
18 # mlir-headers may be dialect-dependent.
19 add_custom_target(mlir-headers)
20 set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
21 add_dependencies(mlir-headers mlir-generic-headers)
22 add_custom_target(mlir-doc)
24 # Build the CUDA conversions and run according tests if the NVPTX backend
26 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
27 set(MLIR_CUDA_CONVERSIONS_ENABLED 1)
29 set(MLIR_CUDA_CONVERSIONS_ENABLED 0)
31 # TODO: we should use a config.h file like LLVM does
32 add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_CUDA_CONVERSIONS_ENABLED})
34 # Build the ROCm conversions and run according tests if the AMDGPU backend
36 if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
37 set(MLIR_ROCM_CONVERSIONS_ENABLED 1)
39 set(MLIR_ROCM_CONVERSIONS_ENABLED 0)
41 add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ROCM_CONVERSIONS_ENABLED})
43 set(MLIR_CUDA_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir CUDA runner")
44 set(MLIR_VULKAN_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir Vulkan runner")
46 option(MLIR_INCLUDE_TESTS
47 "Generate build targets for the MLIR unit tests."
48 ${LLVM_INCLUDE_TESTS})
50 include_directories( "include")
51 include_directories( ${MLIR_INCLUDE_DIR})
53 # Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
54 # MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
55 # from another directory like tools
56 add_subdirectory(tools/mlir-tblgen)
58 add_subdirectory(include/mlir)
60 if (MLIR_INCLUDE_TESTS)
61 add_definitions(-DMLIR_INCLUDE_TESTS)
62 add_subdirectory(unittests)
63 add_subdirectory(test)
65 # Tools needs to come late to ensure that MLIR_ALL_LIBS is populated.
66 # Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
67 add_subdirectory(tools)
69 if( LLVM_INCLUDE_EXAMPLES )
70 add_subdirectory(examples)
73 option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs."
75 if (MLIR_INCLUDE_DOCS)
76 add_subdirectory(docs)
79 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
80 install(DIRECTORY include/mlir include/mlir-c
82 COMPONENT mlir-headers
91 install(DIRECTORY ${MLIR_INCLUDE_DIR}/mlir ${MLIR_INCLUDE_DIR}/mlir-c
93 COMPONENT mlir-headers
100 PATTERN "CMakeFiles" EXCLUDE
101 PATTERN "config.h" EXCLUDE
104 if (NOT LLVM_ENABLE_IDE)
105 add_llvm_install_targets(install-mlir-headers
107 COMPONENT mlir-headers)
111 add_subdirectory(cmake/modules)