CMake toolchain for PIC microcontroller (with XC8 C Compiler)
You can use this toolchain by some ways:
- Configure project only for PIC (always use toolchain when build project)
- Configure project for cross-platform software (use toolchain only if build for PIC)
This repository depends on MPLAB X IDE and MPLAB XC8 Compiler.
If you always want to use XC8 toolchain, please insert following lines into CMakeLists.txt
.
NOTE: Please insert them before project()
statement!
# fetch and enable PIC XC8 toolchain
include(FetchContent)
FetchContent_Declare(
xc8_toolchain
GIT_REPOSITORY https://github.com/Enchan1207/cmake-xc8
GIT_TAG v1
)
FetchContent_Populate(xc8_toolchain)
set(CMAKE_TOOLCHAIN_FILE "${xc8_toolchain_SOURCE_DIR}/cmake/xc8_toolchain.cmake")
If your project is developed as cross-platform software, add --toolchain=
options to cmake when configure.
cmake .. --toolchain=/path/to/xc8_toolchain.cmake
It can be able to build your project for PIC without making any changes to CMakeLists.txt
.
This toolchain provides custom macros named target_configure_for_pic()
. It can use like this:
add_executable(main)
target_sources(main PRIVATE
main.cpp
)
# If your project is not only for PIC,
# please check if BUILD_FOR_PIC is defined and its value is `true`
if(${BUILD_FOR_PIC})
target_configure_for_pic(main)
endif()
This macro adds the following custom targets and commands to your target:
- Flash target:
Custom target namedflash-{target_name}
for flashing. If you execute this target, built programms will be flashed to microcontroller byipecmd.jar
(command-line tool included in MPLAB IPE).
You can specify some options to cmake-xc8. These can be checked and edited using ccmake, cmake-gui or command-line options.
- Environment options:
XC8_INSTALL_DIR
: Optional
Root path of XC8 compiler. If you installed XC8 to custom directory, you need to set this.MPLABX_INSTALL_DIR
: Optional
Root path of MPLAB X IDE. If you installed IPE to custom directory, you need to set this.
- Compiler options:
PIC_MCU
: Required
The identifier of target microcontroller.PIC_FCPU
: Required
The clock frequency of target microcontroller.
- Programmer options:
IPE_TOOL
: Optional
Flash tool identifier. If you want to use PICKit 3, specifyPPK3
.
This repository is published under MIT License.