Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
juanAngel committed Nov 24, 2017
2 parents 568ae06 + 947ffd9 commit caef8de
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Modules/Platform/MicrochipMCU-C-XC32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
# to provide information specific to the XC32 compiler

include(MicrochipPathSearch)

set(_CMAKE_TOOLCHAIN_PREFIX "xc32-")
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)
MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32
CACHE "the path to a Microchip XC32 installation"
STORE_VERSION MICROCHIP_C_COMPILER_VERSION
)
endif()


function(_xc32_get_version)
execute_process(
Expand Down Expand Up @@ -64,6 +69,7 @@ set(CMAKE_FIND_ROOT_PATH ${MICROCHIP_XC32_PATH})
find_program(CMAKE_ASM_COMPILER "xc32-gcc")
find_program(CMAKE_C_COMPILER "xc32-gcc")
find_program(CMAKE_CXX_COMPILER "xc32-g++")

set(MICROCHIP_C_COMPILER_ID XC32)
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 90)
set(CMAKE_CXX_COMPILER_FORCED ON)
Expand Down
46 changes: 46 additions & 0 deletions Modules/Platform/MicrochipMCU-CXX-XC32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#=============================================================================
# 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-CXX`
# to provide information specific to the XC32 compiler

include(MicrochipPathSearch)
if(NOT MICROCHIP_XC32_PATH)
MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32
CACHE "the path to a Microchip XC32 installation"
STORE_VERSION MICROCHIP_CXX_COMPILER_VERSION
)
endif()

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(OS_SUFFIX "")
if(WIN32)
string(APPEND OS_SUFFIX ".exe")
endif()

set(CMAKE_CXX_COMPILER ${MICROCHIP_XC32_PATH}/bin/xc32-g++${OS_SUFFIX} CACHE STRING "" FORCE)
set(MICROCHIP_CXX_COMPILER_ID XC32)

set(CMAKE_CXX_FLAGS "-mprocessor=${MICROCHIP_MCU_MODEL}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "-g" CACHE STRING "" FORCE)
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf" CACHE STRING "" FORCE)
31 changes: 31 additions & 0 deletions Modules/Platform/MicrochipMCU-CXX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#=============================================================================
# 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 loaded during the search for a CXX compiler
# to provide the information necessary to find one.

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_32")
include(Platform/MicrochipMCU-CXX-XC32)
else()
message(FATAL_ERROR
"No CXX compiler for '${CMAKE_SYSTEM_PROCESSOR}'"
" is supported yet."
)
endif()

if(MICROCHIP_CXX_COMPILER_ID)
message(STATUS
"Using Microchip CXX compiler ${MICROCHIP_CXX_COMPILER_ID}"
" ${MICROCHIP_CXX_COMPILER_VERSION}"
)
endif()
18 changes: 18 additions & 0 deletions Modules/Platform/MicrochipMCU-GNU-C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# for XC16, inject properties that may have been missed
# see `Platform/MicrochipMCU-C-XC16` for explanation

if(MICROCHIP_C_COMPILER_ID STREQUAL "XC16")
if(NOT CMAKE_C_COMPILE_FEATURES)
set(CMAKE_C_COMPILE_FEATURES "c_function_prototypes;c_restrict;c_variadic_macros")
Expand All @@ -32,3 +33,20 @@ if(MICROCHIP_C_COMPILER_ID STREQUAL "XC16")
set(CMAKE_C_COMPILER_ABI ELF)
endif()
endif()

if(MICROCHIP_C_COMPILER_ID STREQUAL "XC32")
if(NOT CMAKE_C_COMPILE_FEATURES)
set(CMAKE_C_COMPILE_FEATURES "c_function_prototypes;c_restrict;c_variadic_macros")
set(CMAKE_C90_COMPILE_FEATURES "c_function_prototypes")
set(CMAKE_C99_COMPILE_FEATURES "c_restrict;c_variadic_macros")
set(CMAKE_C11_COMPILE_FEATURES "")
endif()

if(NOT CMAKE_C_SIZEOF_DATA_PTR)
set(CMAKE_C_SIZEOF_DATA_PTR 4)
endif()

if(NOT CMAKE_C_COMPILER_ABI)
set(CMAKE_C_COMPILER_ABI ELF)
endif()
endif()
28 changes: 28 additions & 0 deletions Modules/Platform/MicrochipMCU-GNU-CXX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#=============================================================================
# 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 after the compiler has been determined
# to set up information specific to Microchip GNU CXX compilers

# for XC32, inject properties that may have been missed
# see `Platform/MicrochipMCU-CXX-XC32` for explanation

if(MICROCHIP_CXX_COMPILER_ID STREQUAL "XC32")
if(NOT CMAKE_CXX_SIZEOF_DATA_PTR)
set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
endif()

if(NOT CMAKE_CXX_COMPILER_ABI)
set(CMAKE_CXX_COMPILER_ABI ELF)
endif()
endif()
4 changes: 4 additions & 0 deletions toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,8 @@ if(MICROCHIP_XC32_PATH)
add_compile_options(
${compile_flags}
)
add_compile_options(
"$<$<CONFIG:RELASE>:-DNDEBUG>"
"$<$<CONFIG:DEBUG>:-g>"
)
endif()

0 comments on commit caef8de

Please sign in to comment.