stm32f303.cmake 2.09 KB
Newer Older
Mikaël BRIDAY's avatar
init  
Mikaël BRIDAY committed
1
# define CPU OPTIONS
2
3
set(CPU_OPTIONS -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32F303x8 -DARMCM4)
#set(CPU_OPTIONS -mthumb -mcpu=cortex-m4 -mfloat-abi=soft -DSTM32F303x8 -DARMCM4)
Mikaël BRIDAY's avatar
init  
Mikaël BRIDAY committed
4

5
6
7
8
set(CMAKE_C_FLAGS_DEBUG   "-O0 -Wno-deprecated -Werror -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wno-deprecated -Werror -DDEBUG")
set(CMAKE_C_FLAGS_RELEASE   "-O3") #remove the -Werror => pb with Adafruit lib.
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
Mikaël BRIDAY's avatar
init  
Mikaël BRIDAY committed
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

#compiler options
add_compile_options(
    ${CPU_OPTIONS}
	$<$<COMPILE_LANGUAGE:C>:-std=c11>
	$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>          #CMSYS do not support C++17
    $<$<COMPILE_LANGUAGE:CXX>:-fms-extensions>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
    $<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>
	#$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast>   #Adafruit
	#$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override> #GFX does not support it
    $<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>
    -fstrict-volatile-bitfields
    -ffunction-sections
    -Wall
    -Wextra
    -Wcast-align
	#-Wconversion
    #-Wsign-conversion
    -Wshadow
    -Wlogical-op
    -Wsuggest-final-types
    -Wsuggest-final-methods
    #-pedantic
35
36
    -fexceptions
    -g
Mikaël BRIDAY's avatar
init  
Mikaël BRIDAY committed
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
)

include_directories(
    ${CMSIS_DIR}/Device/ST/STM32F3xx/Include
    ${CMSIS_DIR}/Include
)

set(SYSTEMSRCS
    ${SYS_DIR}/startup_ARMCM4.c
    ${SYS_DIR}/startup_clock.c
)

#executable (should be after compile options)
add_executable(${PROJECT_NAME} ${APP_SRCS} ${SYSTEMSRCS})

# select linker script
set(LINKER_DIR ${SYS_DIR})
set(LINKER_SCRIPT "stm32f303K8.ld")
set(LINKER_FLAGS 
	-Wl,--start-group -lm  -Wl,--end-group -Wl,--gc-sections
	-Lsys
	-lstdc++_nano
	-Xlinker -Map=${PROJECT_NAME}.map
)

#should be defined after 'add_executable'
target_link_libraries(${PROJECT_NAME}
	${CPU_OPTIONS}
	-T${LINKER_DIR}/${LINKER_SCRIPT}
	${LINKER_FLAGS}
    m
    #-nostartfiles
    #-nostdlib
)

set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_DEPENDS ${LINKER_DIR}/${LINKER_SCRIPT})

#flashing rules
include("../sys/cmake/flash.cmake")