1function(mlir_tablegen ofn) 2 tablegen(MLIR ${ARGV}) 3 set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn} 4 PARENT_SCOPE) 5endfunction() 6 7# TODO: This is to handle the current static registration, but should be 8# factored out a bit. 9function(whole_archive_link target) 10 add_dependencies(${target} ${ARGN}) 11 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") 12 set(link_flags "-L${CMAKE_BINARY_DIR}/lib ") 13 FOREACH(LIB ${ARGN}) 14 if("${CMAKE_GENERATOR}" STREQUAL "Xcode") 15 string(CONCAT link_flags ${link_flags} "-Wl,-force_load ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/lib${LIB}.a ") 16 else() 17 string(CONCAT link_flags ${link_flags} "-Wl,-force_load ${CMAKE_BINARY_DIR}/lib/lib${LIB}.a ") 18 endif() 19 ENDFOREACH(LIB) 20 elseif(MSVC) 21 FOREACH(LIB ${ARGN}) 22 string(CONCAT link_flags ${link_flags} "/WHOLEARCHIVE:${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${LIB}.lib ") 23 ENDFOREACH(LIB) 24 else() 25 set(link_flags "-L${CMAKE_BINARY_DIR}/lib -Wl,--whole-archive,") 26 FOREACH(LIB ${ARGN}) 27 string(CONCAT link_flags ${link_flags} "-l${LIB},") 28 ENDFOREACH(LIB) 29 string(CONCAT link_flags ${link_flags} "--no-whole-archive") 30 endif() 31 set_target_properties(${target} PROPERTIES LINK_FLAGS ${link_flags}) 32endfunction(whole_archive_link) 33 34# Declare a dialect in the include directory 35function(add_mlir_dialect dialect dialect_namespace) 36 set(LLVM_TARGET_DEFINITIONS ${dialect}.td) 37 mlir_tablegen(${dialect}.h.inc -gen-op-decls) 38 mlir_tablegen(${dialect}.cpp.inc -gen-op-defs) 39 mlir_tablegen(${dialect}Dialect.h.inc -gen-dialect-decls -dialect=${dialect_namespace}) 40 add_public_tablegen_target(MLIR${dialect}IncGen) 41 add_dependencies(mlir-headers MLIR${dialect}IncGen) 42endfunction() 43 44# Generate Documentation 45function(add_mlir_doc doc_filename command output_file output_directory) 46 set(LLVM_TARGET_DEFINITIONS ${doc_filename}.td) 47 tablegen(MLIR ${output_file}.md ${command} "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}") 48 set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/${output_directory}${output_file}.md) 49 add_custom_command( 50 OUTPUT ${GEN_DOC_FILE} 51 COMMAND ${CMAKE_COMMAND} -E copy 52 ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.md 53 ${GEN_DOC_FILE} 54 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.md) 55 add_custom_target(${output_file}DocGen DEPENDS ${GEN_DOC_FILE}) 56 add_dependencies(mlir-doc ${output_file}DocGen) 57endfunction() 58 59# Declare a library which can be compiled in libMLIR.so 60macro(add_mlir_library name) 61 set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name}) 62 add_llvm_library(${ARGV}) 63endmacro(add_mlir_library) 64 65# Declare the library associated with a dialect. 66function(add_mlir_dialect_library name) 67 set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name}) 68 add_mlir_library(${ARGV}) 69endfunction(add_mlir_dialect_library) 70 71# Declare the library associated with a conversion. 72function(add_mlir_conversion_library name) 73 set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name}) 74 add_mlir_library(${ARGV}) 75endfunction(add_mlir_conversion_library) 76