-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists_link_with_static_lib.txt
79 lines (65 loc) · 2.37 KB
/
CMakeLists_link_with_static_lib.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##########################################################
#
# Created: 26-Dec-2022
# Author: Goce Boshkovski
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# Example CMakeLists.txt file for linking the binary with a static
# library for both GNU avr-gcc and Microchip XC8 compiler.
#
##########################################################
cmake_minimum_required(VERSION 3.1)
# Define the project name
project(DS18S20example1)
# Show the compiler commands during the build
set(CMAKE_VERBOSE_MAKEFILE ON)
# Define the variables/command line arguments for target MCU and MCU clock frequency
if (NOT MICROCHIP_XC8_COMPILER)
set(MCU "atmega32" CACHE STRING "Target micro-controller with default value atmega32")
else()
set(MCU ${AVR8_MCU} CACHE STRING "Target micro-controller with default value set to AVR8_MCU from toolchain file")
endif()
set(CPU_FREQ "16000000L" CACHE STRING "MCU CPU frequency")
# Define the extra include directories here
include_directories(/usr/local/include/avr8)
# Add library path
link_directories(/usr/local/lib/avr8/${MCU})
if (NOT MICROCHIP_XC8_COMPILER)
# Define linker options
add_link_options(-mmcu=${MCU} -Wl,-Map=${PROJECT_NAME}.map)
# Add mmcu as compiler option
add_compile_options(-mmcu=${MCU})
else()
# Microchip XC8 compiler
# Do not append -mmcu to linker options, aready done in toolchain file
add_link_options(-Wl,-Map=${PROJECT_NAME}.map)
endif()
# Define the F_CPU macro required for some avr-libc functions
add_definitions(-DF_CPU=${CPU_FREQ})
# Define the list of source files.
set (SOURCE_LIST
DS18S20example1.c
UART.c
)
# Define the binary
add_executable(${PROJECT_NAME}.elf ${SOURCE_LIST})
# Link the binary with the static library libDS18S20.a
target_link_libraries(${PROJECT_NAME}.elf DS18S20)
# Post build step for generating the firware in Intel HEX format
if (NOT MICROCHIP_XC8_COMPILER)
add_custom_command(
TARGET ${PROJECT_NAME}.elf
POST_BUILD
COMMAND avr-objcopy -j .text -j .data -O ihex ${PROJECT_NAME}.elf ${PROJECT_NAME}.hex
)
else()
# Object copy tool distributed with Microchip XC8
add_custom_command(
TARGET ${PROJECT_NAME}.elf
POST_BUILD
COMMAND ${OBJ_COPY_TOOL} -j .text -j .dat -O ihex ${PROJECT_NAME}.elf ${PROJECT_NAME}.hex
)
endif()