blob: 6815e759f0d0b7eb50ae7af376e4305399793704 [file] [log] [blame]
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +05301#/** @file
Dávid Házi330c4b12023-05-03 11:20:02 +02002# * Copyright (c) 2019-2023, Arm Limited or its affiliates. All rights reserved.
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +05303# * 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)
jothikumar mani4a274162023-07-18 00:31:22 +080019set(CMAKE_SYSTEM_PROCESSOR ARM)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053020
jk-armbf532fd2021-05-07 13:58:22 +053021set(_C_TOOLCHAIN_NAME arm-none-eabi-gcc)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053022
23if(WIN32)
Dávid Házi330c4b12023-05-03 11:20:02 +020024 if (NOT DEFINED GNUARM_PATH)
25 set(GNUARM_PATH "C:" CACHE PATH "Install directory for GNUARM Compiler")
26 endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053027else(WIN32)
Dávid Házi330c4b12023-05-03 11:20:02 +020028 if (NOT DEFINED GNUARM_PATH)
29 set(GNUARM_PATH "/" CACHE PATH "Install directory for GNUARM Compiler")
30 endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053031endif(WIN32)
32
33find_program(
Dávid Házi330c4b12023-05-03 11:20:02 +020034 _C_TOOLCHAIN_PATH
35 ${_C_TOOLCHAIN_NAME}
36 PATHS env PATH
37 HINTS ${GNUARM_PATH}
38 HINTS bin
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053039)
40
41if(_C_TOOLCHAIN_PATH STREQUAL "_C_TOOLCHAIN_PATH-NOTFOUND")
42 message(FATAL_ERROR "[PSA] : Couldn't find ${_C_TOOLCHAIN_NAME}."
Dávid Házi330c4b12023-05-03 11:20:02 +020043 " Either put ${_C_TOOLCHAIN_NAME} on the PATH or set GNUARM_PATH set properly.")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053044endif()
45
46set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
47
48foreach(_LNG IN ITEMS "C" "ASM")
Dávid Házi330c4b12023-05-03 11:20:02 +020049 set(CMAKE_${_LNG}_COMPILER ${_C_TOOLCHAIN_PATH})
50 message(STATUS "[PSA] : ${_LNG} compiler used '${CMAKE_${_LNG}_COMPILER}'")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053051endforeach()
52
53if(${CPU_ARCH} STREQUAL armv7m)
Dávid Házi330c4b12023-05-03 11:20:02 +020054 set(TARGET_SWITCH "-march=armv7-m")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053055elseif(${CPU_ARCH} STREQUAL armv8m_ml)
Dávid Házi330c4b12023-05-03 11:20:02 +020056 set(TARGET_SWITCH "-march=armv8-m.main -mcmse")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053057elseif(${CPU_ARCH} STREQUAL armv8m_bl)
Dávid Házi330c4b12023-05-03 11:20:02 +020058 set(TARGET_SWITCH "-march=armv8-m.base -mcmse")
59elseif(${CPU_ARCH} STREQUAL armv81m_ml)
60 set(TARGET_SWITCH "-march=armv8.1-m.main -mcmse")
jothikumar mani4a274162023-07-18 00:31:22 +080061elseif(${CPU_ARCH} STREQUAL armv7a)
62 set(TARGET_SWITCH "-march=armv7-a")
63elseif(${CPU_ARCH} STREQUAL armv8a)
64 set(TARGET_SWITCH "-march=armv8-a")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053065endif()
66
Vinay Kumar Kotegowder52bbfc92020-07-03 17:23:59 +053067set(CMAKE_C_FLAGS "${TARGET_SWITCH} -g -Wall -Werror -Wextra -fdata-sections -ffunction-sections -mno-unaligned-access")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053068set(CMAKE_ASM_FLAGS "${TARGET_SWITCH} -mthumb")
69set(CMAKE_EXE_LINKER_FLAGS "-Xlinker --fatal-warnings -Xlinker --gc-sections -z max-page-size=0x400 -lgcc -lc -lnosys")