-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
85 lines (72 loc) · 3.58 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
76
77
78
79
80
81
82
83
84
85
cmake_minimum_required(VERSION 3.6)
include(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME "Generic")
SET(CMAKE_SYSTEM_VERSION 1)
if (UNIX)
set(TOOLCHAIN_DIR "/usr/bin")
# set(TOOLCHAIN_DIR "/opt/gcc-arm-none-eabi-6-2017-q1-update/bin/")
# set(CMAKE_C_COMPILER "/opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc")
# set(CMAKE_CXX_COMPILER "/opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-g++")
CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++ GNU)
else ()
set(TOOLCHAIN_DIR "D:/Programy/GNU Tools ARM Embedded/5.4 2016q3/bin")
CMAKE_FORCE_C_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-gcc.exe GNU)
CMAKE_FORCE_CXX_COMPILER(${TOOLCHAIN_DIR}/arm-none-eabi-g++.exe GNU)
endif ()
project(RS41OGN C CXX)
add_definitions(-DSTM32F100C8)
add_definitions(-DSTM32F10X_MD_VL)
add_definitions(-DUSE_STDPERIPH_DRIVER)
add_definitions(-DSUPPORT_CPLUSPLUS)
add_definitions(-D__ASSEMBLY__)
add_definitions(-DWITH_STM32)
SET(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/arm-gcc-link.ld)
SET(COMMON_FLAGS " -mcpu=cortex-m3 -mthumb -Wall -Wno-misleading-indentation -fno-exceptions -ffunction-sections -fdata-sections -g -Os -nostartfiles ")
# SET(COMMON_FLAGS " -mcpu=cortex-m3 -mthumb -Wall -Wno-misleading-indentation -fno-exceptions -ffunction-sections -g -Os -nostartfiles ")
SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-Map=${CMAKE_BINARY_DIR}/${PROJECT_NAME}.map -lstdc++ -O3 -Wl,--gc-sections --specs=nano.specs -T ${LINKER_SCRIPT}")
include_directories(
${PROJECT_SOURCE_DIR}/cmsis
${PROJECT_SOURCE_DIR}/cmsis_boot
${PROJECT_SOURCE_DIR}/stm_lib/inc
${PROJECT_SOURCE_DIR}/FreeRTOS_9.0.0/Source/include
${PROJECT_SOURCE_DIR}/FreeRTOS_9.0.0/Source/portable/GCC/ARM_CM3
${PROJECT_SOURCE_DIR}
)
file(GLOB USER_SOURCES
${PROJECT_SOURCE_DIR}/*.c
${PROJECT_SOURCE_DIR}/*.cpp
${PROJECT_SOURCE_DIR}/cmsis/*.h
${PROJECT_SOURCE_DIR}/cmsis_boot/*.h
${PROJECT_SOURCE_DIR}/cmsis_boot/*.c
${PROJECT_SOURCE_DIR}/cmsis_boot/startup/*.c
${PROJECT_SOURCE_DIR}/stm_lib/src/*.c
${PROJECT_SOURCE_DIR}/stm_lib/inc/*.h
${PROJECT_SOURCE_DIR}/FreeRTOS_9.0.0/Source/*.c
${PROJECT_SOURCE_DIR}/FreeRTOS_9.0.0/Source/portable/GCC/ARM_CM3/*.c
${PROJECT_SOURCE_DIR}/FreeRTOS_9.0.0/Source/portable/MemMang/heap_4.c
${PROJECT_SOURCE_DIR}/*.h
)
# file(GLOB_RECURSE USER_SOURCES "*.c")
# file(GLOB_RECURSE USER_SOURCES_CXX "*.cpp")
# file(GLOB_RECURSE USER_HEADERS "*.h")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${USER_SOURCES_CXX} ${USER_HEADERS} ${HAL_SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${CMAKE_BINARY_DIR}/${PROJECT_NAME}.map")
set(HEX_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}"
COMMAND ${TOOLCHAIN_DIR}/arm-none-eabi-size ${PROJECT_NAME}.elf)
set(CMAKE_CXX_STANDARD 11)
add_custom_target(upload
DEPENDS ${PROJECT_NAME}.elf
if (UNIX)
COMMAND sudo st-flash --reset --format ihex write ${HEX_FILE}
else ()
COMMAND D:/Programy/stlink-1.3.0-win64/bin/st-flash --reset write ${BIN_FILE} 0x08000000
endif ()
COMMENT "flashing ${BIN_FILE}")