blob: faf1755f2d8650dca14ce0013f77fb8e4d646969 [file] [log] [blame]
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +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 Kotegowder9982f902019-07-15 09:13:54 +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 "[PSA] : 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 Kotegowder9982f902019-07-15 09:13:54 +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 "[PSA] : ${_LNG} compiler used '${CMAKE_${_LNG}_COMPILER}'")
55endforeach()
56
57if(${CPU_ARCH} STREQUAL armv7m)
58 set(TARGET_SWITCH "-march=armv7-m")
59elseif(${CPU_ARCH} STREQUAL armv8m_ml)
60 set(TARGET_SWITCH "-march=armv8-m.main -mcmse")
61elseif(${CPU_ARCH} STREQUAL armv8m_bl)
62 set(TARGET_SWITCH "-march=armv8-m.base -mcmse")
63endif()
64
Vinay Kumar Kotegowder52bbfc92020-07-03 17:23:59 +053065set(CMAKE_C_FLAGS "${TARGET_SWITCH} -g -Wall -Werror -Wextra -fdata-sections -ffunction-sections -mno-unaligned-access")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053066set(CMAKE_ASM_FLAGS "${TARGET_SWITCH} -mthumb")
67set(CMAKE_EXE_LINKER_FLAGS "-Xlinker --fatal-warnings -Xlinker --gc-sections -z max-page-size=0x400 -lgcc -lc -lnosys")