1# 2# SPDX-License-Identifier: BSD-3-Clause 3# SPDX-FileCopyrightText: Copyright TF-RMM Contributors. 4# 5 6include_guard() 7include(CheckCCompilerFlag) 8 9include(${CMAKE_CURRENT_LIST_DIR}/../common.cmake) 10 11set(CMAKE_SYSTEM_NAME "Generic") 12set(CMAKE_SYSTEM_PROCESSOR aarch64) 13 14foreach(language IN ITEMS ASM C) 15 string(APPEND CMAKE_${language}_FLAGS_INIT "-ffreestanding ") 16 string(APPEND CMAKE_${language}_FLAGS_INIT "-mbranch-protection=standard ") 17 string(APPEND CMAKE_${language}_FLAGS_INIT "-mgeneral-regs-only ") 18 string(APPEND CMAKE_${language}_FLAGS_INIT "-mstrict-align ") 19 string(APPEND CMAKE_${language}_FLAGS_INIT "-fpie ") 20 # Omit the frame pointer for Release build, this also disables 21 # backtrace in the exception handler. 22 string(APPEND CMAKE_${language}_FLAGS_RELEASE_INIT "-fomit-frame-pointer ") 23 string(APPEND CMAKE_${language}_FLAGS_DEBUG_INIT "-fno-omit-frame-pointer ") 24endforeach() 25 26string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-nostdlib ") 27string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-pie ") 28 29# Detect applicable "march=" option supported by compiler 30function(detect_and_set_march) 31 set (march_list 9.2 9.1 9 8.8 8.7 8.6 8.5) 32 33 foreach(v ${march_list}) 34 string(REPLACE "." "_" n ${v}) 35 check_c_compiler_flag("-march=armv${v}-a" COMPILER_SUPPORTS_${n}) 36 if(COMPILER_SUPPORTS_${n}) 37 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv${v}-a" PARENT_SCOPE) 38 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=armv${v}-a" PARENT_SCOPE) 39 return() 40 endif() 41 endforeach() 42 message(FATAL_ERROR "Suitable -march not detected. Please upgrade aarch64 compiler." ) 43endfunction() 44