Vinay Kumar Kotegowder | 932eed0 | 2019-08-22 00:42:47 +0530 | [diff] [blame] | 1 | #/** @file |
| 2 | # * Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved. |
| 3 | # * SPDX-License-Identifier : Apache-2.0 |
| 4 | # * |
| 5 | # * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # * you may not use this file except in compliance with the License. |
| 7 | # * You may obtain a copy of the License at |
| 8 | # * |
| 9 | # * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # * |
| 11 | # * Unless required by applicable law or agreed to in writing, software |
| 12 | # * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # * See the License for the specific language governing permissions and |
| 15 | # * limitations under the License. |
| 16 | #**/ |
| 17 | |
| 18 | set(CMAKE_SYSTEM_NAME Generic) |
| 19 | set(CMKE_SYSTEM_PROCESSOR ARM) |
| 20 | |
Øyvind Rønningstad | c50804e | 2021-03-12 12:43:25 +0100 | [diff] [blame] | 21 | if (DEFINED CROSS_COMPILE) |
| 22 | set(_C_TOOLCHAIN_NAME ${CROSS_COMPILE}-gcc) |
| 23 | else() |
| 24 | set(_C_TOOLCHAIN_NAME arm-none-eabi-gcc) |
| 25 | endif() |
Vinay Kumar Kotegowder | 932eed0 | 2019-08-22 00:42:47 +0530 | [diff] [blame] | 26 | |
| 27 | if (WIN32) |
| 28 | if (NOT DEFINED GNUARM_PATH) |
| 29 | set(GNUARM_PATH "C:" CACHE PATH "Install directory for GNUARM Compiler") |
| 30 | endif() |
| 31 | else (WIN32) |
| 32 | if (NOT DEFINED GNUARM_PATH) |
| 33 | set(GNUARM_PATH "/" CACHE PATH "Install directory for GNUARM Compiler") |
| 34 | endif() |
| 35 | endif (WIN32) |
| 36 | |
| 37 | find_program( |
| 38 | _C_TOOLCHAIN_PATH |
| 39 | ${_C_TOOLCHAIN_NAME} |
| 40 | PATHS env PATH |
| 41 | HINTS ${GNUARM_PATH} |
| 42 | HINTS bin |
| 43 | ) |
| 44 | |
| 45 | if (_C_TOOLCHAIN_PATH STREQUAL "_C_TOOLCHAIN_PATH-NOTFOUND") |
| 46 | message(FATAL_ERROR "[TBSA] : Couldn't find ${_C_TOOLCHAIN_NAME}." |
Øyvind Rønningstad | c50804e | 2021-03-12 12:43:25 +0100 | [diff] [blame] | 47 | " Either put ${_C_TOOLCHAIN_NAME} on the PATH or set GNUARM_PATH or CROSS_COMPILE properly.") |
Vinay Kumar Kotegowder | 932eed0 | 2019-08-22 00:42:47 +0530 | [diff] [blame] | 48 | endif() |
| 49 | |
| 50 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 51 | |
| 52 | foreach(_LNG IN ITEMS "C" "ASM") |
| 53 | set(CMAKE_${_LNG}_COMPILER ${_C_TOOLCHAIN_PATH}) |
| 54 | message(STATUS "[TBSA] : ${_LNG} compiler used '${CMAKE_${_LNG}_COMPILER}'") |
| 55 | endforeach() |
| 56 | |
| 57 | set(CMAKE_C_FLAGS "-march=armv8-m.${ARCH} -mcmse -mthumb -Wall -Werror -O0 -nostartfiles -fdata-sections -ffunction-sections") |
| 58 | set(CMAKE_ASM_FLAGS "-march=armv8-m.${ARCH} -mthumb") |
| 59 | set(CMAKE_EXE_LINKER_FLAGS "-Xlinker --fatal-warnings -Xlinker --gc-sections -z max-page-size=0x400 -lgcc -lc -lnosys") |
| 60 | |
| 61 | set(TBSA_LINKER_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_linker_scripts/tbsa.linker.template) |
| 62 | set(TBSA_TEST_LINKER_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_linker_scripts/test.linker.template) |
| 63 | set(TBSA_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/tbsa.linker) |
| 64 | set(TBSA_TEST_S_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/test_s.linker) |
| 65 | set(TBSA_TEST_NS_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/test_ns.linker) |
| 66 | |
| 67 | function(compiler_set_linker_options) |
| 68 | set(options) |
| 69 | set(oneValueArgs TARGET_NAME ENTRY_FUNCTION LINKER_SCRIPT MAP_FILE) #Single option arguments. |
| 70 | set(multiValueArgs) #List arguments |
| 71 | cmake_parse_arguments(_MY_PARAMS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
| 72 | |
| 73 | # Check passed arguments |
| 74 | if(NOT _MY_PARAMS_TARGET_NAME) |
| 75 | message(FATAL_ERROR "[TBSA] : compiler_set_linker_options: mandatory parameter 'TARGET_NAME' is missing!") |
| 76 | endif() |
| 77 | if(NOT _MY_PARAMS_ENTRY_FUNCTION) |
| 78 | message(FATAL_ERROR "[TBSA] : compiler_set_linker_options: mandatory parameter 'ENTRY_FUNCTION' is missing!") |
| 79 | endif() |
| 80 | if(NOT _MY_PARAMS_LINKER_SCRIPT) |
| 81 | message(FATAL_ERROR "[TBSA] : compiler_set_linker_options: mandatory parameter 'LINKER_SCRIPT' is missing!") |
| 82 | endif() |
| 83 | if(NOT _MY_PARAMS_MAP_FILE) |
| 84 | message(FATAL_ERROR "[TBSA] : compiler_set_linker_options: mandatory parameter 'MAP_FILE' is missing!") |
| 85 | endif() |
| 86 | |
| 87 | set_property(TARGET ${_MY_PARAMS_TARGET_NAME} APPEND_STRING PROPERTY LINK_FLAGS "--entry=${_MY_PARAMS_ENTRY_FUNCTION} -T${_MY_PARAMS_LINKER_SCRIPT} -Xlinker -Map=${_MY_PARAMS_MAP_FILE}") |
| 88 | endfunction(compiler_set_linker_options) |