1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14add_library(asm_defines defines.cpp) 15 16add_dependencies(asm_defines 17 intrinsics_gen_arkruntime) 18 19set(ASM_DIR ${CMAKE_CURRENT_BINARY_DIR}) 20set(ASM_FILE libasm_defines.S) 21set(OUTPUT_FILE asm_defines.h) 22set(OUTPUT_DIR ${GEN_INCLUDE_DIR}) 23file(MAKE_DIRECTORY ${OUTPUT_DIR}) 24 25set_target_properties(asm_defines 26 PROPERTIES 27 ARCHIVE_OUTPUT_DIRECTORY ${ASM_DIR} 28 SUFFIX .S 29) 30 31target_include_directories(asm_defines 32 PUBLIC "$<TARGET_PROPERTY:arkruntime,INTERFACE_INCLUDE_DIRECTORIES>" 33 PUBLIC "$<TARGET_PROPERTY:arkruntime_test_interpreter_impl,INTERFACE_INCLUDE_DIRECTORIES>" 34) 35 36# We have to disable LTO, because it generates llvm IR instead of assembly for '-S' option. 37# Without this restriction, we can just use generator expressions and inherit compile flags from arkruntime (that looks 38# best way to do that): 39# target_compile_options(asm_defines 40# PUBLIC "$<TARGET_PROPERTY:arkruntime,COMPILE_OPTIONS>" 41# ) 42# But it seems that we can't remove options from the generator expressions. 43# (-fno-lto doesn't work because compilation fails with inappropriate regalloc) 44string(REPLACE "-mllvm -regalloc=${PANDA_LLVM_REGALLOC}" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 45string(REPLACE "-flto=thin" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 46target_compile_options(asm_defines PUBLIC "-Wno-invalid-offsetof") 47target_compile_options(asm_defines PUBLIC "-S") 48 49add_custom_command(OUTPUT ${OUTPUT_DIR}/${OUTPUT_FILE} 50 COMMAND ruby ${CMAKE_CURRENT_SOURCE_DIR}/defines_generator.rb "${ASM_DIR}/${ASM_FILE}" ${OUTPUT_DIR}/${OUTPUT_FILE} 51 DEPENDS asm_defines ${ASM_DIR}/${ASM_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/defines_generator.rb 52) 53 54add_custom_target(asm_defines_generator 55 DEPENDS ${OUTPUT_DIR}/${OUTPUT_FILE} 56) 57