@@ -201,25 +201,9 @@ function(add_mlir_doc doc_filename output_file output_directory command)
201
201
add_dependencies (mlir-doc ${output_file} DocGen )
202
202
endfunction ()
203
203
204
- # Declare an mlir library which can be compiled in libMLIR.so
205
- # In addition to everything that llvm_add_library accepts, this
206
- # also has the following option:
207
- # EXCLUDE_FROM_LIBMLIR
208
- # Don't include this library in libMLIR.so. This option should be used
209
- # for test libraries, executable-specific libraries, or rarely used libraries
210
- # with large dependencies.
211
- # ENABLE_AGGREGATION
212
- # Forces generation of an OBJECT library, exports additional metadata,
213
- # and installs additional object files needed to include this as part of an
214
- # aggregate shared library.
215
- # TODO: Make this the default for all MLIR libraries once all libraries
216
- # are compatible with building an object library.
217
- function (add_mlir_library name )
218
- cmake_parse_arguments (ARG
219
- "SHARED;INSTALL_WITH_TOOLCHAIN;EXCLUDE_FROM_LIBMLIR;DISABLE_INSTALL;ENABLE_AGGREGATION"
220
- ""
221
- "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
222
- ${ARGN} )
204
+ # Sets ${srcs} to contain the list of additional headers for the target. Extra
205
+ # arguments are included into the list of additional headers.
206
+ function (_set_mlir_additional_headers_as_srcs )
223
207
set (srcs )
224
208
if (MSVC_IDE OR XCODE )
225
209
# Add public headers
@@ -245,13 +229,83 @@ function(add_mlir_library name)
245
229
endif ()
246
230
endif ()
247
231
endif (MSVC_IDE OR XCODE )
248
- if (srcs OR ARG_ADDITIONAL_HEADERS )
232
+ if (srcs OR ARGN )
249
233
set (srcs
250
234
ADDITIONAL_HEADERS
251
235
${srcs}
252
- ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
236
+ ${ARGN} # It may contain unparsed unknown args.
237
+ PARENT_SCOPE
253
238
)
254
239
endif ()
240
+ endfunction ()
241
+
242
+ # Checks that the LLVM components are not listed in the extra arguments,
243
+ # assumed to be coming from the LINK_LIBS variable.
244
+ function (_check_llvm_components_usage name )
245
+ # LINK_COMPONENTS is necessary to allow libLLVM.so to be properly
246
+ # substituted for individual library dependencies if LLVM_LINK_LLVM_DYLIB
247
+ # Perhaps this should be in llvm_add_library instead? However, it fails
248
+ # on libclang-cpp.so
249
+ get_property (llvm_component_libs GLOBAL PROPERTY LLVM_COMPONENT_LIBS )
250
+ foreach (lib ${ARGN} )
251
+ if (${lib} IN_LIST llvm_component_libs )
252
+ message (SEND_ERROR "${name} specifies LINK_LIBS ${lib} , but LINK_LIBS cannot be used for LLVM libraries. Please use LINK_COMPONENTS instead." )
253
+ endif ()
254
+ endforeach ()
255
+ endfunction ()
256
+
257
+ function (add_mlir_example_library name )
258
+ cmake_parse_arguments (ARG
259
+ "SHARED;DISABLE_INSTALL"
260
+ ""
261
+ "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
262
+ ${ARGN} )
263
+ _set_mlir_additional_headers_as_srcs (${ARG_ADDITIONAL_HEADERS} )
264
+ if (ARG_SHARED )
265
+ set (LIBTYPE SHARED )
266
+ else ()
267
+ if (BUILD_SHARED_LIBS )
268
+ set (LIBTYPE SHARED )
269
+ else ()
270
+ set (LIBTYPE STATIC )
271
+ endif ()
272
+ endif ()
273
+
274
+ # MLIR libraries uniformly depend on LLVMSupport. Just specify it once here.
275
+ list (APPEND ARG_LINK_COMPONENTS Support )
276
+ _check_llvm_components_usage (${name} ${ARG_LINK_LIBS} )
277
+
278
+ list (APPEND ARG_DEPENDS mlir-generic-headers )
279
+
280
+ llvm_add_library (${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs} DEPENDS ${ARG_DEPENDS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} LINK_LIBS ${ARG_LINK_LIBS} )
281
+ set_target_properties (${name} PROPERTIES FOLDER "Examples" )
282
+ if (LLVM_BUILD_EXAMPLES AND NOT ${ARG_DISABLE_INSTALL} )
283
+ add_mlir_library_install (${name} )
284
+ else ()
285
+ set_target_properties (${name} PROPERTIES EXCLUDE_FROM_ALL ON )
286
+ endif ()
287
+ endfunction ()
288
+
289
+ # Declare an mlir library which can be compiled in libMLIR.so
290
+ # In addition to everything that llvm_add_library accepts, this
291
+ # also has the following option:
292
+ # EXCLUDE_FROM_LIBMLIR
293
+ # Don't include this library in libMLIR.so. This option should be used
294
+ # for test libraries, executable-specific libraries, or rarely used libraries
295
+ # with large dependencies.
296
+ # ENABLE_AGGREGATION
297
+ # Forces generation of an OBJECT library, exports additional metadata,
298
+ # and installs additional object files needed to include this as part of an
299
+ # aggregate shared library.
300
+ # TODO: Make this the default for all MLIR libraries once all libraries
301
+ # are compatible with building an object library.
302
+ function (add_mlir_library name )
303
+ cmake_parse_arguments (ARG
304
+ "SHARED;INSTALL_WITH_TOOLCHAIN;EXCLUDE_FROM_LIBMLIR;DISABLE_INSTALL;ENABLE_AGGREGATION"
305
+ ""
306
+ "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
307
+ ${ARGN} )
308
+ _set_mlir_additional_headers_as_srcs (${ARG_ADDITIONAL_HEADERS} )
255
309
256
310
# Is an object library needed.
257
311
set (NEEDS_OBJECT_LIB OFF )
@@ -287,17 +341,7 @@ function(add_mlir_library name)
287
341
288
342
# MLIR libraries uniformly depend on LLVMSupport. Just specify it once here.
289
343
list (APPEND ARG_LINK_COMPONENTS Support )
290
-
291
- # LINK_COMPONENTS is necessary to allow libLLVM.so to be properly
292
- # substituted for individual library dependencies if LLVM_LINK_LLVM_DYLIB
293
- # Perhaps this should be in llvm_add_library instead? However, it fails
294
- # on libclang-cpp.so
295
- get_property (llvm_component_libs GLOBAL PROPERTY LLVM_COMPONENT_LIBS )
296
- foreach (lib ${ARG_LINK_LIBS} )
297
- if (${lib} IN_LIST llvm_component_libs )
298
- message (SEND_ERROR "${name} specifies LINK_LIBS ${lib} , but LINK_LIBS cannot be used for LLVM libraries. Please use LINK_COMPONENTS instead." )
299
- endif ()
300
- endforeach ()
344
+ _check_llvm_components_usage (${name} ${ARG_LINK_LIBS} )
301
345
302
346
list (APPEND ARG_DEPENDS mlir-generic-headers )
303
347
llvm_add_library (${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs} DEPENDS ${ARG_DEPENDS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} LINK_LIBS ${ARG_LINK_LIBS} )
0 commit comments