Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2019 The IREE Authors |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 2 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 6 | |
| 7 | include(CMakeParseArguments) |
| 8 | |
| 9 | # iree_tablegen_library() |
| 10 | # |
| 11 | # Runs iree-tablegen to produce some artifacts. |
| 12 | function(iree_tablegen_library) |
| 13 | cmake_parse_arguments( |
Ben Vanik | 6b112ef | 2019-10-03 10:45:14 -0700 | [diff] [blame] | 14 | _RULE |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 15 | "TESTONLY" |
Marius Brehler | 80d9abe | 2019-12-11 08:44:38 -0800 | [diff] [blame] | 16 | "NAME;TBLGEN" |
Marius Brehler | fa1dbd8 | 2020-01-28 14:45:50 -0800 | [diff] [blame] | 17 | "TD_FILE;OUTS" |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 18 | ${ARGN} |
| 19 | ) |
| 20 | |
Lei Zhang | d454ee4 | 2020-06-02 11:48:57 -0700 | [diff] [blame] | 21 | if(_RULE_TESTONLY AND NOT IREE_BUILD_TESTS) |
| 22 | return() |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 23 | endif() |
Lei Zhang | d454ee4 | 2020-06-02 11:48:57 -0700 | [diff] [blame] | 24 | |
| 25 | # Prefix the library with the package name, so we get: iree_package_name |
| 26 | iree_package_name(_PACKAGE_NAME) |
| 27 | set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}") |
| 28 | |
| 29 | if(${_RULE_TBLGEN} MATCHES "IREE") |
| 30 | set(_TBLGEN "IREE") |
| 31 | else() |
| 32 | set(_TBLGEN "MLIR") |
| 33 | endif() |
| 34 | |
| 35 | set(LLVM_TARGET_DEFINITIONS ${_RULE_TD_FILE}) |
Ben Vanik | 6bc6f90 | 2020-11-16 05:37:08 -0800 | [diff] [blame] | 36 | set(_INCLUDE_DIRS |
| 37 | "${MLIR_INCLUDE_DIRS}" |
| 38 | "${IREE_SOURCE_DIR}" |
| 39 | ) |
Lei Zhang | d454ee4 | 2020-06-02 11:48:57 -0700 | [diff] [blame] | 40 | list(APPEND _INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) |
| 41 | list(TRANSFORM _INCLUDE_DIRS PREPEND "-I") |
| 42 | set(_OUTPUTS) |
| 43 | while(_RULE_OUTS) |
| 44 | list(GET _RULE_OUTS 0 _COMMAND) |
| 45 | list(REMOVE_AT _RULE_OUTS 0) |
| 46 | list(GET _RULE_OUTS 0 _FILE) |
| 47 | list(REMOVE_AT _RULE_OUTS 0) |
| 48 | tablegen(${_TBLGEN} ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS}) |
| 49 | list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE}) |
| 50 | endwhile() |
| 51 | add_custom_target(${_NAME}_target DEPENDS ${_OUTPUTS}) |
| 52 | set_target_properties(${_NAME}_target PROPERTIES FOLDER "Tablegenning") |
| 53 | |
| 54 | add_library(${_NAME} INTERFACE) |
| 55 | add_dependencies(${_NAME} ${_NAME}_target) |
| 56 | |
| 57 | # Alias the iree_package_name library to iree::package::name. |
| 58 | iree_package_ns(_PACKAGE_NS) |
| 59 | add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME}) |
Ben Vanik | cc2aff9 | 2019-09-24 10:23:55 -0700 | [diff] [blame] | 60 | endfunction() |