|
| 1 | +#============================================================================= |
| 2 | +# Copyright 2018 Sam Hanes |
| 3 | +# |
| 4 | +# Distributed under the OSI-approved BSD License (the "License"); |
| 5 | +# see accompanying file COPYING.txt for details. |
| 6 | +# |
| 7 | +# This software is distributed WITHOUT ANY WARRANTY; without even the |
| 8 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 9 | +# See the License for more information. |
| 10 | +#============================================================================= |
| 11 | +# (To distribute this file outside of CMake-Microchip, |
| 12 | +# substitute the full License text for the above reference.) |
| 13 | + |
| 14 | +# this module is called by `Platform/MicrochipMCU-C` |
| 15 | +# to provide information specific to the XC8 compiler |
| 16 | + |
| 17 | +include(MicrochipPathSearch) |
| 18 | +MICROCHIP_PATH_SEARCH(MICROCHIP_XC8_PATH xc8 |
| 19 | + CACHE "the path to a Microchip XC8 installation" |
| 20 | +) |
| 21 | + |
| 22 | +if(NOT MICROCHIP_XC8_PATH) |
| 23 | + message(FATAL_ERROR |
| 24 | + "No Microchip XC8 compiler was found. Please provide the path" |
| 25 | + " to an XC8 installation on the command line, for example:\n" |
| 26 | + "cmake -DMICROCHIP_XC8_PATH=/opt/microchip/xc8/v2.00 ." |
| 27 | + ) |
| 28 | +endif() |
| 29 | + |
| 30 | + |
| 31 | +set(CMAKE_FIND_ROOT_PATH ${MICROCHIP_XC8_PATH}) |
| 32 | + |
| 33 | +# skip compiler search and just use XC8 |
| 34 | +find_program(CMAKE_C_COMPILER "xc8") |
| 35 | + |
| 36 | +# skip compiler ID since XC8 isn't supported by CMake's test file |
| 37 | +set(CMAKE_C_COMPILER_ID_RUN 1) |
| 38 | +set(CMAKE_C_COMPILER_ID "XC8") |
| 39 | + |
| 40 | +# call the compiler to check its version |
| 41 | +function(_xc8_get_version) |
| 42 | + execute_process( |
| 43 | + COMMAND "${CMAKE_C_COMPILER}" "--ver" |
| 44 | + OUTPUT_VARIABLE output |
| 45 | + ERROR_VARIABLE output |
| 46 | + RESULT_VARIABLE result |
| 47 | + ) |
| 48 | + |
| 49 | + if(result) |
| 50 | + message(FATAL_ERROR |
| 51 | + "Calling '${CMAKE_C_COMPILER} --ver' failed." |
| 52 | + ) |
| 53 | + endif() |
| 54 | + |
| 55 | + if(output MATCHES "XC8 C Compiler V([0-9]+\.[0-9]+)") |
| 56 | + set(CMAKE_C_COMPILER_VERSION ${CMAKE_MATCH_1} PARENT_SCOPE) |
| 57 | + else() |
| 58 | + message(FATAL_ERROR |
| 59 | + "Failed to parse output of '${CMAKE_C_COMPILER} --ver'." |
| 60 | + ) |
| 61 | + endif() |
| 62 | +endfunction() |
| 63 | +_xc8_get_version() |
0 commit comments