|
| 1 | +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +# SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +# For AMD-Xilinx tooling enable control flow path whereby only target app |
| 5 | +# is configured to build. In the future we can add options for each |
| 6 | +# app but for now enable as a one-shot flow switch |
| 7 | + |
| 8 | +message("Building for AMD-Xilinx Demos") |
| 9 | + |
| 10 | +cmake_minimum_required(VERSION 3.24) |
| 11 | + |
| 12 | +enable_language(C ASM ) |
| 13 | + |
| 14 | +set_property (GLOBAL PROPERTY OPENAMP_APP_NAME "${OPENAMP_APP_NAME}") |
| 15 | +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/") |
| 16 | + |
| 17 | +include(CheckSymbolExists) |
| 18 | + |
| 19 | +# Demos currently target R5 and R52. |
| 20 | +# If the target is not one of these target cores, then surrounding |
| 21 | +# tooling (Yocto or Vitis) will report error. |
| 22 | +#set (MACHINE "zynqmp_r5") |
| 23 | +#set_property (GLOBAL PROPERTY MACHINE ${MACHINE}) |
| 24 | +#set (PROJECT_MACHINE ${MACHINE}) |
| 25 | + |
| 26 | +get_property (OPENAMP_APP_NAME GLOBAL PROPERTY OPENAMP_APP_NAME) |
| 27 | +if(OPENAMP_APP_NAME STREQUAL "rpc_demo") |
| 28 | + set(_app rpc_demo) |
| 29 | +elseif(OPENAMP_APP_NAME STREQUAL "echo") |
| 30 | + set (_app rpmsg-echo) |
| 31 | +elseif(OPENAMP_APP_NAME STREQUAL "matrix_multiply") |
| 32 | + set (_app matrix_multiplyd) |
| 33 | +else() |
| 34 | + message(FATAL_ERROR "OPENAMP_APP_NAME not picked up") |
| 35 | +endif() |
| 36 | +message("OpenAMP: OPENAMP_APP_NAME: ${OPENAMP_APP_NAME}") |
| 37 | + |
| 38 | +# Ensure that for Compile step that the _AMD_GENERATED_ symbol is present |
| 39 | +# for app build if it was provided in CMake configure tooling |
| 40 | +if (_AMD_GENERATED_) |
| 41 | + add_definitions(-D_AMD_GENERATED_) |
| 42 | +endif() |
| 43 | + |
| 44 | +string(TOUPPER "${CMAKE_MACHINE}" _soc) |
| 45 | + |
| 46 | +if(_soc STREQUAL "ZYNQMP" OR _soc STREQUAL "VERSAL") |
| 47 | + set_property(GLOBAL PROPERTY SOC "${_soc}") |
| 48 | +else() |
| 49 | + message(FATAL_ERROR "Unsupported CMAKE_MACHINE: ${CMAKE_MACHINE}") |
| 50 | +endif() |
| 51 | + |
| 52 | +get_property (SOC GLOBAL PROPERTY SOC) |
| 53 | +message("OpenAMP: SOC in build is: ${SOC}") |
| 54 | + |
| 55 | +# Lopper plugin can generate linker meta data in below file |
| 56 | +# This can define RSC_TABLE so include before |
| 57 | +message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") |
| 58 | +file (GLOB LINKER_METADATA_FILE "${CMAKE_SOURCE_DIR}/*Example.cmake") |
| 59 | +if (EXISTS ${LINKER_METADATA_FILE}) |
| 60 | + set_property(GLOBAL PROPERTY LINKER_METADATA_FILE ${LINKER_METADATA_FILE}) |
| 61 | + message("OpenAMP: Linker will be configured using file: ${LINKER_METADATA_FILE}") |
| 62 | +else() |
| 63 | + message("OpenAMP: Linker will be configured using static linker script for ${SOC}") |
| 64 | +endif() |
| 65 | + |
| 66 | +get_property (OPENAMP_APP_NAME GLOBAL PROPERTY OPENAMP_APP_NAME) |
| 67 | +if (OPENAMP_APP_NAME STREQUAL "") |
| 68 | + message(FATAL_ERROR "AMD-Xilinx: Demos: missing property OPENAMP_APP_NAME.") |
| 69 | + return() |
| 70 | +#else() |
| 71 | + #add_subdirectory (${APPS_ROOT_DIR}/machine ${CMAKE_CURRENT_BINARY_DIR}/machine_build) |
| 72 | + #add_subdirectory (${APPS_ROOT_DIR}/system ${CMAKE_CURRENT_BINARY_DIR}/system_build) |
| 73 | +endif (OPENAMP_APP_NAME STREQUAL "") |
| 74 | + |
| 75 | +add_subdirectory(${PROJECT_MACHINE}) |
| 76 | + |
| 77 | +# pull in original legacy app demo logic here |
| 78 | +set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") |
| 79 | +set (_fw_dir "${APPS_SHARE_DIR}") |
| 80 | + |
| 81 | +collect(APP_INC_DIRS ${APPS_ROOT_DIR}/examples/${OPENAMP_APP_NAME}) |
| 82 | +collect(APP_INC_DIRS ${APPS_ROOT_DIR}/machine/${MACHINE}) |
| 83 | + |
| 84 | +collector_list (_list PROJECT_INC_DIRS) |
| 85 | +collector_list (_app_list APP_INC_DIRS) |
| 86 | + |
| 87 | +include_directories (${_list} ${_app_list}) |
| 88 | +include_directories (${APPS_ROOT_DIR}/examples/legacy_apps/include) |
| 89 | +link_directories (${_list} ${_app_list}) |
| 90 | + |
| 91 | +get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) |
| 92 | + |
| 93 | +# below is where demo config and compilation occurs |
| 94 | +collect(PROJECT_LIB_DEPS c) |
| 95 | +collect(PROJECT_LIB_DEPS m) |
| 96 | +collect(PROJECT_LIB_DEPS metal) |
| 97 | +collect(PROJECT_LIB_DEPS open_amp) |
| 98 | + |
| 99 | +collect (APP_COMMON_SOURCES "${APPS_ROOT_DIR}/examples/${OPENAMP_APP_NAME}/${_app}.c") |
| 100 | +collect (APP_COMMON_SOURCES "${APPS_ROOT_DIR}/examples/${OPENAMP_APP_NAME}/${PROJECT_SYSTEM}/main.c") |
| 101 | +collector_list (_sources APP_COMMON_SOURCES) |
| 102 | + |
| 103 | +collector_list (_app_list APP_INC_DIRS) |
| 104 | +collector_list (_list PROJECT_INC_DIRS) |
| 105 | +include_directories (${_list} ${_app_list} ${APPS_ROOT_DIR} ${APPS_ROOT_DIR}/system/${PROJECT_SYSTEM}/machine/${PROJECT_MACHINE}/) |
| 106 | +collector_list (_list PROJECT_LIB_DIRS) |
| 107 | +collector_list (_app_list APP_LIB_DIRS) |
| 108 | +link_directories (${_list} ${_app_list} ${APPS_ROOT_DIR}/system/${PROJECT_SYSTEM}/machine/${PROJECT_MACHINE}/) |
| 109 | +# UserConfig.cmake is file generated by Vitis-Unified workspace for applications. |
| 110 | +include(${CMAKE_SOURCE_DIR}/UserConfig.cmake) |
| 111 | +set (executable_name ${CMAKE_PROJECT_NAME}) |
| 112 | +add_executable (${executable_name}.elf ${_sources}) |
| 113 | +set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") |
| 114 | + |
| 115 | +get_property (LINKER_METADATA_FILE GLOBAL PROPERTY LINKER_METADATA_FILE) |
| 116 | +get_property (SOC GLOBAL PROPERTY SOC) |
| 117 | +set (SOCS ZYNQMP VERSAL) |
| 118 | +set (LOPPER_CFG_LINKERS lscript_r5.ld.in lscript_versal_r5.ld.in) |
| 119 | + |
| 120 | +list(FIND SOCS "${SOC}" soc_index) |
| 121 | + |
| 122 | +# AMD-Xilinx SDT workflow has split up libxil. Below are required libs |
| 123 | +# That were previously in libxil. |
| 124 | +collect(PROJECT_LIB_DEPS xil) |
| 125 | +collect(PROJECT_LIB_DEPS xiltimer) |
| 126 | +collect(PROJECT_LIB_DEPS xilstandalone) |
| 127 | + |
| 128 | +if (EXISTS ${LINKER_METADATA_FILE}) |
| 129 | + include(${LINKER_METADATA_FILE}) |
| 130 | + list (GET LOPPER_CFG_LINKERS ${soc_index} linker_in) |
| 131 | + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/linker_files/${linker_in} "${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld") |
| 132 | + list(APPEND LINKER_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${linker_in}) |
| 133 | + list(APPEND LINKER_FILE ${linker_in}) |
| 134 | + set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld") |
| 135 | + message("Using LINKER_METADATA_FILE: ${LINKER_METADATA_FILE}") |
| 136 | + set (_linker_opt "-Wl,--defsym,_rsc_table=${RSC_TABLE} -T\"${_linker_script}\"") |
| 137 | +else() |
| 138 | + message(FATAL_ERROR "Could not find linker meta data file") |
| 139 | +endif(EXISTS ${LINKER_METADATA_FILE}) |
| 140 | + |
| 141 | +collector_list (_deps PROJECT_LIB_DEPS) |
| 142 | + |
| 143 | +# Enable user to pass in extra linker flags |
| 144 | +if (DEFINED DEMO_LINK_FLAGS) |
| 145 | + set (_deps "${_deps} ${DEMO_LINK_FLAGS}") |
| 146 | +endif(DEFINED DEMO_LINK_FLAGS) |
| 147 | + |
| 148 | +target_link_libraries(${executable_name}.elf -Wl,-Map=${executable_name}.map -L${CMAKE_LIBRARY_PATH} -L${USER_LINK_DIRECTORIES} -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB} ${_deps} -Wl,--end-group) |
| 149 | +target_compile_definitions(${executable_name}.elf PUBLIC ${USER_COMPILE_DEFINITIONS}) |
| 150 | +install (TARGETS ${executable_name}.elf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
0 commit comments