-
Notifications
You must be signed in to change notification settings - Fork 0
/
stm32f4discovery.cmake
75 lines (63 loc) · 2.78 KB
/
stm32f4discovery.cmake
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
#################################################
# lib opencm3
set(OPENCM3DIR libopencm3)
set(OPENCM3LIB opencm3_stm32f4)
set(OPENCM3BUILD stm32/f4)
set(LIBOPENCM3_COMMIT b1d8a4c5)
add_custom_target(buildlibopencm3 DEPENDS ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/Makefile ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/lib/lib${OPENCM3LIB}.a)
# clone libopencm3
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/Makefile
COMMAND rm -rf ${OPENCM3DIR}
message(STATUS "### runn git submodule update --init --recursive")
COMMAND git submodule update --init --recursive; true
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
# build libopencm3
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/lib/lib${OPENCM3LIB}.a
COMMAND make -C ${OPENCM3DIR} TARGETS=${OPENCM3BUILD}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
add_library(libopencm3 STATIC IMPORTED GLOBAL)
add_dependencies(libopencm3 buildlibopencm3)
set_target_properties(libopencm3 PROPERTIES
IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/lib/lib${OPENCM3LIB}.a
# INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/include
)
set(LIBOPENCM3_INCLUDE ${PROJECT_SOURCE_DIR}/${OPENCM3DIR}/include)
######################################################
set(USE_QEMU False CACHE STRING "Use qemu emulator for M4 target. It doesn't affect other tatgets")
if("${toolchain}" STREQUAL "arm-none-eabi-libopencm3")
if(USE_QEMU)
add_compile_options(-DUSE_QEMU)
set(RUNTEST bash ${PROJECT_SOURCE_DIR}/tests/run_test.sh -v -h 1 -b )
else()
set(RUNTEST bash ${PROJECT_SOURCE_DIR}/tests/run_test.sh -v -b )
endif()
add_compile_options(-DSTM32F4)
add_link_options(-L${PROJECT_SOURCE_DIR}/libopencm3/lib)
add_link_options(-T${PROJECT_SOURCE_DIR}/hw/stm32f405x6.ld)
include_directories(${LIBOPENCM3_INCLUDE})
link_libraries(libopencm3)
add_library(hal_lib OBJECT ${PROJECT_SOURCE_DIR}/hw/hal-stm32f4.c ${PROJECT_SOURCE_DIR}/hw/syscall_wrappers.c)
# disable cppcheck and clang-tidy for hal-stm32f4.c
set_target_properties(hal_lib PROPERTIES C_CPPCHECK "" C_CLANG_TIDY "")
link_libraries(hal_lib)
set(EXT .bin)
endif()
#add_executeble with additional objcopy step when needed
macro(add_custom_exe)
add_executable(${ARGV})
target_compile_definitions(${ARGV0} PRIVATE TARGET_NAME="${ARGV0}")
if("${EXT}" STREQUAL ".bin" AND (NOT KEEP_ELF)) ## add objcopy command
add_custom_command(
TARGET ${ARGV0} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary ${ARGV0} ${ARGV0}
DEPENDS ${ARGV0})
endif()
endmacro()
include_directories(${PROJECT_SOURCE_DIR}/hw)
add_library(test_randomlib STATIC ${PROJECT_SOURCE_DIR}/hw/hw_randombytes.c)
link_libraries(test_randomlib)
add_compile_definitions(USERDTSC)