Skip to content

Commit c20f61a

Browse files
committed
2 parents 568ae06 + 947ffd9 commit c20f61a

6 files changed

+137
-4
lines changed

Modules/Platform/MicrochipMCU-C-XC32.cmake

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
# to provide information specific to the XC32 compiler
1616

1717
include(MicrochipPathSearch)
18+
1819
set(_CMAKE_TOOLCHAIN_PREFIX "xc32-")
19-
MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32
20-
CACHE "the path to a Microchip XC32 installation"
21-
STORE_VERSION MICROCHIP_C_COMPILER_VERSION
22-
)
20+
21+
if(NOT MICROCHIP_XC32_PATH)
22+
MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32
23+
CACHE "the path to a Microchip XC32 installation"
24+
STORE_VERSION MICROCHIP_C_COMPILER_VERSION
25+
)
26+
endif()
27+
2328

2429
function(_xc32_get_version)
2530
execute_process(
@@ -64,6 +69,7 @@ set(CMAKE_FIND_ROOT_PATH ${MICROCHIP_XC32_PATH})
6469
find_program(CMAKE_ASM_COMPILER "xc32-gcc")
6570
find_program(CMAKE_C_COMPILER "xc32-gcc")
6671
find_program(CMAKE_CXX_COMPILER "xc32-g++")
72+
6773
set(MICROCHIP_C_COMPILER_ID XC32)
6874
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 90)
6975
set(CMAKE_CXX_COMPILER_FORCED ON)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#=============================================================================
2+
# Copyright 2016 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-CXX`
15+
# to provide information specific to the XC32 compiler
16+
17+
include(MicrochipPathSearch)
18+
if(NOT MICROCHIP_XC32_PATH)
19+
MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32
20+
CACHE "the path to a Microchip XC32 installation"
21+
STORE_VERSION MICROCHIP_CXX_COMPILER_VERSION
22+
)
23+
endif()
24+
25+
if(NOT MICROCHIP_XC32_PATH)
26+
message(FATAL_ERROR
27+
"No Microchip XC32 compiler was found. Please provide the path"
28+
" to an XC32 installation on the command line, for example:\n"
29+
"cmake -DMICROCHIP_XC32_PATH=/opt/microchip/xc32/v1.42 ."
30+
)
31+
endif()
32+
33+
set(CMAKE_FIND_ROOT_PATH ${MICROCHIP_XC32_PATH})
34+
35+
set(OS_SUFFIX "")
36+
if(WIN32)
37+
string(APPEND OS_SUFFIX ".exe")
38+
endif()
39+
40+
set(CMAKE_CXX_COMPILER ${MICROCHIP_XC32_PATH}/bin/xc32-g++${OS_SUFFIX} CACHE STRING "" FORCE)
41+
set(MICROCHIP_CXX_COMPILER_ID XC32)
42+
43+
set(CMAKE_CXX_FLAGS "-mprocessor=${MICROCHIP_MCU_MODEL}" CACHE STRING "" FORCE)
44+
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG" CACHE STRING "" FORCE)
45+
set(CMAKE_CXX_FLAGS_DEBUG "-g" CACHE STRING "" FORCE)
46+
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf" CACHE STRING "" FORCE)
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#=============================================================================
2+
# Copyright 2016 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 loaded during the search for a CXX compiler
15+
# to provide the information necessary to find one.
16+
17+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_32")
18+
include(Platform/MicrochipMCU-CXX-XC32)
19+
else()
20+
message(FATAL_ERROR
21+
"No CXX compiler for '${CMAKE_SYSTEM_PROCESSOR}'"
22+
" is supported yet."
23+
)
24+
endif()
25+
26+
if(MICROCHIP_CXX_COMPILER_ID)
27+
message(STATUS
28+
"Using Microchip CXX compiler ${MICROCHIP_CXX_COMPILER_ID}"
29+
" ${MICROCHIP_CXX_COMPILER_VERSION}"
30+
)
31+
endif()

Modules/Platform/MicrochipMCU-GNU-C.cmake

+18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# for XC16, inject properties that may have been missed
1818
# see `Platform/MicrochipMCU-C-XC16` for explanation
19+
1920
if(MICROCHIP_C_COMPILER_ID STREQUAL "XC16")
2021
if(NOT CMAKE_C_COMPILE_FEATURES)
2122
set(CMAKE_C_COMPILE_FEATURES "c_function_prototypes;c_restrict;c_variadic_macros")
@@ -32,3 +33,20 @@ if(MICROCHIP_C_COMPILER_ID STREQUAL "XC16")
3233
set(CMAKE_C_COMPILER_ABI ELF)
3334
endif()
3435
endif()
36+
37+
if(MICROCHIP_C_COMPILER_ID STREQUAL "XC32")
38+
if(NOT CMAKE_C_COMPILE_FEATURES)
39+
set(CMAKE_C_COMPILE_FEATURES "c_function_prototypes;c_restrict;c_variadic_macros")
40+
set(CMAKE_C90_COMPILE_FEATURES "c_function_prototypes")
41+
set(CMAKE_C99_COMPILE_FEATURES "c_restrict;c_variadic_macros")
42+
set(CMAKE_C11_COMPILE_FEATURES "")
43+
endif()
44+
45+
if(NOT CMAKE_C_SIZEOF_DATA_PTR)
46+
set(CMAKE_C_SIZEOF_DATA_PTR 4)
47+
endif()
48+
49+
if(NOT CMAKE_C_COMPILER_ABI)
50+
set(CMAKE_C_COMPILER_ABI ELF)
51+
endif()
52+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#=============================================================================
2+
# Copyright 2016 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 after the compiler has been determined
15+
# to set up information specific to Microchip GNU CXX compilers
16+
17+
# for XC32, inject properties that may have been missed
18+
# see `Platform/MicrochipMCU-CXX-XC32` for explanation
19+
20+
if(MICROCHIP_CXX_COMPILER_ID STREQUAL "XC32")
21+
if(NOT CMAKE_CXX_SIZEOF_DATA_PTR)
22+
set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
23+
endif()
24+
25+
if(NOT CMAKE_CXX_COMPILER_ABI)
26+
set(CMAKE_CXX_COMPILER_ABI ELF)
27+
endif()
28+
endif()

toolchain.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,8 @@ if(MICROCHIP_XC32_PATH)
167167
add_compile_options(
168168
${compile_flags}
169169
)
170+
add_compile_options(
171+
"$<$<CONFIG:RELASE>:-DNDEBUG>"
172+
"$<$<CONFIG:DEBUG>:-g>"
173+
)
170174
endif()

0 commit comments

Comments
 (0)