Lun Dong | 26c106a | 2023-10-24 09:14:25 -0700 | [diff] [blame] | 1 | # Copyright 2023 Google LLC |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Cindy Liu | 0db7168 | 2022-07-19 14:50:54 -0700 | [diff] [blame] | 15 | include(CMakeParseArguments) |
| 16 | |
Lun Dong | cf1be4a | 2023-07-18 13:42:47 -0700 | [diff] [blame] | 17 | # sparrow_test() |
Cindy Liu | 0db7168 | 2022-07-19 14:50:54 -0700 | [diff] [blame] | 18 | # |
| 19 | # A wrapper for the iree_cc_binary to attach lit run files to an executable |
| 20 | # Parameters: |
| 21 | # NAME: Name of target. |
| 22 | # SRCS: List of source files for the binary |
| 23 | # DEPS: List of other libraries to be linked in to the binary targets |
| 24 | # COPTS: List of public defines |
| 25 | # LINKOPTS: List of link options |
| 26 | # TESTFILES: List of lit test run files |
| 27 | # |
| 28 | # Examples: |
Lun Dong | cf1be4a | 2023-07-18 13:42:47 -0700 | [diff] [blame] | 29 | # sparrow_test( |
Cindy Liu | 0db7168 | 2022-07-19 14:50:54 -0700 | [diff] [blame] | 30 | # NAME |
| 31 | # simple_int_vec_mul_emitc_static |
| 32 | # SRCS |
| 33 | # "int_vec.c" |
| 34 | # DEPS |
| 35 | # ::simple_int_mul_c_module_static_c |
| 36 | # ::simple_int_mul_c_module_static_emitc |
| 37 | # samples::util::util |
| 38 | # COPTS |
| 39 | # "-DBUILD_EMITC" |
| 40 | # TESTFILES |
| 41 | # "simple_test.run" |
| 42 | # ) |
Lun Dong | cf1be4a | 2023-07-18 13:42:47 -0700 | [diff] [blame] | 43 | function(sparrow_test) |
Cindy Liu | 0db7168 | 2022-07-19 14:50:54 -0700 | [diff] [blame] | 44 | cmake_parse_arguments( |
| 45 | _RULE |
| 46 | "" |
| 47 | "NAME" |
| 48 | "SRCS;COPTS;LINKOPTS;DEPS;TESTFILES" |
| 49 | ${ARGN} |
| 50 | ) |
| 51 | |
| 52 | iree_cc_binary( |
| 53 | NAME |
| 54 | ${_RULE_NAME} |
| 55 | SRCS |
| 56 | ${_RULE_SRCS} |
| 57 | DEPS |
| 58 | ${_RULE_DEPS} |
| 59 | COPTS |
| 60 | ${_RULE_COPTS} |
| 61 | LINKOPTS |
| 62 | ${_RULE_LINKOPTS} |
| 63 | ) |
| 64 | if(NOT _RULE_TESTFILES) |
| 65 | return() |
| 66 | endif() |
| 67 | |
| 68 | iree_package_name(_PACKAGE_NAME) |
| 69 | foreach(_FILE ${_RULE_TESTFILES}) |
| 70 | get_filename_component(_FILE_PATH ${_FILE} REALPATH) |
| 71 | get_filename_component(_FILE_NAME ${_FILE_PATH} NAME) |
| 72 | set(_FILE_TARGET ${_PACKAGE_NAME}_${_FILE_NAME}) |
| 73 | if(NOT TARGET ${_FILE_TARGET}) |
| 74 | add_custom_target( |
| 75 | ${_FILE_TARGET} |
| 76 | COMMAND ${CMAKE_COMMAND} -E copy ${_FILE_PATH} |
| 77 | ${CMAKE_CURRENT_BINARY_DIR}/${_FILE_NAME} |
| 78 | BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE_NAME} |
| 79 | COMMENT "Copy lit run file ${_FILE_NAME}" |
| 80 | VERBATIM |
| 81 | ) |
| 82 | endif() |
| 83 | |
| 84 | add_dependencies(${_PACKAGE_NAME}_${_RULE_NAME} ${_FILE_TARGET}) |
| 85 | endforeach() |
| 86 | endfunction() |