Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2017, Arm Limited. All rights reserved. |
| 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 | |
| 64 | function(compiler_set_linkercmdfile TARGET FILE_PATH) |
| 65 | #Note: the space before the option is important! |
| 66 | set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --scatter=${FILE_PATH}") |
| 67 | set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS ${FILE_PATH}) |
| 68 | #Tell cmake .map files shall be removed when project is cleaned (make clean) |
| 69 | get_filename_component(_TARGET_BASE_NAME ${TARGET} NAME_WE) |
| 70 | get_directory_property(_ADDITIONAL_MAKE_CLEAN_FILES DIRECTORY "./" ADDITIONAL_MAKE_CLEAN_FILES) |
| 71 | set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_ADDITIONAL_MAKE_CLEAN_FILES} ${_TARGET_BASE_NAME}.map") |
| 72 | endfunction() |
| 73 | |
| 74 | function(compiler_set_cmse_output TARGET FILE_PATH) |
| 75 | #Note: the space before the option is important! |
| 76 | set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --import_cmse_lib_out=${FILE_PATH}") |
| 77 | #Tell cmake cmse output is a generated object file. |
| 78 | SET_SOURCE_FILES_PROPERTIES("${FILE_PATH}" PROPERTIES EXTERNAL_OBJECT true GENERATED true) |
| 79 | #Tell cmake cmse output shall be removed by clean target. |
| 80 | get_directory_property(_ADDITIONAL_MAKE_CLEAN_FILES DIRECTORY "./" ADDITIONAL_MAKE_CLEAN_FILES) |
| 81 | set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_ADDITIONAL_MAKE_CLEAN_FILES} ${FILE_PATH}") |
| 82 | endfunction() |
| 83 | |
| 84 | function(compiler_merge_library) |
| 85 | set( _OPTIONS_ARGS ) #Option (on/off) arguments. |
| 86 | set( _ONE_VALUE_ARGS DEST) #Single option arguments. |
| 87 | set( _MULTI_VALUE_ARGS LIBS) #List arguments |
| 88 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} ) |
| 89 | |
| 90 | #Check passed parameters |
| 91 | if(NOT _MY_PARAMS_DEST) |
| 92 | message(FATAL_ERROR "embedded_merge_library: no destination library target specified.") |
| 93 | endif() |
| 94 | #Check if destination is a target |
| 95 | if(NOT TARGET ${_MY_PARAMS_DEST}) |
| 96 | message(FATAL_ERROR "embedded_merge_library: parameter DEST must be a target already defined.") |
| 97 | endif() |
| 98 | #Check if destination is a library |
| 99 | get_target_property(_tmp ${_MY_PARAMS_DEST} TYPE) |
| 100 | if(NOT "${_tmp}" STREQUAL "STATIC_LIBRARY") |
| 101 | message(FATAL_ERROR "embedded_merge_library: parameter DEST must be a static library target.") |
| 102 | endif() |
| 103 | |
| 104 | #Check list if libraries to be merged |
| 105 | if(NOT _MY_PARAMS_LIBS) |
| 106 | message(FATAL_ERROR "embedded_merge_library: no source libraries specified. Please see the LIBS parameter.") |
| 107 | endif() |
| 108 | |
| 109 | #Mark each library file as a generated external object. This is needed to |
| 110 | #avoid error because CMake has no info how these can be built. |
| 111 | SET_SOURCE_FILES_PROPERTIES( |
| 112 | ${_MY_PARAMS_LIBS} |
| 113 | PROPERTIES |
| 114 | EXTERNAL_OBJECT true |
| 115 | GENERATED true) |
| 116 | |
| 117 | #Add additional input to target |
| 118 | target_sources(${_MY_PARAMS_DEST} PRIVATE ${_MY_PARAMS_LIBS}) |
| 119 | endfunction() |