1# Copyright 2019 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# https://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 15# Forked from IREE's iree_cc_binary.cmake. 16 17include(CMakeParseArguments) 18include(cmake/ruy_include_directories.cmake) 19 20# ruy_cc_binary() 21# 22# CMake function to imitate Bazel's cc_binary rule. 23function(ruy_cc_binary) 24 cmake_parse_arguments( 25 _RULE 26 "TESTONLY" 27 "NAME" 28 "SRCS;COPTS;LINKOPTS;DEPS;TAGS" 29 ${ARGN} 30 ) 31 32 if(_RULE_TESTONLY AND RUY_MINIMAL_BUILD) 33 return() 34 endif() 35 36 set(_NAME "${_RULE_NAME}") 37 38 add_executable(${_NAME} "") 39 target_sources(${_NAME} 40 PRIVATE 41 ${_RULE_SRCS} 42 ) 43 set_target_properties(${_NAME} PROPERTIES OUTPUT_NAME "${_RULE_NAME}") 44 ruy_include_directories(${_NAME} "${_RULE_DEPS}") 45 target_compile_options(${_NAME} 46 PRIVATE 47 ${_RULE_COPTS} 48 ) 49 target_link_options(${_NAME} 50 PRIVATE 51 ${_RULE_LINKOPTS} 52 ) 53 target_link_libraries(${_NAME} 54 PUBLIC 55 ${_RULE_DEPS} 56 ) 57endfunction() 58