1# Copyright (c) 2021-2022 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 14cmake_minimum_required(VERSION 3.10) 15 16project(arkfile) 17 18set(GEN_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include") 19file(MAKE_DIRECTORY ${GEN_INCLUDE_DIR}) 20file(MAKE_DIRECTORY "${GEN_INCLUDE_DIR}/tests") 21 22set(TEMPLATES 23 bytecode_instruction_enum_gen.h.erb 24 bytecode_instruction-inl_gen.h.erb 25 bytecode_emitter_def_gen.h.erb 26 bytecode_emitter_gen.h.erb 27 file_format_version.h.erb 28 tests/bytecode_emitter_tests_gen.h.erb 29) 30 31panda_isa_gen(TEMPLATES ${TEMPLATES} 32 SOURCE ${CMAKE_CURRENT_LIST_DIR}/templates 33 DESTINATION ${GEN_INCLUDE_DIR} 34 REQUIRES "${CMAKE_CURRENT_LIST_DIR}/pandafile_isapi.rb" 35 EXTRA_DEPENDENCIES ${output} 36) 37 38set(GENERATOR ${CMAKE_CURRENT_LIST_DIR}/types.rb) 39set(TEMPLATE ${CMAKE_CURRENT_LIST_DIR}/templates/type.h.erb) 40set(DATAFILE ${CMAKE_CURRENT_LIST_DIR}/types.yaml) 41set(DEPENDENCIES ${GENERATOR} ${TEMPLATE} ${DATAFILE}) 42set(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/include/type.h") 43add_custom_command(OUTPUT "${OUTFILE}" 44 COMMENT "Generate type.h" 45 COMMAND ${PANDA_ROOT}/isa/gen.rb -d ${DATAFILE} -t ${TEMPLATE} -o "${OUTFILE}" -r ${GENERATOR} 46 DEPENDS ${DEPENDENCIES}) 47 add_custom_target(type_gen_${PROJECT_NAME} ALL DEPENDS "${OUTFILE}") 48 49set(SOURCES 50 annotation_data_accessor.cpp 51 bytecode_emitter.cpp 52 debug_data_accessor.cpp 53 field_data_accessor.cpp 54 file.cpp 55 file_reader.cpp 56 file_writer.cpp 57 file_items.cpp 58 file_item_container.cpp 59 pgo.cpp 60 class_data_accessor.cpp 61 code_data_accessor.cpp 62 method_data_accessor.cpp 63 method_handle_data_accessor.cpp 64 debug_info_extractor.cpp 65 literal_data_accessor.cpp 66 file_format_version.cpp 67) 68 69add_library(arkfile ${PANDA_DEFAULT_LIB_TYPE} ${SOURCES}) 70 71panda_add_to_clang_tidy(TARGET arkfile) 72 73target_include_directories(arkfile 74 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} 75 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include 76) 77 78# Disable warning about offsetof usage for non-standard layout types. 79# In C++17 offsetof is conditionally implemented for such types, so 80# compiler should issue error if it doesn't implemented offsetof for 81# them. Also we use static asserts to ensure that offsetof works correctly 82# for non-standard layout types. 83target_compile_options(arkfile PUBLIC -Wno-invalid-offsetof) 84 85set(LINK_LIBRARIES arkbase arkziparchive c_secshared) 86if (NOT (PANDA_TARGET_MACOS OR PANDA_TARGET_OHOS)) 87 list(APPEND LINK_LIBRARIES atomic) 88endif() 89 90add_dependencies(arkfile isa_gen_${PROJECT_NAME} type_gen_${PROJECT_NAME}) 91 92target_link_libraries(arkfile ${LINK_LIBRARIES}) 93 94panda_add_gtest( 95 NAME arkfile_tests 96 SOURCES 97 tests/bytecode_instruction_tests.cpp 98 tests/file_test.cpp 99 tests/file_item_container_test.cpp 100 tests/file_items_test.cpp 101 tests/bytecode_emitter_tests.cpp 102 tests/debug_info_extractor_test.cpp 103 tests/file_format_version_test.cpp 104 LIBRARIES 105 arkbase 106 arkfile 107 arkassembler 108 arkziparchive 109 SANITIZERS 110 ${PANDA_SANITIZERS_LIST} 111) 112if(TARGET arkfile_tests) 113 add_dependencies(arkfile_tests isa_gen_${PROJECT_NAME}) 114 target_include_directories(arkfile_tests 115 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include/tests) 116endif() 117 118panda_add_sanitizers(TARGET arkfile SANITIZERS ${PANDA_SANITIZERS_LIST}) 119 120add_check_style(".") 121 122if (TARGET host_tools_depends) 123 add_dependencies(host_tools_depends arkfile) 124endif() 125 126if (DEFINED PANDA_ROOT_BINARY_DIR) 127 # Special case for host tool build. 128 target_include_directories(arkfile PUBLIC ${PANDA_ROOT_BINARY_DIR}/libpandafile/include) 129endif() 130