# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # 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. # Add a panda assembly to the project using the specified source file # # Example usage: # # add_panda_assembly(TARGET SOURCE INDIR OUTDIR TARGETNAME ) # # Adds a panda assembly target called to be build from file # listed in the command invocation. function(add_panda_assembly) set(prefix ARG) set(noValues) set(singleValues TARGET SOURCE INDIR OUTDIR TARGETNAME) set(multiValues) cmake_parse_arguments(${prefix} "${noValues}" "${singleValues}" "${multiValues}" ${ARGN}) if (NOT DEFINED ARG_TARGET) message(FATAL_ERROR "Mandatory TARGET argument is not defined.") endif() if (NOT DEFINED ARG_SOURCE) message(FATAL_ERROR "Mandatory SOURCE argument is not defined.") endif() set(source_file_dir "${CMAKE_CURRENT_SOURCE_DIR}") if (DEFINED ARG_INDIR) set(source_file_dir "${ARG_INDIR}") endif() set(binary_file_dir "${CMAKE_CURRENT_BINARY_DIR}") if (DEFINED ARG_OUTDIR) set(binary_file_dir "${ARG_OUTDIR}") endif() set(target_file_name "${ARG_TARGET}") if (DEFINED ARG_TARGETNAME) set(target_file_name "${ARG_TARGETNAME}") endif() if (TARGET ARG_TARGET) message(FATAL_ERROR "Target ${ARG_TARGET} is already defined.") endif() set(source_file "${source_file_dir}/${ARG_SOURCE}") set(binary_file "${binary_file_dir}/${target_file_name}.abc") if(CMAKE_CROSSCOMPILING) ExternalProject_Get_Property(panda_host_tools binary_dir) set(assembler_target panda_host_tools) set(assembler_bin "${binary_dir}/assembler/ark_asm") else() set(assembler_target ark_asm) set(assembler_bin $) endif() add_custom_command(OUTPUT "${binary_file}" COMMENT "Building ${ARG_TARGET}" COMMAND "${assembler_bin}" "${source_file}" "${binary_file}" DEPENDS ${assembler_target} "${source_file}") add_custom_target(${ARG_TARGET} DEPENDS "${binary_file}") endfunction() # Use `mkdir` instead of `file(MAKE_DIRECTORY)` to create dependency on the directory existence: set(COMPILER_STATS_DIR "${CMAKE_BINARY_DIR}/compiler/stats/csv") add_custom_target(compiler_stats_dir COMMAND mkdir -p "${COMPILER_STATS_DIR}") # Add a single buildable and runnable Panda Assembly file to the build tree. # # Usage: # # panda_add_asm_file( # FILE # TARGET # [ENTRY ] # [SUBDIR ] # [OUTPUT_FILE_VARIABLE ] # [ERROR_FILE_VARIABLE ] # [SKIP_BUILD TRUE|FALSE] # [AOT_MODE TRUE|FALSE] # [AOT_STATS TRUE|FALSE] # [DEPENDS ...] # [RUNTIME_OPTIONS