Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XC32 C++ working on Windows. #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Modules/Compiler/XC8-C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# called by `CMakeCInformation`
# to configure the XC8 compiler interface for C files
# this supports the `xc8` CLI driver in XC8 1.x
# and the equivalent legacy CLI driver in XC8 2.x


set(MICROCHIP_XC8_MODE "free"
Expand All @@ -28,7 +30,10 @@ string(APPEND CMAKE_C_FLAGS_INIT
" --chip=${MICROCHIP_MCU_MODEL}"
)


set(CMAKE_C_OUTPUT_EXTENSION ".p1")
set(CMAKE_STATIC_LIBRARY_SUFFIX_C ".lpp")


set(CMAKE_C_COMPILE_OBJECT)
string(APPEND CMAKE_C_COMPILE_OBJECT
Expand All @@ -42,3 +47,10 @@ string(APPEND CMAKE_C_LINK_EXECUTABLE
" <OBJECTS> <LINK_LIBRARIES>"
" -o<TARGET>"
)

set(CMAKE_C_CREATE_STATIC_LIBRARY)
string(APPEND CMAKE_C_CREATE_STATIC_LIBRARY
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> <LINK_LIBRARIES>"
" --output=lpp -o<TARGET>"
)
45 changes: 45 additions & 0 deletions Modules/Compiler/XC8CC-C.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#=============================================================================
# Copyright 2019 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.)

# called by `CMakeCInformation`
# to configure the XC8CC compiler interface for C files
# this supports the xc8-cc CLI driver from XC8 v2.x


string(APPEND CMAKE_C_FLAGS_INIT
# build for the configured MCU model
" -mcpu=${MICROCHIP_MCU_MODEL}"
# fail if the requested optimization level is forbidden by the license
" --nofallback"
)

set(CMAKE_C_OUTPUT_EXTENSION ".p1")

set(CMAKE_C_COMPILE_OBJECT)
string(APPEND CMAKE_C_COMPILE_OBJECT
"<CMAKE_C_COMPILER> <FLAGS> <DEFINES> <INCLUDES>"
" -o <OBJECT> -c <SOURCE>"
)

set(CMAKE_C_LINK_EXECUTABLE)
string(APPEND CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> <LINK_LIBRARIES>"
" -o <TARGET>"
)

set(CMAKE_C_CREATE_STATIC_LIBRARY)
string(APPEND CMAKE_C_CREATE_STATIC_LIBRARY
"<CMAKE_AR> -r <TARGET>"
" <OBJECTS> <LINK_LIBRARIES>"
)
28 changes: 17 additions & 11 deletions Modules/Platform/MicrochipMCU-C-XC32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# 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)
MICROCHIP_PATH_SEARCH(MICROCHIP_XC32_PATH xc32
CACHE "the path to a Microchip XC32 installation"
STORE_VERSION MICROCHIP_C_COMPILER_VERSION
)
endif()

if(NOT MICROCHIP_XC32_PATH)
message(FATAL_ERROR
Expand All @@ -30,12 +32,16 @@ endif()

set(CMAKE_FIND_ROOT_PATH ${MICROCHIP_XC32_PATH})

set(CMAKE_C_COMPILER xc32-gcc)
set(OS_SUFFIX "")
if(WIN32)
string(APPEND OS_SUFFIX ".exe")
endif()

set(CMAKE_C_COMPILER ${MICROCHIP_XC32_PATH}/bin/xc32-gcc${OS_SUFFIX} CACHE STRING "" FORCE)
set(CMAKE_BIN2HEX ${MICROCHIP_XC32_PATH}/bin/xc32-bin2hex${OS_SUFFIX} CACHE STRING "" FORCE)
set(MICROCHIP_C_COMPILER_ID XC32)

add_compile_options(
"-mprocessor=${MICROCHIP_MCU_MODEL}"
)
string(APPEND CMAKE_C_LINK_FLAGS
" -mprocessor=${MICROCHIP_MCU_MODEL}"
)
set(CMAKE_C_FLAGS "-mprocessor=${MICROCHIP_MCU_MODEL}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG "-g" CACHE STRING "" FORCE)
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf" CACHE STRING "" FORCE)
70 changes: 59 additions & 11 deletions Modules/Platform/MicrochipMCU-C-XC8.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,68 @@ if(NOT MICROCHIP_XC8_PATH)
)
endif()


set(CMAKE_FIND_ROOT_PATH "${MICROCHIP_XC8_PATH}")

# skip compiler search and just use XC8
find_program(CMAKE_C_COMPILER "xc8"
PATHS "${MICROCHIP_XC8_PATH}"
PATH_SUFFIXES "bin"

if(NOT MICROCHIP_XC8_CLI)
set(MICROCHIP_XC8_CLI "xc8-cc")
set(_xc8_cli_default TRUE CACHE INTERNAL "" FORCE)
endif()
set(MICROCHIP_XC8_CLI "${MICROCHIP_XC8_CLI}"
CACHE STRING "the XC8 CLI driver to use ('xc8-cc' or 'xc8')"
)


if(MICROCHIP_XC8_CLI STREQUAL "xc8-cc")
find_program(CMAKE_C_COMPILER "xc8-cc"
PATHS "${MICROCHIP_XC8_PATH}"
PATH_SUFFIXES "bin"
)
find_program(CMAKE_AR "xc8-ar"
PATHS "${MICROCHIP_XC8_PATH}"
PATH_SUFFIXES "bin"
)
set(_xc8_version_flag "--version")
set(CMAKE_C_COMPILER_ID "XC8CC")
elseif(MICROCHIP_XC8_CLI STREQUAL "xc8")
find_program(CMAKE_C_COMPILER "xc8"
PATHS "${MICROCHIP_XC8_PATH}"
PATH_SUFFIXES "bin"
)
set(_xc8_version_flag "--ver")
set(CMAKE_C_COMPILER_ID "XC8")
else()
message(FATAL_ERROR
"Invalid choice '${MICROCHIP_XC8_CLI}' for MICROCHIP_XC8_CLI."
" Please choose either 'xc8-cc' (recommended) or 'xc8'."
" See docs/xc8.md in your cmake-microchip installation for"
" details on this option."
)
endif()


if(NOT CMAKE_C_COMPILER)
if(_xc8_cli_default)
message(WARNING
"The XC8 command-line driver was not explicitly selected,"
" so the newer 'xc8-cc' driver is being used. This requires"
" XC8 version 2.00 or newer. If you want to use older versions"
" of XC8, or if you want to use the legacy 'xc8' driver in XC8"
" 2.00 or newer, add this line to your CMakeLists.txt before"
" the 'project' command:\n"
" set(MICROCHIP_XC8_CLI xc8)\n"
"To suppress this message when XC8 is not found but continue"
" using the newer 'xc8-cc' driver, add this line to your"
" CMakeLists.txt before the 'project' command:\n"
" set(MICROCHIP_XC8_CLI xc8-cc)\n"
"For more information on selecting a command-line driver"
" see docs/xc8.md in your cmake-microchip installation."
)
endif()

message(FATAL_ERROR
"The XC8 compiler executable was not found, but what looks"
" like an XC8 installation was found at:\n"
"The XC8 compiler executable ${MICROCHIP_XC8_CLI} was not found,"
" but what looks like an XC8 installation was found at:\n"
" ${MICROCHIP_XC8_PATH}\n"
"Please provide the path to a working XC8 installation on the"
" command line, for example:\n"
Expand All @@ -49,28 +98,27 @@ endif()

# skip compiler ID since XC8 isn't supported by CMake's test file
set(CMAKE_C_COMPILER_ID_RUN 1)
set(CMAKE_C_COMPILER_ID "XC8")

# call the compiler to check its version
function(_xc8_get_version)
execute_process(
COMMAND "${CMAKE_C_COMPILER}" "--ver"
COMMAND "${CMAKE_C_COMPILER}" "${_xc8_version_flag}"
OUTPUT_VARIABLE output
ERROR_VARIABLE output
RESULT_VARIABLE result
)

if(result)
message(FATAL_ERROR
"Calling '${CMAKE_C_COMPILER} --ver' failed."
"Calling '${CMAKE_C_COMPILER} ${_xc8_version_flag}' failed."
)
endif()

if(output MATCHES "XC8 C Compiler V([0-9]+\.[0-9]+)")
set(CMAKE_C_COMPILER_VERSION ${CMAKE_MATCH_1} PARENT_SCOPE)
else()
message(FATAL_ERROR
"Failed to parse output of '${CMAKE_C_COMPILER} --ver'."
"Failed to parse output of '${CMAKE_C_COMPILER} ${_xc8_version_flag}'."
)
endif()
endfunction()
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()
Loading