From ffa84f3112e78f0052c8b4eb885aa518def7c890 Mon Sep 17 00:00:00 2001 From: Sam Hanes Date: Sat, 18 Jun 2016 10:42:24 -0700 Subject: [PATCH] Add tentative support for XC32. This hasn't been tested all the way to a device, but it at least gets as far as invoking the compiler successfully. --- Modules/MicrochipPathSearch.cmake | 9 ++++- Modules/Platform/MicrochipMCU-C-XC32.cmake | 41 ++++++++++++++++++++++ Modules/Platform/MicrochipMCU-C.cmake | 2 ++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Modules/Platform/MicrochipMCU-C-XC32.cmake diff --git a/Modules/MicrochipPathSearch.cmake b/Modules/MicrochipPathSearch.cmake index d3bacc2..0f859e6 100644 --- a/Modules/MicrochipPathSearch.cmake +++ b/Modules/MicrochipPathSearch.cmake @@ -13,7 +13,7 @@ function(MICROCHIP_PATH_SEARCH outvar target) set(options) - list(APPEND oneValueArgs "CACHE") + list(APPEND oneValueArgs CACHE STORE_VERSION) set(multiValueArgs BAD_VERSIONS) cmake_parse_arguments(SEARCH "${options}" "${oneValueArgs}" "${multiValueArgs}" @@ -87,8 +87,10 @@ function(MICROCHIP_PATH_SEARCH outvar target) if(best_good_path) set(result "${best_good_path}") + set(result_version "${best_good_version}") elseif(best_bad_path) set(result "${best_bad_path}") + set(result_version "${best_good_version}") message(WARNING "Version ${best_bad_version} of ${target} is known" @@ -97,6 +99,7 @@ function(MICROCHIP_PATH_SEARCH outvar target) ) else() set(result "${outvar}-NOTFOUND") + set(result_version "${SEARCH_STORE_VERSION}-NOTFOUND") endif() string(APPEND msg @@ -115,4 +118,8 @@ function(MICROCHIP_PATH_SEARCH outvar target) ) endif() set(${outvar} "${result}" PARENT_SCOPE) + + if(SEARCH_STORE_VERSION) + set(${SEARCH_STORE_VERSION} "${result_version}" PARENT_SCOPE) + endif() endfunction() diff --git a/Modules/Platform/MicrochipMCU-C-XC32.cmake b/Modules/Platform/MicrochipMCU-C-XC32.cmake new file mode 100644 index 0000000..9addb1e --- /dev/null +++ b/Modules/Platform/MicrochipMCU-C-XC32.cmake @@ -0,0 +1,41 @@ +#============================================================================= +# Copyright 2016 Sam Hanes +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file COPYING.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake-Microchip, +# substitute the full License text for the above reference.) + +# this module is called by `Platform/MicrochipMCU-C` +# to provide information specific to the XC32 compiler + +include(MicrochipPathSearch) +MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32 + CACHE "the path to a Microchip XC32 installation" + STORE_VERSION MICROCHIP_C_COMPILER_VERSION +) + +if(NOT MICROCHIP_XC32_PATH) + message(FATAL_ERROR + "No Microchip XC32 compiler was found. Please provide the path" + " to an XC32 installation on the command line, for example:\n" + "cmake -DMICROCHIP_XC32_PATH=/opt/microchip/xc32/v1.42 ." + ) +endif() + +set(CMAKE_FIND_ROOT_PATH ${MICROCHIP_XC32_PATH}) + +set(CMAKE_C_COMPILER xc32-gcc) +set(MICROCHIP_C_COMPILER_ID XC32) + +add_compile_options( + "-mprocessor=${MICROCHIP_MCU_MODEL}" +) +string(APPEND CMAKE_C_LINK_FLAGS + " -mprocessor=${MICROCHIP_MCU_MODEL}" +) diff --git a/Modules/Platform/MicrochipMCU-C.cmake b/Modules/Platform/MicrochipMCU-C.cmake index e2d1259..ee07691 100644 --- a/Modules/Platform/MicrochipMCU-C.cmake +++ b/Modules/Platform/MicrochipMCU-C.cmake @@ -16,6 +16,8 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_16") include(Platform/MicrochipMCU-C-XC16) +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_32") + include(Platform/MicrochipMCU-C-XC32) else() message(FATAL_ERROR "No C compiler for '${CMAKE_SYSTEM_PROCESSOR}'"