blob: 53f143a33c96424f5a4a90e7d9a441160aad2788 [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Gyorgy Szing1e4a5da2018-05-29 15:11:28 +02002# Copyright (c) 2017-2019, Arm Limited. All rights reserved.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8#This file contains settings to specify how ARMCLANG shall be used
9
10function(check_armclang_input_vars MY_VERSION)
11 #Specify where armclang is
12 if (NOT DEFINED ARMCLANG_PATH)
13 message(FATAL_ERROR "Please set ARMCLANG_PATH to the root directory of the armclang installation. e.g. set(ARMCLANG_PATH \"C:/Program Files/ARMCompiler${MY_VERSION}\")")
14 endif()
15
16 STRING(REGEX REPLACE "([0-9]+).([0-9]+).*" "\\1.\\2" _MY_MAJOR_MINOR "${MY_VERSION}")
17 STRING(REGEX REPLACE "([0-9]+).([0-9]+).*" "\\1.\\2" _ARMCLANG_MAJOR_MINOR "${ARMCLANG_VER}")
18
19 #Check armclang version.
20 if (NOT "${_MY_MAJOR_MINOR}" VERSION_EQUAL "${_ARMCLANG_MAJOR_MINOR}")
21 message(FATAL_ERROR "ARMClang version (ARMCLANG_VER=${ARMCLANG_VER}) does not match ${MY_VERSION}")
22 endif()
23
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000024 if (NOT DEFINED ARM_CPU_ARCHITECTURE AND NOT DEFINED ARM_CPU_TYPE)
25 message(FATAL_ERROR "ARM_CPU_TYPE and ARM_CPU_ARCHITECTURE is not defined! Please include the CPU specific config file before this one.")
Gyorgy Szing30fa9872017-12-05 01:08:47 +000026 endif()
27
28endfunction()
29
30message(STATUS "Using armclang compiler package v${ARMCLANG_VER} from ${ARMCLANG_PATH}")
31
32
33#Tell cmake which compiler we use
34if (EXISTS "c:/")
35 set (CMAKE_C_COMPILER "${ARMCLANG_PATH}/bin/armclang.exe")
36 set (CMAKE_CXX_COMPILER "${ARMCLANG_PATH}/bin/armclang.exe")
37 set (CMAKE_ASM_COMPILER "${ARMCLANG_PATH}/bin/armasm.exe")
38else()
39 set (CMAKE_C_COMPILER "${ARMCLANG_PATH}/bin/armclang")
40 set (CMAKE_CXX_COMPILER "${ARMCLANG_PATH}/bin/armclang")
41 set (CMAKE_ASM_COMPILER "${ARMCLANG_PATH}/bin/armasm")
42endif()
43
44if("CXX" IN_LIST languages)
45 set(CMAKE_CXX_COMPILER_ID "ARMCLANG" CACHE INTERNAL "CXX compiler ID" FORCE)
46 include(Compiler/ARMClang-CXX)
47endif()
48
49if("C" IN_LIST languages)
50 set(CMAKE_C_COMPILER_ID "ARMCLANG" CACHE INTERNAL "C compiler ID" FORCE)
51 include(Compiler/ARMClang-C)
52endif()
53
54if("ASM" IN_LIST languages)
55 set(CMAKE_C_COMPILER_ID "ARMCLANG" CACHE INTERNAL "ASM compiler ID" FORCE)
56 include(Compiler/ARMClang-ASM)
57endif()
58
Mate Toth-Pal76867262018-03-09 13:15:36 +010059function(compiler_set_linkercmdfile)
60 set( _OPTIONS_ARGS ) #Option (on/off) arguments.
61 set( _ONE_VALUE_ARGS TARGET PATH) #Single option arguments.
62 set( _MULTI_VALUE_ARGS DEFINES INCLUDES) #List arguments
63 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
64
65 #Check passed parameters
66 if(NOT _MY_PARAMS_TARGET)
67 message(FATAL_ERROR "compiler_set_linkercmdfile: mandatory parameter 'TARGET' is missing.")
68 endif()
69 if (NOT TARGET ${_MY_PARAMS_TARGET})
70 message(FATAL_ERROR "compiler_set_linkercmdfile: value of parameter 'TARGET' is invalid.")
71 endif()
72
73 if(NOT _MY_PARAMS_PATH)
74 message(FATAL_ERROR "compiler_set_linkercmdfile: mandatory parameter 'PATH' is missing.")
75 endif()
76 set(_FILE_PATH ${_MY_PARAMS_PATH})
77
78 #Compose additional command line switches from macro definitions.
79 set(_FLAGS "")
80 if (_MY_PARAMS_DEFINES)
81 foreach(_DEFINE IN LISTS _MY_PARAMS_DEFINES)
82 string(APPEND _FLAGS " --predefine=\"-D${_DEFINE}\"")
83 endforeach()
84 endif()
85 #Compose additional command line switches from include paths.
86 if (_MY_PARAMS_INCLUDES)
87 foreach(_INCLUDE_P IN LISTS _MY_PARAMS_INCLUDES)
Gabor Kerteszfffaafb2018-06-27 17:13:13 +020088 string(APPEND _FLAGS " --predefine=\"-I${_INCLUDE_P}\"")
Mate Toth-Pal76867262018-03-09 13:15:36 +010089 endforeach()
90 endif()
91
Gyorgy Szing30fa9872017-12-05 01:08:47 +000092 #Note: the space before the option is important!
Mate Toth-Pal76867262018-03-09 13:15:36 +010093 set_property(TARGET ${_MY_PARAMS_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " ${_FLAGS} --scatter=${_FILE_PATH}")
94 set_property(TARGET ${_MY_PARAMS_TARGET} APPEND PROPERTY LINK_DEPENDS ${_FILE_PATH})
Gyorgy Szing30fa9872017-12-05 01:08:47 +000095 #Tell cmake .map files shall be removed when project is cleaned (make clean)
Mate Toth-Pal76867262018-03-09 13:15:36 +010096 get_filename_component(_TARGET_BASE_NAME ${_MY_PARAMS_TARGET} NAME_WE)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000097 get_directory_property(_ADDITIONAL_MAKE_CLEAN_FILES DIRECTORY "./" ADDITIONAL_MAKE_CLEAN_FILES)
98 set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_ADDITIONAL_MAKE_CLEAN_FILES} ${_TARGET_BASE_NAME}.map")
99endfunction()
100
101function(compiler_set_cmse_output TARGET FILE_PATH)
102 #Note: the space before the option is important!
103 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --import_cmse_lib_out=${FILE_PATH}")
104 #Tell cmake cmse output is a generated object file.
105 SET_SOURCE_FILES_PROPERTIES("${FILE_PATH}" PROPERTIES EXTERNAL_OBJECT true GENERATED true)
106 #Tell cmake cmse output shall be removed by clean target.
107 get_directory_property(_ADDITIONAL_MAKE_CLEAN_FILES DIRECTORY "./" ADDITIONAL_MAKE_CLEAN_FILES)
108 set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_ADDITIONAL_MAKE_CLEAN_FILES} ${FILE_PATH}")
109endfunction()
110
111function(compiler_merge_library)
112 set( _OPTIONS_ARGS ) #Option (on/off) arguments.
Tamas Ban581034a2017-12-19 19:54:37 +0000113 set( _ONE_VALUE_ARGS DEST) #Single option arguments.
114 set( _MULTI_VALUE_ARGS LIBS) #List arguments
115 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000116
117 #Check passed parameters
118 if(NOT _MY_PARAMS_DEST)
119 message(FATAL_ERROR "embedded_merge_library: no destination library target specified.")
120 endif()
121 #Check if destination is a target
122 if(NOT TARGET ${_MY_PARAMS_DEST})
123 message(FATAL_ERROR "embedded_merge_library: parameter DEST must be a target already defined.")
124 endif()
125 #Check if destination is a library
126 get_target_property(_tmp ${_MY_PARAMS_DEST} TYPE)
127 if(NOT "${_tmp}" STREQUAL "STATIC_LIBRARY")
128 message(FATAL_ERROR "embedded_merge_library: parameter DEST must be a static library target.")
129 endif()
130
131 #Check list if libraries to be merged
132 if(NOT _MY_PARAMS_LIBS)
133 message(FATAL_ERROR "embedded_merge_library: no source libraries specified. Please see the LIBS parameter.")
134 endif()
135
136 #Mark each library file as a generated external object. This is needed to
137 #avoid error because CMake has no info how these can be built.
138 SET_SOURCE_FILES_PROPERTIES(
Tamas Ban581034a2017-12-19 19:54:37 +0000139 ${_MY_PARAMS_LIBS}
140 PROPERTIES
141 EXTERNAL_OBJECT true
142 GENERATED true)
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000143
144 #Add additional input to target
145 target_sources(${_MY_PARAMS_DEST} PRIVATE ${_MY_PARAMS_LIBS})
146endfunction()
Tamas Ban581034a2017-12-19 19:54:37 +0000147
148function(compiler_generate_binary_output TARGET)
149 add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_ARMCCLANG_FROMELF} ARGS --bincombined --output=$<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin $<TARGET_FILE:${TARGET}>)
150endfunction()