-
Notifications
You must be signed in to change notification settings - Fork 247
/
CMakeLists.txt
207 lines (180 loc) · 6.71 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# use a recent CMake version
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_policy(VERSION 3.13)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
cmake_policy(SET CMP0083 NEW)
endif()
# QPC SDK project root CMakeLists.txt
set(QPC_HOST_PORTS posix win32)
set(QPC_RTOS_PORTS embos esp-idf freertos threadx uc-os2)
set(QPC_BAREMETAL_PORTS arm-cm arm-cr msp430 pic32 risc-v)
set(QPC_MISC_PORTS qep-only qube)
foreach(p in HOST RTOS BAREMETAL MISC)
list(APPEND QPC_ALL_PORTS ${QPC_${p}_PORTS})
endforeach()
# project configuration
if(DEFINED ENV{QPC_CFG_KERNEL} AND (NOT QPC_CFG_KERNEL))
set(QPC_CFG_KERNEL $ENV{QPC_CFG_KERNEL})
message("Using QPC_CFG_KERNEL from environment ('${QPC_CFG_KERNEL}')")
elseif(NOT QPC_CFG_KERNEL)
set(QPC_CFG_KERNEL qv)
message("Set QPC_CFG_KERNEL to ('${QPC_CFG_KERNEL}') since not specified")
endif()
if(DEFINED ENV{QPC_CFG_PORT} AND (NOT QPC_CFG_PORT))
set(QPC_CFG_PORT $ENV{QPC_CFG_PORT})
message("Using QPC_CFG_PORT from environment ('${QPC_CFG_PORT}')")
endif()
if(NOT QPC_CFG_GUI)
set(QPC_CFG_GUI OFF CACHE BOOL "enable GUI support for matching ports (e.g. win32 or posix & GTK)")
message("Set QPC_CFG_GUI to ('${QPC_CFG_GUI}') since not specified")
endif()
if(NOT QPC_CFG_UNIT_TEST)
set(QPC_CFG_UNIT_TEST OFF CACHE BOOL "enable detailled unit testing support")
message("Set QPC_CFG_UNIT_TEST to ('${QPC_CFG_UNIT_TEST}') since not specified")
endif()
if(NOT QPC_CFG_DEBUG)
set(QPC_CFG_DEBUG ON CACHE BOOL "enable debug sessions")
message("Set QPC_CFG_DEBUG to ('${QPC_CFG_DEBUG}') since not specified")
endif()
if(NOT QPC_CFG_VERBOSE)
set(QPC_CFG_VERBOSE OFF CACHE BOOL "enable verbose build output")
message("Set QPC_CFG_VERBOSE to ('${QPC_CFG_VERBOSE}') since not specified")
endif()
project(
qpc
VERSION "1.0.0"
DESCRIPTION "QPC library"
LANGUAGES C ASM
)
# add support for SPY configuration if not set via CMAKE_TOOLCHAIN_FILE
if(NOT CMAKE_C_FLAGS_SPY)
foreach(LANG IN ITEMS C CXX ASM)
set(CMAKE_${LANG}_FLAGS_SPY "${CMAKE_${LANG}_FLAGS_DEBUG} -DQ_SPY")
endforeach()
endif()
# check target port plausibility
if(NOT QPC_CFG_PORT)
message(WARNING "No PORT is configured! Falling back to target system '${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}'.")
if(CMAKE_SYSTEM_NAME)
string(TOLOWER ${CMAKE_SYSTEM_NAME} sysName)
else()
set(sysName generic)
endif()
if(CMAKE_SYSTEM_PROCESSOR)
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} sysProc)
else()
set(sysproc none)
endif()
if((sysName STREQUAL generic) AND (sysProc STREQUAL arm))
set(PORT arm-cm)
elseif(WIN32)
set(PORT win32)
elseif(UNIX)
set(PORT posix)
else()
message(FATAL_ERROR No valid target port could be found. Aborting!)
endif()
else()
string(TOLOWER ${QPC_CFG_PORT} PORT)
endif()
if(NOT (${PORT} IN_LIST QPC_ALL_PORTS))
if(DEFINED PORT)
message(FATAL_ERROR "Target port '${PORT}' not found!")
else()
message(FATAL_ERROR "Target port not defined!")
endif()
endif()
set(QPC_CFG_PORT ${PORT} CACHE STRING "The QPC target port for the system platform")
message(STATUS "Set QPC_CFG_PORT to ('${QPC_CFG_PORT}')")
# check/set Qx real time kernel
string(TOLOWER ${QPC_CFG_KERNEL} KERNEL)
list (APPEND kernList qv qk qxk)
if(NOT (${KERNEL} IN_LIST kernList))
if(QPC_CFG_KERNEL)
message(WARNING "Unknown kernel '${QPC_CFG_KERNEL}' specified!
Falling back to QV kernel")
endif()
set(QPC_CFG_KERNEL QV CACHE STRING "set to ON, if the QV micro kernel shall be configured. Leave OFF for host based configurations. (default: OFF)" FORCE)
set(KERNEL qv)
endif()
unset(kernList)
add_library(qpc STATIC "")
# set position independent code compile/link parameters
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
include(CheckPIESupported)
check_pie_supported()
endif()
set_property(TARGET qpc PROPERTY POSITION_INDEPENDENT_CODE FALSE)
# set up the include directory search path
target_include_directories(qpc PUBLIC
src
include
)
# add subdirectories with source/header files
add_subdirectory(src)
add_subdirectory(ports)
# set general defines
target_compile_definitions(qpc PRIVATE
$<$<BOOL:${ADD_DEBUG_CODE}>:${ADD_DEBUG_CODE}>
$<$<BOOL:${QPC_CFG_GUI}>:QWIN_GUI>
# $<$<CONFIG:Spy>:Q_SPY> # set via toolchain file
$<$<AND:$<CONFIG:Spy>,$<BOOL:${QPC_CFG_UNIT_TEST}>>:Q_UTEST>
)
target_compile_options(qpc PRIVATE
$<$<BOOL:${QPC_CFG_VERBOSE}>:-v>
)
target_link_options(qpc PRIVATE
$<$<BOOL:${QPC_CFG_VERBOSE}>:-v>
)
target_link_libraries(qpc PUBLIC
$<$<AND:$<CONFIG:Spy>,$<STREQUAL:win32,${PORT}>>:ws2_32>
)
# print configuration
message(STATUS
"========================================================
Configured project ${PROJECT_NAME} for ${PORT}
PROJECT_NAME = ${QPC_PROJECT}
TARGET = ${TARGET}
IMAGE = ${IMAGE}
SW_VERSION = ${SW_VERSION}
PORT = ${PORT}
QPC_CFG_GUI = ${QPC_CFG_GUI}
QPC_CFG_UNIT_TEST = ${QPC_CFG_UNIT_TEST}
QPC_CFG_KERNEL = ${QPC_CFG_KERNEL}
QPC_CFG_DEBUG = ${QPC_CFG_DEBUG}
CMAKE_C_CPPCHECK = ${CMAKE_C_CPPCHECK}
-- ========================================================
"
)
if(QPC_CFG_VERBOSE)
message(STATUS
"========================================================
System information:
CMAKE_VERSION = ${CMAKE_VERSION}
CMAKE_CROSSCOMPILING = ${CMAKE_CROSSCOMPILING}
CMAKE_HOST_SYSTEM = ${CMAKE_HOST_SYSTEM}
CMAKE_HOST_SYSTEM_NAME = ${CMAKE_HOST_SYSTEM_NAME}
CMAKE_HOST_LINUX = ${CMAKE_HOST_LINUX}
CMAKE_HOST_UNIX = ${CMAKE_HOST_UNIX}
CMAKE_HOST_WIN32 = ${CMAKE_HOST_WIN32}
CMAKE_SYSTEM = ${CMAKE_SYSTEM}
CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}
CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}
WIN32 = ${WIN32}
MSYS = ${MSYS}
MINGW = ${MINGW}
UNIX = ${UNIX}
LINUX = ${LINUX}
CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}
CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}
CMAKE_C_COMPILER_ID = ${CMAKE_C_COMPILER_ID}
CMAKE_C_COMPILER_VERSION = ${CMAKE_C_COMPILER_VERSION}
CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}
CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}
CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}
CMAKE_ASM_COMPILER = ${CMAKE_ASM_COMPILER}
CMAKE_ASM_FLAGS = ${CMAKE_ASM_FLAGS}
-- ========================================================
"
)
endif()