setup cmake for avr
This commit is contained in:
38
CMakeLists.txt
Normal file
38
CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
# Project name and version
|
||||
project(tool_probe VERSION 1.0)
|
||||
|
||||
|
||||
# enable_language(C ASM)
|
||||
|
||||
# toolchain file for AVR
|
||||
# set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/avr-gcc-toolchain.cmake)
|
||||
|
||||
# Set executable name
|
||||
add_executable(${PROJECT_NAME})
|
||||
|
||||
# generate hex file
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND avr-objcopy -O ihex -R .eeprom ${PROJECT_NAME}.elf ${PROJECT_NAME}.hex
|
||||
COMMAND avr-size ${PROJECT_NAME}.elf
|
||||
COMMENT "Generating HEX file"
|
||||
)
|
||||
|
||||
# add custom target for uploading
|
||||
add_custom_target(flash
|
||||
COMMAND avrdude -p ${AVR_MCU} -c ${AVR_PROGRAMMER} -U flash:w:${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.hex:i
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
COMMENT "Uploading HEX file to microcontroller"
|
||||
)
|
||||
|
||||
# Link directories setup
|
||||
target_link_directories(${PROJECT_NAME} PRIVATE
|
||||
src
|
||||
)
|
||||
|
||||
# Add sources to executable
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
src/main.c
|
||||
)
|
||||
Reference in New Issue
Block a user