Skip to content

Commit ffb29d9

Browse files
committed
Add basic support for XC8.
1 parent 2832835 commit ffb29d9

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

Modules/Compiler/XC8-C.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
# called by `CMakeCInformation`
15+
# to configure the XC8 compiler interface for C files
16+
17+
18+
set(MICROCHIP_XC8_MODE "free"
19+
CACHE STRING "the license mode for XC8 (pro, std, free)"
20+
)
21+
22+
string(APPEND CMAKE_C_FLAGS_INIT
23+
# don't output the copyright notice on every invocation
24+
"-Q"
25+
# use the configured license mode and fail if it's not available
26+
" --mode=${MICROCHIP_XC8_MODE} --nofallback"
27+
# build for the configured MCU model
28+
" --chip=${MICROCHIP_MCU_MODEL}"
29+
)
30+
31+
set(CMAKE_C_OUTPUT_EXTENSION ".p1")
32+
33+
set(CMAKE_C_COMPILE_OBJECT)
34+
string(APPEND CMAKE_C_COMPILE_OBJECT
35+
"<CMAKE_C_COMPILER> <FLAGS> <DEFINES> <INCLUDES>"
36+
" -o<OBJECT> --pass1 <SOURCE>"
37+
)
38+
39+
set(CMAKE_C_LINK_EXECUTABLE)
40+
string(APPEND CMAKE_C_LINK_EXECUTABLE
41+
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
42+
" <OBJECTS> <LINK_LIBRARIES>"
43+
" -o<TARGET>"
44+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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()

Modules/Platform/MicrochipMCU-C.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# This module is loaded during the search for a C compiler
1515
# to provide the information necessary to find one.
1616

17-
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_16")
17+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_8")
18+
include(Platform/MicrochipMCU-C-XC8)
19+
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_16")
1820
include(Platform/MicrochipMCU-C-XC16)
1921
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_32")
2022
include(Platform/MicrochipMCU-C-XC32)

0 commit comments

Comments
 (0)