1# 2# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6 7cmake_minimum_required(VERSION 3.7.2) 8 9function(BuildCapDLApplication) 10 cmake_parse_arguments(PARSE_ARGV 0 CAPDL_BUILD_APP "" "C_SPEC;OUTPUT" "ELF;DEPENDS") 11 if(NOT "${CAPDL_BUILD_APP_UNPARSED_ARGUMENTS}" STREQUAL "") 12 message(FATAL_ERROR "Unknown arguments to BuildCapDLApplication") 13 endif() 14 # Require a cspec and an output 15 if("${CAPDL_BUILD_APP_C_SPEC}" STREQUAL "") 16 message(FATAL_ERROR "C_SPEC is required argument to BuildCapDLApplication") 17 endif() 18 if("${CAPDL_BUILD_APP_OUTPUT}" STREQUAL "") 19 message(FATAL_ERROR "OUTPUT is required argument to BuildCapDLApplication") 20 endif() 21 # Build a CPIO archive out of the provided ELF files 22 include(cpio) 23 MakeCPIO( 24 ${CAPDL_BUILD_APP_OUTPUT}_archive.o 25 "${CAPDL_BUILD_APP_ELF}" 26 CPIO_SYMBOL 27 _capdl_archive 28 ) 29 30 if(DEFINED platform_yaml) 31 32 find_file(PLATFORM_SIFT platform_sift.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH) 33 mark_as_advanced(FORCE PLATFORM_SIFT) 34 if("${PLATFORM_SIFT}" STREQUAL "PLATFORM_SIFT-NOTFOUND") 35 message( 36 FATAL_ERROR 37 "Failed to find platform_sift.py. Consider using -DPLATFORM_SIFT=/path/to/file" 38 ) 39 endif() 40 41 set( 42 MEMORY_REGIONS 43 "${CMAKE_BINARY_DIR}/capdl/capdl-loader-app/gen_config/capdl_loader_app/platform_info.h" 44 ) 45 add_custom_command( 46 COMMAND ${PLATFORM_SIFT} --emit-c-syntax ${platform_yaml} > ${MEMORY_REGIONS} 47 OUTPUT ${MEMORY_REGIONS} 48 ) 49 add_custom_target(mem_regions DEPENDS ${platform_yaml} ${PLATFORM_SIFT} ${MEMORY_REGIONS}) 50 set_property( 51 SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/capdl/capdl-loader-app/src/main.c 52 PROPERTY OBJECT_DEPENDS mem_regions 53 ) 54 endif() 55 56 # Build the application 57 add_executable( 58 "${CAPDL_BUILD_APP_OUTPUT}" 59 EXCLUDE_FROM_ALL 60 $<TARGET_PROPERTY:capdl_app_properties,C_FILES> 61 ${CAPDL_LOADER_APP_C_FILES} 62 ${CAPDL_BUILD_APP_OUTPUT}_archive.o 63 ${CAPDL_BUILD_APP_C_SPEC} 64 ) 65 66 if(DEFINED platform_yaml) 67 add_dependencies("${CAPDL_BUILD_APP_OUTPUT}" mem_regions) 68 endif() 69 70 add_dependencies("${CAPDL_BUILD_APP_OUTPUT}" ${CAPDL_BUILD_APP_DEPENDS}) 71 target_include_directories( 72 "${CAPDL_BUILD_APP_OUTPUT}" 73 PRIVATE $<TARGET_PROPERTY:capdl_app_properties,INCLUDE_DIRS> 74 ) 75 target_link_libraries( 76 "${CAPDL_BUILD_APP_OUTPUT}" 77 sel4runtime 78 sel4 79 cpio 80 sel4platsupport 81 sel4utils 82 capdl_loader_app_Config 83 sel4_autoconf 84 ) 85 if(KernelDebugBuild) 86 target_link_libraries("${CAPDL_BUILD_APP_OUTPUT}" sel4muslcsys) 87 endif() 88endfunction(BuildCapDLApplication) 89 90# Hook for CAmkES build system. This allows CAmkES projects to 91# propagate the capDL allocation setting into the loader. 92function(SetCapDLLoaderStaticAlloc) 93 set(CapDLLoaderStaticAlloc ON CACHE BOOL "" FORCE) 94endfunction() 95