Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame^] | 2 | # Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | #This file contains settings to specify how ARMCLANG shall be used |
| 9 | |
| 10 | function(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 | |
| 24 | #Emit warning if needed environment variables are not set. |
| 25 | if(NOT DEFINED ENV{ARM_TOOL_VARIANT} OR NOT DEFINED ENV{ARM_PRODUCT_PATH}) |
| 26 | message(WARNING "ARM_TOOL_VARIANT or ARM_PRODUCT_PATH environment variables are not set!") |
| 27 | endif() |
| 28 | |
| 29 | if (NOT DEFINED ARM_CPU_ARHITECTURE AND NOT DEFINED ARM_CPU_TYPE) |
| 30 | message(FATAL_ERROR "ARM_CPU_TYPE and ARM_CPU_ARHITECTURE is not defined! Please include the CPU specific config file before this one.") |
| 31 | endif() |
| 32 | |
| 33 | endfunction() |
| 34 | |
| 35 | message(STATUS "Using armclang compiler package v${ARMCLANG_VER} from ${ARMCLANG_PATH}") |
| 36 | |
| 37 | |
| 38 | #Tell cmake which compiler we use |
| 39 | if (EXISTS "c:/") |
| 40 | set (CMAKE_C_COMPILER "${ARMCLANG_PATH}/bin/armclang.exe") |
| 41 | set (CMAKE_CXX_COMPILER "${ARMCLANG_PATH}/bin/armclang.exe") |
| 42 | set (CMAKE_ASM_COMPILER "${ARMCLANG_PATH}/bin/armasm.exe") |
| 43 | else() |
| 44 | set (CMAKE_C_COMPILER "${ARMCLANG_PATH}/bin/armclang") |
| 45 | set (CMAKE_CXX_COMPILER "${ARMCLANG_PATH}/bin/armclang") |
| 46 | set (CMAKE_ASM_COMPILER "${ARMCLANG_PATH}/bin/armasm") |
| 47 | endif() |
| 48 | |
| 49 | if("CXX" IN_LIST languages) |
| 50 | set(CMAKE_CXX_COMPILER_ID "ARMCLANG" CACHE INTERNAL "CXX compiler ID" FORCE) |
| 51 | include(Compiler/ARMClang-CXX) |
| 52 | endif() |
| 53 | |
| 54 | if("C" IN_LIST languages) |
| 55 | set(CMAKE_C_COMPILER_ID "ARMCLANG" CACHE INTERNAL "C compiler ID" FORCE) |
| 56 | include(Compiler/ARMClang-C) |
| 57 | endif() |
| 58 | |
| 59 | if("ASM" IN_LIST languages) |
| 60 | set(CMAKE_C_COMPILER_ID "ARMCLANG" CACHE INTERNAL "ASM compiler ID" FORCE) |
| 61 | include(Compiler/ARMClang-ASM) |
| 62 | endif() |
| 63 | |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame^] | 64 | function(compiler_set_linkercmdfile) |
| 65 | set( _OPTIONS_ARGS ) #Option (on/off) arguments. |
| 66 | set( _ONE_VALUE_ARGS TARGET PATH) #Single option arguments. |
| 67 | set( _MULTI_VALUE_ARGS DEFINES INCLUDES) #List arguments |
| 68 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} ) |
| 69 | |
| 70 | #Check passed parameters |
| 71 | if(NOT _MY_PARAMS_TARGET) |
| 72 | message(FATAL_ERROR "compiler_set_linkercmdfile: mandatory parameter 'TARGET' is missing.") |
| 73 | endif() |
| 74 | if (NOT TARGET ${_MY_PARAMS_TARGET}) |
| 75 | message(FATAL_ERROR "compiler_set_linkercmdfile: value of parameter 'TARGET' is invalid.") |
| 76 | endif() |
| 77 | |
| 78 | if(NOT _MY_PARAMS_PATH) |
| 79 | message(FATAL_ERROR "compiler_set_linkercmdfile: mandatory parameter 'PATH' is missing.") |
| 80 | endif() |
| 81 | set(_FILE_PATH ${_MY_PARAMS_PATH}) |
| 82 | |
| 83 | #Compose additional command line switches from macro definitions. |
| 84 | set(_FLAGS "") |
| 85 | if (_MY_PARAMS_DEFINES) |
| 86 | foreach(_DEFINE IN LISTS _MY_PARAMS_DEFINES) |
| 87 | string(APPEND _FLAGS " --predefine=\"-D${_DEFINE}\"") |
| 88 | endforeach() |
| 89 | endif() |
| 90 | #Compose additional command line switches from include paths. |
| 91 | if (_MY_PARAMS_INCLUDES) |
| 92 | foreach(_INCLUDE_P IN LISTS _MY_PARAMS_INCLUDES) |
| 93 | string(APPEND _FLAGS " -I ${_INCLUDE_P}") |
| 94 | endforeach() |
| 95 | endif() |
| 96 | |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 97 | #Note: the space before the option is important! |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame^] | 98 | set_property(TARGET ${_MY_PARAMS_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " ${_FLAGS} --scatter=${_FILE_PATH}") |
| 99 | set_property(TARGET ${_MY_PARAMS_TARGET} APPEND PROPERTY LINK_DEPENDS ${_FILE_PATH}) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 100 | #Tell cmake .map files shall be removed when project is cleaned (make clean) |
Mate Toth-Pal | 7686726 | 2018-03-09 13:15:36 +0100 | [diff] [blame^] | 101 | get_filename_component(_TARGET_BASE_NAME ${_MY_PARAMS_TARGET} NAME_WE) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 102 | get_directory_property(_ADDITIONAL_MAKE_CLEAN_FILES DIRECTORY "./" ADDITIONAL_MAKE_CLEAN_FILES) |
| 103 | set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_ADDITIONAL_MAKE_CLEAN_FILES} ${_TARGET_BASE_NAME}.map") |
| 104 | endfunction() |
| 105 | |
| 106 | function(compiler_set_cmse_output TARGET FILE_PATH) |
| 107 | #Note: the space before the option is important! |
| 108 | set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --import_cmse_lib_out=${FILE_PATH}") |
| 109 | #Tell cmake cmse output is a generated object file. |
| 110 | SET_SOURCE_FILES_PROPERTIES("${FILE_PATH}" PROPERTIES EXTERNAL_OBJECT true GENERATED true) |
| 111 | #Tell cmake cmse output shall be removed by clean target. |
| 112 | get_directory_property(_ADDITIONAL_MAKE_CLEAN_FILES DIRECTORY "./" ADDITIONAL_MAKE_CLEAN_FILES) |
| 113 | set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_ADDITIONAL_MAKE_CLEAN_FILES} ${FILE_PATH}") |
| 114 | endfunction() |
| 115 | |
| 116 | function(compiler_merge_library) |
| 117 | set( _OPTIONS_ARGS ) #Option (on/off) arguments. |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 118 | set( _ONE_VALUE_ARGS DEST) #Single option arguments. |
| 119 | set( _MULTI_VALUE_ARGS LIBS) #List arguments |
| 120 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} ) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 121 | |
| 122 | #Check passed parameters |
| 123 | if(NOT _MY_PARAMS_DEST) |
| 124 | message(FATAL_ERROR "embedded_merge_library: no destination library target specified.") |
| 125 | endif() |
| 126 | #Check if destination is a target |
| 127 | if(NOT TARGET ${_MY_PARAMS_DEST}) |
| 128 | message(FATAL_ERROR "embedded_merge_library: parameter DEST must be a target already defined.") |
| 129 | endif() |
| 130 | #Check if destination is a library |
| 131 | get_target_property(_tmp ${_MY_PARAMS_DEST} TYPE) |
| 132 | if(NOT "${_tmp}" STREQUAL "STATIC_LIBRARY") |
| 133 | message(FATAL_ERROR "embedded_merge_library: parameter DEST must be a static library target.") |
| 134 | endif() |
| 135 | |
| 136 | #Check list if libraries to be merged |
| 137 | if(NOT _MY_PARAMS_LIBS) |
| 138 | message(FATAL_ERROR "embedded_merge_library: no source libraries specified. Please see the LIBS parameter.") |
| 139 | endif() |
| 140 | |
| 141 | #Mark each library file as a generated external object. This is needed to |
| 142 | #avoid error because CMake has no info how these can be built. |
| 143 | SET_SOURCE_FILES_PROPERTIES( |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 144 | ${_MY_PARAMS_LIBS} |
| 145 | PROPERTIES |
| 146 | EXTERNAL_OBJECT true |
| 147 | GENERATED true) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 148 | |
| 149 | #Add additional input to target |
| 150 | target_sources(${_MY_PARAMS_DEST} PRIVATE ${_MY_PARAMS_LIBS}) |
| 151 | endfunction() |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 152 | |
| 153 | function(compiler_generate_binary_output TARGET) |
| 154 | add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_ARMCCLANG_FROMELF} ARGS --bincombined --output=$<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin $<TARGET_FILE:${TARGET}>) |
| 155 | endfunction() |