blob: 9ca9a64c6616e0bc7bd80743cd5242f6dc3f775a [file] [log] [blame]
Vinay Kumar Kotegowder932eed02019-08-22 00:42:47 +05301#/** @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
18set(CMAKE_SYSTEM_NAME Generic)
19set(CMKE_SYSTEM_PROCESSOR ARM)
20
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +010021if (DEFINED CROSS_COMPILE)
22 set(_C_TOOLCHAIN_NAME ${CROSS_COMPILE}-gcc)
23else()
24 set(_C_TOOLCHAIN_NAME arm-none-eabi-gcc)
25endif()
Vinay Kumar Kotegowder932eed02019-08-22 00:42:47 +053026
27if (WIN32)
28 if (NOT DEFINED GNUARM_PATH)
29 set(GNUARM_PATH "C:" CACHE PATH "Install directory for GNUARM Compiler")
30 endif()
31else (WIN32)
32 if (NOT DEFINED GNUARM_PATH)
33 set(GNUARM_PATH "/" CACHE PATH "Install directory for GNUARM Compiler")
34 endif()
35endif (WIN32)
36
37find_program(
38 _C_TOOLCHAIN_PATH
39 ${_C_TOOLCHAIN_NAME}
40 PATHS env PATH
41 HINTS ${GNUARM_PATH}
42 HINTS bin
43)
44
45if (_C_TOOLCHAIN_PATH STREQUAL "_C_TOOLCHAIN_PATH-NOTFOUND")
46 message(FATAL_ERROR "[TBSA] : Couldn't find ${_C_TOOLCHAIN_NAME}."
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +010047 " Either put ${_C_TOOLCHAIN_NAME} on the PATH or set GNUARM_PATH or CROSS_COMPILE properly.")
Vinay Kumar Kotegowder932eed02019-08-22 00:42:47 +053048endif()
49
50set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
51
52foreach(_LNG IN ITEMS "C" "ASM")
53 set(CMAKE_${_LNG}_COMPILER ${_C_TOOLCHAIN_PATH})
54 message(STATUS "[TBSA] : ${_LNG} compiler used '${CMAKE_${_LNG}_COMPILER}'")
55endforeach()
56
57set(CMAKE_C_FLAGS "-march=armv8-m.${ARCH} -mcmse -mthumb -Wall -Werror -O0 -nostartfiles -fdata-sections -ffunction-sections")
58set(CMAKE_ASM_FLAGS "-march=armv8-m.${ARCH} -mthumb")
59set(CMAKE_EXE_LINKER_FLAGS "-Xlinker --fatal-warnings -Xlinker --gc-sections -z max-page-size=0x400 -lgcc -lc -lnosys")
60
61set(TBSA_LINKER_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_linker_scripts/tbsa.linker.template)
62set(TBSA_TEST_LINKER_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_linker_scripts/test.linker.template)
63set(TBSA_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/tbsa.linker)
64set(TBSA_TEST_S_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/test_s.linker)
65set(TBSA_TEST_NS_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/test_ns.linker)
66
67function(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}")
88endfunction(compiler_set_linker_options)