-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
179 lines (158 loc) · 8.48 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
cmake_minimum_required (VERSION 3.14)
if(DEFINED STLIB_NAME_SUFFIX)
project (ST-LIB-${STLIB_NAME_SUFFIX} C CXX)
set(STLIB_LIBRARY st-lib-${STLIB_NAME_SUFFIX})
else()
project (ST-LIB C CXX)
set(STLIB_LIBRARY st-lib)
endif()
if (NOT PROJECT_IS_TOP_LEVEL)
set(STLIB_LIBRARY ${STLIB_LIBRARY} PARENT_SCOPE)
endif()
option(USE_ETHERNET "Enable ethernet peripheral" OFF)
option(TARGET_NUCLEO "Targets the STM32H723 Nucleo development board" OFF)
message(STATUS "${PROJECT_NAME} Ethernet: ${USE_ETHERNET}")
message(STATUS "${PROJECT_NAME} Nucleo: ${TARGET_NUCLEO}")
if ((PROJECT_IS_TOP_LEVEL AND (NOT CMAKE_CROSSCOMPILING)))
include(FetchContent)
option(BUILD_GMOCK OFF)
option(INSTALL_GTEST OFF)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
)
FetchContent_MakeAvailable(googletest)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest_main)
endif()
if (NOT CMAKE_CROSSCOMPILING)
add_subdirectory(Tests)
endif()
# This should be an explicit list of files, but there are just too many files :(
file(GLOB_RECURSE HEADER_DRIVER ${CMAKE_CURRENT_LIST_DIR}/Drivers/*.h )
file(GLOB_RECURSE SOURCE_DRIVER ${CMAKE_CURRENT_LIST_DIR}/Drivers/*.c )
file(GLOB_RECURSE HEADER_MIDDLEWARE ${CMAKE_CURRENT_LIST_DIR}/Middlewares/*.h)
file(GLOB_RECURSE SOURCE_MIDDLEWARE ${CMAKE_CURRENT_LIST_DIR}/Middlewares/*.c)
file(GLOB_RECURSE HEADER_LWIP ${CMAKE_CURRENT_LIST_DIR}/LWIP/*.h)
file(GLOB_RECURSE SOURCE_LWIP ${CMAKE_CURRENT_LIST_DIR}/LWIP/*.c)
# CPP UTILITIES
file(GLOB_RECURSE CPP_UTILITIES_H ${CMAKE_CURRENT_LIST_DIR}/Inc/C++Utilities/*.h)
file(GLOB_RECURSE CPP_UTILITIES_HPP ${CMAKE_CURRENT_LIST_DIR}/Inc/C++Utilities/*.hpp)
file(GLOB_RECURSE CPP_UTILITIES_C ${CMAKE_CURRENT_LIST_DIR}/Src/C++Utilities/*.c)
file(GLOB_RECURSE CPP_UTILITIES_CPP ${CMAKE_CURRENT_LIST_DIR}/Src/C++Utilities/*.cpp)
# HALAL (and Mock)
file(GLOB_RECURSE HALAL_H ${CMAKE_CURRENT_LIST_DIR}/Inc/HALAL/*.h)
file(GLOB_RECURSE HALAL_MOCK_H ${CMAKE_CURRENT_LIST_DIR}/Inc/HALALMock/*.h)
list(REMOVE_ITEM HALAL_H ${HALAL_MOCK_H})
file(GLOB_RECURSE HALAL_HPP ${CMAKE_CURRENT_LIST_DIR}/Inc/HALAL/*.hpp)
file(GLOB_RECURSE HALAL_MOCK_HPP ${CMAKE_CURRENT_LIST_DIR}/Inc/HALALMock/*.hpp)
list(REMOVE_ITEM HALAL_HPP ${HALAL_MOCK_HPP})
file(GLOB_RECURSE HALAL_C ${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/*.c)
file(GLOB_RECURSE HALAL_MOCK_C ${CMAKE_CURRENT_LIST_DIR}/Src/HALALMock/*.c)
list(REMOVE_ITEM HALAL_C ${HALAL_MOCK_C})
file(GLOB_RECURSE HALAL_CPP ${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/*.cpp)
file(GLOB_RECURSE HALAL_MOCK_CPP ${CMAKE_CURRENT_LIST_DIR}/Src/HALALMock/*.cpp)
list(REMOVE_ITEM HALAL_CPP ${HALAL_MOCK_CPP})
# STLIB_LOW
file(GLOB_RECURSE STLIB_LOW_H ${CMAKE_CURRENT_LIST_DIR}/Inc/ST-LIB_LOW/*.h)
file(GLOB_RECURSE STLIB_LOW_HPP ${CMAKE_CURRENT_LIST_DIR}/Inc/ST-LIB_LOW/*.hpp)
file(GLOB_RECURSE STLIB_LOW_C ${CMAKE_CURRENT_LIST_DIR}/Src/ST-LIB_LOW/*.c)
file(GLOB_RECURSE STLIB_LOW_CPP ${CMAKE_CURRENT_LIST_DIR}/Src/ST-LIB_LOW/*.cpp)
# STLIB_HIGH
file(GLOB_RECURSE STLIB_HIGH_H ${CMAKE_CURRENT_LIST_DIR}/Inc/ST-LIB_HIGH/*.h)
file(GLOB_RECURSE STLIB_HIGH_HPP ${CMAKE_CURRENT_LIST_DIR}/Inc/ST-LIB_HIGH/*.hpp)
file(GLOB_RECURSE STLIB_HIGH_C ${CMAKE_CURRENT_LIST_DIR}/Src/ST-LIB_HIGH/*.c)
file(GLOB_RECURSE STLIB_HIGH_CPP ${CMAKE_CURRENT_LIST_DIR}/Src/ST-LIB_HIGH/*.cpp)
add_library(${STLIB_LIBRARY} STATIC
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${HEADER_DRIVER}>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${HEADER_MIDDLEWARE}>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${HEADER_LWIP}>
${CPP_UTILITIES_H}
$<IF:$<BOOL:${CMAKE_CROSSCOMPILING}>,${HALAL_H},${HALAL_MOCK_H}>
${STLIB_LOW_H}
${STLIB_HIGH_H}
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${SOURCE_DRIVER}>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${SOURCE_MIDDLEWARE}>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${SOURCE_LWIP}>
${CPP_UTILITIES_C}
$<IF:$<BOOL:${CMAKE_CROSSCOMPILING}>,${HALAL_C},${HALAL_MOCK_C}>
${STLIB_LOW_C}
${STLIB_HIGH_C}
${CPP_UTILITIES_HPP}
$<IF:$<BOOL:${CMAKE_CROSSCOMPILING}>,${HALAL_HPP},${HALAL_MOCK_HPP}>
${CMAKE_CURRENT_LIST_DIR}/Inc/HALAL/HALAL.hpp
${STLIB_LOW_HPP}
${STLIB_HIGH_HPP}
${CPP_UTILITIES_CPP}
$<IF:$<BOOL:${CMAKE_CROSSCOMPILING}>,${HALAL_CPP},${HALAL_MOCK_CPP}>
${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/HALAL.cpp
${STLIB_LOW_CPP}
${STLIB_HIGH_CPP}
${CMAKE_CURRENT_LIST_DIR}/Src/ST-LIB.cpp
)
set_target_properties(${STLIB_LIBRARY} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED C_STANDARD 11 C_STANDARD_REQUIRED)
target_compile_definitions(${STLIB_LIBRARY} PRIVATE
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:USE_HAL_DRIVER>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:STM32H723xx>
$<$<NOT:$<BOOL:${CMAKE_CROSSCOMPILING}>>:SIM_ON>
$<$<BOOL:${USE_ETHERNET}>:STLIB_ETH>
$<IF:$<BOOL:${TARGET_NUCLEO}>,NUCLEO,BOARD>
$<IF:$<BOOL:${TARGET_NUCLEO}>,HSE_VALUE=8000000,HSE_VALUE=25000000>
)
target_compile_options(${STLIB_LIBRARY} PRIVATE
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-mcpu=cortex-m7>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-mfpu=fpv5-d16>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-mfloat-abi=hard>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-mthumb>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-specs=nosys.specs>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-ffunction-sections>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-fdata-sections>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:-fno-exceptions>
-Wno-psabi
$<$<COMPILE_LANGUAGE:C>:-w>
$<$<COMPILE_LANGUAGE:CXX>:-Wall>
$<$<COMPILE_LANGUAGE:CXX>:-Wpedantic>
$<$<COMPILE_LANGUAGE:CXX>:-Werror>
$<$<COMPILE_LANGUAGE:CXX>:-Wno-gnu-zero-variadic-macro-arguments>
$<$<COMPILE_LANGUAGE:CXX>:-Wno-inconsistent-missing-override>
$<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
$<$<COMPILE_LANGUAGE:CXX>:-Wno-address-of-packed-member> # Add this line
)
target_include_directories(${STLIB_LIBRARY} PRIVATE
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Drivers/CMSIS/Device/ST/STM32H7xx/Include>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Drivers/CMSIS/Include>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/system>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/netif/ppp>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/lwip>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/lwip/apps>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/lwip/priv>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/lwip/prot>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/netif>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/compat>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix/net>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix/sys>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/stdc>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Middlewares/Third_Party/LwIP/system/arch>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Drivers/BSP/Components>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/Drivers/BSP/Components/lan8742>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/LWIP/App>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${CMAKE_CURRENT_LIST_DIR}/LWIP/Target>
${CMAKE_CURRENT_LIST_DIR}/Inc
${CMAKE_CURRENT_LIST_DIR}/Inc/ST-LIB_LOW
${CMAKE_CURRENT_LIST_DIR}/Inc/ST-LIB_HIGH
)
if (PROJECT_IS_TOP_LEVEL)
# Create symlink to compile_commands.json for IDE to pick it up
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
)
endif()