8
8
9
9
set (IMEX_EXTERNAL_PROJECT_BUILD OFF )
10
10
11
- if (NOT (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) AND NOT MLIR_BINARY_DIR )
11
+ if (NOT (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) AND NOT DEFINED MLIR_BINARY_DIR )
12
12
# Building as part of LLVM via the external project mechanism.
13
13
set (IMEX_EXTERNAL_PROJECT_BUILD ON )
14
14
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake/modules" )
@@ -39,14 +39,21 @@ if(IMEX_EXTERNAL_PROJECT_BUILD)
39
39
message (FATAL_ERROR "Invalid llvm version" )
40
40
endif ()
41
41
42
+ # Variables needed for mlir_tablegen() to function
42
43
set (MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR} /../mlir )
43
44
set (MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR} /include )
45
+
46
+ set (LLVM_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR} /include )
47
+
48
+ # LLVM headers in source tree are already included
49
+ # as part of LLVM_EXTERNAL_PROJECTS build
50
+
51
+ # MLIR headers in source tree
52
+ include_directories (${MLIR_INCLUDE_DIR} )
53
+ # Generated MLIR headers
44
54
set (MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR} /tools/mlir/include )
45
- include_directories (SYSTEM ${MLIR_INCLUDE_DIR} )
46
- include_directories (SYSTEM ${MLIR_GENERATED_INCLUDE_DIR} )
47
- include_directories (SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR} )
55
+ include_directories (${MLIR_GENERATED_INCLUDE_DIR} )
48
56
49
- set (BACKEND_PACKAGE_STRING "${PACKAGE_STRING} " )
50
57
list (APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR} /cmake/modules" )
51
58
else ()
52
59
message (STATUS "Building IMEX with external MLIR" )
@@ -66,17 +73,82 @@ else()
66
73
message (STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR} " )
67
74
message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR} " )
68
75
76
+ # For redirecting llvm_add_library() to IMEX's bin and lib folders
69
77
set (LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR} /bin )
70
78
set (LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR} /lib )
71
- set (MLIR_BINARY_DIR ${CMAKE_BINARY_DIR} )
79
+
80
+ # LLVM_INCLUDE_DIRS is the same as MLIR_INCLUDE_DIRS in an MLIR install tree
81
+ include_directories (${MLIR_INCLUDE_DIRS} )
72
82
73
83
list (APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR} " )
74
84
list (APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR} " )
75
85
endif ()
76
86
87
+ # For redirecting add_mlir_doc() to IMEX's doc folder
88
+ set (MLIR_BINARY_DIR ${CMAKE_BINARY_DIR} )
89
+
77
90
include (TableGen )
78
91
include (AddLLVM )
79
92
include (AddMLIR )
93
+
94
+ # Instead of creating a separate AddIMEX,
95
+ # redefine some functions included from include(AddMLIR)
96
+ # and change the behavior of add_mlir_* functions to
97
+ # properly generate IMEXConfig.cmake and IMEXTargets.cmake
98
+ function (add_mlir_library_install name )
99
+ get_target_export_arg (${name} IMEX export_to_mlirtargets UMBRELLA imex-libraries )
100
+ install (TARGETS ${name}
101
+ COMPONENT ${name}
102
+ ${export_to_mlirtargets}
103
+ LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
104
+ ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
105
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} "
106
+ # Note that CMake will create a directory like:
107
+ # objects-${CMAKE_BUILD_TYPE}/obj.LibName
108
+ # and put object files there.
109
+ OBJECTS DESTINATION lib${LLVM_LIBDIR_SUFFIX}
110
+ )
111
+
112
+ add_llvm_install_targets (install -${name}
113
+ DEPENDS ${name}
114
+ COMPONENT ${name} )
115
+ set_property (GLOBAL APPEND PROPERTY IMEX_ALL_LIBS ${name} )
116
+ set_property (GLOBAL APPEND PROPERTY IMEX_EXPORTS ${name} )
117
+ endfunction ()
118
+
119
+ # Declare the library associated with a dialect.
120
+ function (add_mlir_dialect_library name )
121
+ set_property (GLOBAL APPEND PROPERTY IMEX_DIALECT_LIBS ${name} )
122
+ add_mlir_library (${ARGV} DEPENDS mlir-headers )
123
+ endfunction (add_mlir_dialect_library )
124
+
125
+ # Declare the library associated with a conversion.
126
+ function (add_mlir_conversion_library name )
127
+ set_property (GLOBAL APPEND PROPERTY IMEX_CONVERSION_LIBS ${name} )
128
+ add_mlir_library (${ARGV} DEPENDS mlir-headers )
129
+ endfunction (add_mlir_conversion_library )
130
+
131
+ # Declare the library associated with a translation.
132
+ function (add_mlir_translation_library name )
133
+ set_property (GLOBAL APPEND PROPERTY IMEX_TRANSLATION_LIBS ${name} )
134
+ add_mlir_library (${ARGV} DEPENDS mlir-headers )
135
+ endfunction (add_mlir_translation_library )
136
+
137
+ macro (add_imex_tool name )
138
+ add_llvm_executable (${name} ${ARGN} )
139
+ get_target_export_arg (${name} IMEX export_to_imexexports )
140
+ install (TARGETS ${name}
141
+ ${export_to_imexexports}
142
+ RUNTIME DESTINATION ${IMEX_TOOLS_INSTALL_DIR}
143
+ COMPONENT ${name} )
144
+
145
+ add_llvm_install_targets (install -${name}
146
+ DEPENDS ${name}
147
+ COMPONENT ${name} )
148
+ set_property (GLOBAL APPEND PROPERTY IMEX_EXPORTS ${name} )
149
+ set_target_properties (${name} PROPERTIES FOLDER "Tools" )
150
+ endmacro ()
151
+
80
152
include (HandleLLVMOptions )
81
153
82
154
set (IMEX_ENABLE_SYCL_RUNTIME 0 CACHE BOOL "Enable the Sycl Runtime" )
@@ -110,11 +182,11 @@ if(NOT IMEX_EXTERNAL_PROJECT_BUILD)
110
182
COMPONENTS Interpreter )
111
183
endif ()
112
184
113
- include_directories (${LLVM_INCLUDE_DIRS} )
114
- include_directories (${MLIR_INCLUDE_DIRS} )
185
+ # IMEX headers in source tree
115
186
include_directories (${CMAKE_CURRENT_SOURCE_DIR} /include )
187
+ # Generated IMEX headers
116
188
include_directories (${CMAKE_CURRENT_BINARY_DIR} /include )
117
- link_directories ( ${LLVM_BUILD_LIBRARY_DIR} )
189
+ message ( STATUS "LLVM_DEFINITIONS: ${LLVM_DEFINITIONS} " )
118
190
add_definitions (${LLVM_DEFINITIONS} )
119
191
120
192
set (LLVM_LIT_ARGS "-sv" CACHE STRING "lit default options" )
@@ -128,6 +200,9 @@ else()
128
200
set (IMEX_LIB_DIR ${IMEX_BINARY_DIR} /lib )
129
201
endif ()
130
202
203
+ set (IMEX_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR} " CACHE STRING
204
+ "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR} ')" )
205
+
131
206
include (sanitizers )
132
207
133
208
add_subdirectory (include )
@@ -140,9 +215,14 @@ if (IMEX_INCLUDE_DOCS)
140
215
add_subdirectory (docs )
141
216
endif ()
142
217
143
- install (DIRECTORY ${PROJECT_SOURCE_DIR} /include/mlir
218
+ # Custom target to install all imex headers
219
+ add_custom_target (imex-headers )
220
+ set_target_properties (imex-headers PROPERTIES FOLDER "Misc" )
221
+
222
+ # Headers in source tree
223
+ install (DIRECTORY include /imex
144
224
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
145
- COMPONENT mlir -headers
225
+ COMPONENT imex -headers
146
226
FILES_MATCHING
147
227
PATTERN "*.def"
148
228
PATTERN "*.h"
@@ -151,9 +231,10 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/mlir
151
231
PATTERN "LICENSE.TXT"
152
232
)
153
233
154
- install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /include
234
+ # Generated headers
235
+ install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /include/imex
155
236
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
156
- COMPONENT mlir -headers
237
+ COMPONENT imex -headers
157
238
FILES_MATCHING
158
239
PATTERN "*.def"
159
240
PATTERN "*.h"
@@ -164,4 +245,26 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
164
245
PATTERN "config.h" EXCLUDE
165
246
)
166
247
248
+ add_llvm_install_targets (install -imex-headers
249
+ DEPENDS imex-headers
250
+ COMPONENT imex-headers )
251
+
252
+
253
+ # Custom target to install all imex libraries
254
+ add_custom_target (imex-libraries )
255
+ set_target_properties (imex-libraries PROPERTIES FOLDER "Misc" )
256
+
257
+ add_llvm_install_targets (install -imex-libraries
258
+ DEPENDS imex-libraries
259
+ COMPONENT imex-libraries )
260
+
261
+ get_property (IMEX_LIBS GLOBAL PROPERTY IMEX_ALL_LIBS )
262
+ if (IMEX_LIBS )
263
+ list (REMOVE_DUPLICATES IMEX_LIBS )
264
+ foreach (lib ${IMEX_LIBS} )
265
+ add_dependencies (imex-libraries ${lib} )
266
+ add_dependencies (install -imex-libraries install -${lib} )
267
+ endforeach ()
268
+ endif ()
269
+
167
270
add_subdirectory (cmake/modules )
0 commit comments