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 | #Find the location of the ARMClang C/C++ compiler. |
| 9 | # |
| 10 | # Find armclang on the specified location or on the PATH and optionally validate its version. |
| 11 | # |
| 12 | #Inputs: |
| 13 | # ARMCLANG_PATH - (optional)- install path of armclang compiler to use. If not set the |
| 14 | # compiler on the PATH is used. |
| 15 | # ARMCLANG_VER - (optional)- version number. If set the module will validate the compiler version. |
| 16 | # |
| 17 | #outputs: |
| 18 | # ARMCLANG_PATH - will be set to the root directory of the compiler. Only set if undefined. |
| 19 | # ARMCLANG_VER - will be set to the version number found. Only set if undefined. |
| 20 | # ARMCLANG_MODULE - set to the name of the cmake module to be included for this ARMClang version. |
| 21 | # |
| 22 | |
| 23 | #Include some dependencies |
| 24 | Include(Common/Utils) |
| 25 | |
| 26 | #Get the version of armasm. |
| 27 | # |
| 28 | # Execute armasm and extract its version number for its output. |
| 29 | # |
| 30 | #Exmaples: |
| 31 | # Get the version reported by armasm at location c:/foo/bin/armasm to variable VER |
| 32 | # get_armasm_version(ARMASM "c:/foo/bin/armasm" RES VER) |
| 33 | # |
| 34 | #INPUTS: |
| 35 | # ARMASM - (mandatory) - armasm executable |
| 36 | # RES - (mandatory) - variable name to put result to |
| 37 | # |
| 38 | #OUTPUTS |
| 39 | # The variable named after "RES" will be set to the version number matches |
| 40 | # |
| 41 | function(get_armasm_version) |
| 42 | #Parse our arguments |
| 43 | set( _OPTIONS_ARGS ) #No option (on/off) arguments (e.g. IGNORE_CASE) |
| 44 | set( _ONE_VALUE_ARGS ARMASM RES) #Single option arguments (e.g. PATH "./foo/bar") |
| 45 | set( _MULTI_VALUE_ARGS ) #One list argument (e.g. LANGUAGES C ASM CXX) |
| 46 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} ) |
| 47 | |
| 48 | #Check mandatory parameters |
| 49 | if(NOT _MY_PARAMS_RES) |
| 50 | message (FATAL_ERROR "get_armasm_version(): Missing result parameter!") |
| 51 | endif() |
| 52 | set (_RES ${_MY_PARAMS_RES}) |
| 53 | |
| 54 | if(NOT _MY_PARAMS_ARMASM) |
| 55 | message (FATAL_ERROR "get_armasm_version(): Missing ARMASM parameter!") |
| 56 | endif() |
| 57 | set (_ARMASM ${_MY_PARAMS_ARMASM}) |
| 58 | |
| 59 | #Call specified executable |
| 60 | execute_process(COMMAND "${_ARMASM}" |
| 61 | OUTPUT_VARIABLE _OUTPUT |
| 62 | ERROR_VARIABLE _OUTPUT |
| 63 | ) |
| 64 | #Cut off version number. Just the numbers ignore anything after. |
| 65 | STRING(REGEX REPLACE ".*ARM Compiler (([0-9]+\.)+[0-9]+).*" "\\1" _VER "${_OUTPUT}") |
| 66 | |
| 67 | if (NOT _VER) |
| 68 | message (FATAL_ERROR "get_armasm_version(): Failed to extract version number from armasm output.") |
| 69 | endif() |
| 70 | |
| 71 | set(${_RES} ${_VER} PARENT_SCOPE) |
| 72 | endfunction() |
| 73 | |
| 74 | #If the install location needs to be found. |
| 75 | if(NOT DEFINED ARMCLANG_PATH) |
| 76 | #Set ARMCLANG_PATH to default value. |
| 77 | set (ARMCLANG_PATH "ARMCLANG_PATH-NOTFOUND") |
| 78 | |
| 79 | #First check if armclang is on the PATH |
| 80 | #find_program puts() its output to the cmake cache. We don't want that, so we use a local variable, which |
| 81 | #is unset later. |
| 82 | find_program ( |
| 83 | _ARMCLANG_PATH |
| 84 | armclang |
| 85 | PATHS env PATH |
| 86 | DOC "ARMCLANG compiler location." |
| 87 | ) |
| 88 | |
| 89 | #Yes, check the version number if it is specified. |
| 90 | if(_ARMCLANG_PATH STREQUAL "_ARMCLANG_PATH-NOTFOUND") |
| 91 | message (FATAL_ERROR "armclang install location is unset. Either put armclang on the PATH or set ARMCLANG_PATH.") |
| 92 | endif() |
| 93 | |
| 94 | #Cut off executable name directory name to get install location. |
| 95 | STRING(REGEX REPLACE "(.*)/bin/armclang.*" "\\1" ARMCLANG_PATH "${_ARMCLANG_PATH}") |
| 96 | |
| 97 | #Remove unwanted junk from CMake cache. |
| 98 | unset(_ARMCLANG_PATH CACHE) |
| 99 | endif() |
| 100 | |
| 101 | get_armasm_version(ARMASM "${ARMCLANG_PATH}/bin/armasm" RES _VER) |
| 102 | |
| 103 | #Check the version if needed |
| 104 | if(NOT DEFINED ARMCLANG_VER) |
| 105 | set(ARMCLANG_VER ${_VER}) |
| 106 | endif() |
| 107 | |
| 108 | if(NOT "${ARMCLANG_VER}" VERSION_EQUAL "${_VER}") |
| 109 | message (FATAL_ERROR "FindArmClang.cmake: armclang compiler version ${_VER} does not match ${ARMCLANG_VER}.") |
| 110 | endif() |
| 111 | |
| 112 | STRING(REGEX REPLACE "([0-9]+)\.([0-9]+)(\.[0-9]+)*.*" "CompilerArmClang\\1\\2" ARMCLANG_MODULE "${ARMCLANG_VER}") |
| 113 | |
Mate Toth-Pal | 48fc6a0 | 2018-01-24 09:50:14 +0100 | [diff] [blame] | 114 | if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${ARMCLANG_MODULE}.cmake") |
| 115 | message(FATAL_ERROR "ERROR: Unsupported ARMCLANG compiler version found on PATH.") |
| 116 | endif() |