| # Copyright 2023 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| include(CMakeParseArguments) |
| |
| # sparrow_test() |
| # |
| # A wrapper for the iree_cc_binary to attach lit run files to an executable |
| # Parameters: |
| # NAME: Name of target. |
| # SRCS: List of source files for the binary |
| # DEPS: List of other libraries to be linked in to the binary targets |
| # COPTS: List of public defines |
| # LINKOPTS: List of link options |
| # TESTFILES: List of lit test run files |
| # |
| # Examples: |
| # sparrow_test( |
| # NAME |
| # simple_int_vec_mul_emitc_static |
| # SRCS |
| # "int_vec.c" |
| # DEPS |
| # ::simple_int_mul_c_module_static_c |
| # ::simple_int_mul_c_module_static_emitc |
| # samples::util::util |
| # COPTS |
| # "-DBUILD_EMITC" |
| # TESTFILES |
| # "simple_test.run" |
| # ) |
| function(sparrow_test) |
| cmake_parse_arguments( |
| _RULE |
| "" |
| "NAME" |
| "SRCS;COPTS;LINKOPTS;DEPS;TESTFILES" |
| ${ARGN} |
| ) |
| |
| iree_cc_binary( |
| NAME |
| ${_RULE_NAME} |
| SRCS |
| ${_RULE_SRCS} |
| DEPS |
| ${_RULE_DEPS} |
| COPTS |
| ${_RULE_COPTS} |
| LINKOPTS |
| ${_RULE_LINKOPTS} |
| ) |
| if(NOT _RULE_TESTFILES) |
| return() |
| endif() |
| |
| iree_package_name(_PACKAGE_NAME) |
| foreach(_FILE ${_RULE_TESTFILES}) |
| get_filename_component(_FILE_PATH ${_FILE} REALPATH) |
| get_filename_component(_FILE_NAME ${_FILE_PATH} NAME) |
| set(_FILE_TARGET ${_PACKAGE_NAME}_${_FILE_NAME}) |
| if(NOT TARGET ${_FILE_TARGET}) |
| add_custom_target( |
| ${_FILE_TARGET} |
| COMMAND ${CMAKE_COMMAND} -E copy ${_FILE_PATH} |
| ${CMAKE_CURRENT_BINARY_DIR}/${_FILE_NAME} |
| BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE_NAME} |
| COMMENT "Copy lit run file ${_FILE_NAME}" |
| VERBATIM |
| ) |
| endif() |
| |
| add_dependencies(${_PACKAGE_NAME}_${_RULE_NAME} ${_FILE_TARGET}) |
| endforeach() |
| endfunction() |