-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
107 lines (93 loc) · 4.6 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
SET(PROJECT_NAME project) # set it to your project name
IF(NOT DEFINED MATRIXMCU)
SET(MATRIXMCU ${CMAKE_CURRENT_SOURCE_DIR}/../..) # set it to your default path to MatrixMCU directory
MESSAGE(STATUS "No path to MatrixMCU directory selected, using default (${MATRIXMCU}). You can override it by passing -DMATRIXMCU=<MATRIXMCU> to cmake")
ENDIF()
IF(NOT DEFINED USE_FSM)
SET(USE_FSM true) # set it to true to use FSM library by default
MESSAGE(STATUS "No FSM library usage selected, using default (${USE_FSM}). You can override it by passing -DUSE_FSM=<use_fsm> to cmake")
ENDIF()
IF(NOT DEFINED USE_HAL)
SET(USE_HAL true) # set it to true to use HAL library by default
MESSAGE(STATUS "No HAL library usage selected, using default (${USE_HAL}). You can override it by passing -DUSE_HAL=<use_hal> to cmake")
ENDIF()
IF(NOT DEFINED PLATFORM)
SET(PLATFORM "stm32f446re") # PORTABILITY: change this to your platform
MESSAGE(STATUS "No platform selected, using default (${PLATFORM}). You can override it by passing -DPLATFORM=<platform> to cmake")
ENDIF()
IF(NOT DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug) # set it to your default build type
MESSAGE(STATUS "No build type selected, using default (${CMAKE_BUILD_TYPE}). You can override it by passing -DCMAKE_BUILD_TYPE=<build_type> to cmake")
ENDIF()
########################################################################################
## IF YOU DON'T KNOW WHAT YOU ARE DOING, DO **NOT** EDIT THIS FILE FROM THIS POINT ON ##
########################################################################################
# Load platform-specific setup configuration (e.g., toolchain and libraries)
INCLUDE(${MATRIXMCU}/CMakeLists.txt)
# CMake project configuration
CMAKE_MINIMUM_REQUIRED(VERSION 3.24)
PROJECT(${PROJECT_NAME} C ASM)
SET(CMAKE_C_STANDARD 11)
# Add platform-agnostic flags
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter")
# Build type-specific flags
SET(CMAKE_C_FLAGS_DEBUG "-g -O0")
SET(CMAKE_C_FLAGS_RELEASE "-O3")
# Set output directory for binaries
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/${PLATFORM}/${CMAKE_BUILD_TYPE})
# Find source and include files of the project
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/common) # load project library configuration (common)
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/port) # load project library configuration (port)
FILE(GLOB PROJECT_SOURCES ${PROJECT_SOURCES}) # project library source files
IF(DEFINED PROJECT_ISR_SOURCES)
FILE(GLOB PROJECT_ISR_SOURCES ${PROJECT_ISR_SOURCES}) # project library ISR source files
ENDIF()
IF(VERBOSE)
MESSAGE(STATUS "Found include directories: ${PROJECT_INCLUDE_DIRS}")
MESSAGE(STATUS "Found source files: ${PROJECT_SOURCES}")
MESSAGE(STATUS "Found ISR source files: ${PROJECT_ISR_SOURCES}")
ENDIF()
# Create project library
ADD_LIBRARY(${PROJECT_NAME} STATIC)
TARGET_SOURCES(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDE_DIRS})
# link FSM library to project library (if applies)
IF(USE_FSM)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} fsm)
ENDIF()
# link project library to all targets
LINK_LIBRARIES(${PROJECT_NAME})
# Rules to build main executable
FILE(GLOB PROJECT_MAIN ${CMAKE_CURRENT_SOURCE_DIR}/main.c) # main routine
ADD_EXECUTABLE(main ${PROJECT_MAIN} ${PROJECT_ISR_SOURCES})
IF(DEFINED PLATFORM_EXTENSION)
SET_TARGET_PROPERTIES(main PROPERTIES SUFFIX ${PLATFORM_EXTENSION})
ENDIF()
FILE(GLOB LCD_MAIN ${CMAKE_CURRENT_SOURCE_DIR}/LCDmain.c) # main routine
ADD_EXECUTABLE(LCDmain ${LCD_MAIN} ${PROJECT_ISR_SOURCES})
IF(DEFINED PLATFORM_EXTENSION)
SET_TARGET_PROPERTIES(LCDmain PROPERTIES SUFFIX ${PLATFORM_EXTENSION})
ENDIF()
FILE(GLOB V2_LCD_MAIN ${CMAKE_CURRENT_SOURCE_DIR}/mainLCDexample.c) # main routine
ADD_EXECUTABLE(mainLCDexample ${V2_LCD_MAIN} ${PROJECT_ISR_SOURCES})
IF(DEFINED PLATFORM_EXTENSION)
SET_TARGET_PROPERTIES(mainLCDexample PROPERTIES SUFFIX ${PLATFORM_EXTENSION})
ENDIF()
# Rules to run (native) or flash (OpenOCD) main executable
IF(PLATFORM STREQUAL "native")
ADD_CUSTOM_TARGET(run-main
DEPENDS main
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/main${PLATFORM_EXTENSION}
COMMENT "Running main")
ELSEIF(DEFINED OPENOCD_CONFIG_FILE)
ADD_CUSTOM_TARGET(flash-main
DEPENDS main
COMMAND ${OPENOCD_EXECUTABLE} -f ${OPENOCD_CONFIG_FILE} -c "program ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/main${PLATFORM_EXTENSION} verify reset exit"
COMMENT "Flashing main")
ENDIF()
# Add tests
IF(PLATFORM STREQUAL "native")
INCLUDE(CTest)
ENABLE_TESTING()
ENDIF()
ADD_SUBDIRECTORY(test)