[clang] Avoid linking libdl unless needed
[llvm-project.git] / mlir / CMakeLists.txt
blob0cf1e8d445168c3ecde3817a58361c546aa17e8b
1 # MLIR project.
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")
11 include(AddMLIR)
13 # Installing the headers and docs needs to depend on generating any public
14 # tablegen'd targets.
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
25 # is available
26 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
27   set(MLIR_CUDA_CONVERSIONS_ENABLED 1)
28 else()
29   set(MLIR_CUDA_CONVERSIONS_ENABLED 0)
30 endif()
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
35 # is available
36 if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
37   set(MLIR_ROCM_CONVERSIONS_ENABLED 1)
38 else()
39   set(MLIR_ROCM_CONVERSIONS_ENABLED 0)
40 endif()
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)
59 add_subdirectory(lib)
60 if (MLIR_INCLUDE_TESTS)
61   add_definitions(-DMLIR_INCLUDE_TESTS)
62   add_subdirectory(unittests)
63   add_subdirectory(test)
64 endif()
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)
71 endif()
73 option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs."
74   ${LLVM_INCLUDE_DOCS})
75 if (MLIR_INCLUDE_DOCS)
76   add_subdirectory(docs)
77 endif()
79 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
80   install(DIRECTORY include/mlir include/mlir-c
81     DESTINATION include
82     COMPONENT mlir-headers
83     FILES_MATCHING
84     PATTERN "*.def"
85     PATTERN "*.h"
86     PATTERN "*.inc"
87     PATTERN "*.td"
88     PATTERN "LICENSE.TXT"
89     )
91   install(DIRECTORY ${MLIR_INCLUDE_DIR}/mlir ${MLIR_INCLUDE_DIR}/mlir-c
92     DESTINATION include
93     COMPONENT mlir-headers
94     FILES_MATCHING
95     PATTERN "*.def"
96     PATTERN "*.h"
97     PATTERN "*.gen"
98     PATTERN "*.inc"
99     PATTERN "*.td"
100     PATTERN "CMakeFiles" EXCLUDE
101     PATTERN "config.h" EXCLUDE
102     )
104   if (NOT LLVM_ENABLE_IDE)
105     add_llvm_install_targets(install-mlir-headers
106                              DEPENDS mlir-headers
107                              COMPONENT mlir-headers)
108   endif()
109 endif()
111 add_subdirectory(cmake/modules)