-
Notifications
You must be signed in to change notification settings - Fork 21
/
CMakeLists.txt
75 lines (61 loc) · 2.91 KB
/
CMakeLists.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
# Set helper variables
set(OUT_DIR out)
set(TOOLCHAIN_DIR toolchain)
# Set extension for final binary and output directory
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/${OUT_DIR}/${TYPE}/)
# Set default build type to "debug"
if(NOT DEFINED TYPE)
set(TYPE debug)
ENDIF()
# Create the final executable 'firmware.elf'
add_executable(${CMAKE_PROJECT_NAME})
if(DEFINED ENV{FW_VERSION})
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC FW_VERSION=\"$ENV{FW_VERSION}\")
endif()
if(DEFINED ENV{GIT_VERSION})
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC GIT_VERSION=\"$ENV{GIT_VERSION}\")
endif()
string(TIMESTAMP BUILD_DATE "%Y-%m-%d %H:%M:%S" UTC)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC BUILD_DATE=\"${BUILD_DATE}\")
IF(DEFINED ENV{BAND})
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC BAND=$ENV{BAND})
ELSE()
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC BAND=868)
ENDIF()
# Add debug CFLAGS
if(TYPE MATCHES "debug")
target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC -g3)
target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC -Og)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC DEBUG)
ENDIF()
# Add release CFLAGS
if(TYPE MATCHES "release")
target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC -Os)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC RELEASE)
ENDIF()
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -T${CMAKE_CURRENT_SOURCE_DIR}/sys/lkr/stm32l083cz.ld)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,-Map=${CMAKE_SOURCE_DIR}/${OUT_DIR}/${TYPE}/${CMAKE_PROJECT_NAME}.map)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -mcpu=cortex-m0plus)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -mthumb)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -mlittle-endian)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,-lm)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,-lc)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -static)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,--gc-sections)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,--print-memory-usage)
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,-u,__errno)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/lib/picolibc/lib/libc.a)
target_link_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/picolibc/lib)
# Disable LOAD segment with RWX permissions warning
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -Wl,--no-warn-rwx-segments)
# All other directories with source files
# You need to update the specific CMakeLists files in the respective directories if you want to update the SDK
add_subdirectory(twr)
add_subdirectory(bcl)
add_subdirectory(stm)
add_subdirectory(sys)
add_subdirectory(lib)
# Generate the final "firmware.bin" in "out" directory and root directory
include(${TOOLCHAIN_DIR}/utils.cmake)
generate_object(${CMAKE_PROJECT_NAME} .bin binary)