-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
238 lines (199 loc) · 8.08 KB
/
CMakeLists.txt
File metadata and controls
238 lines (199 loc) · 8.08 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# ***************************************************************************
# * Copyright 2015 Michael Eischer, Philipp Nordhus *
# * Robotics Erlangen e.V. *
# * http://www.robotics-erlangen.de/ *
# * info@robotics-erlangen.de *
# * *
# * This program is free software: you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation, either version 3 of the License, or *
# * any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program. If not, see <http://www.gnu.org/licenses/>. *
# ***************************************************************************
cmake_minimum_required(VERSION 3.13.0)
project(erforce)
enable_testing()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#
# Options
#
option(BUILD_FIRMWARE "Whether to build the firmware. Downloads GCC and ChibiOS" OFF)
option(DOWNLOAD_V8 "Whether to download a prebuilt V8 version. If disabled, V8 must be built locally to enable Typescript support" OFF)
option(TRACKING_DEBUG "Whether to enable tracking debug mode (extra data written to plotter and debug tree)" OFF)
option(PATHFINDING_DEBUG "Whether to enable pathfinding debug mode (extra data written to plotter and debug tree)" OFF)
option(EASY_MODE "Whether to enable easy mode (changes to Ra for first time users)" OFF)
#
# System queries
#
if(MINGW)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(MINGW32 TRUE)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MINGW64 TRUE)
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMAKE_SYSTEM_PROCESSOR uses uname -m on linux and these are all the possible values for arm64
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8b" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8l")
set(ARM64 TRUE)
else()
set(ARM64 FALSE)
endif()
#
# Policies
#
if (POLICY CMP0071)
cmake_policy(SET CMP0071 NEW)
endif()
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
if (POLICY CMP0114)
cmake_policy(SET CMP0114 OLD)
endif()
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++20 HAVE_CPP20)
if (NOT HAVE_CPP20)
message(FATAL_ERROR "Your compiler does not understand -std=c++20, consider updating your compiler")
endif()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED YES)
SET(CMAKE_CXX_EXTENSIONS ON)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
message(STATUS "No toolchain file specified, using system compiler")
# We pass the CMAKE_TOOLCHAIN_FILE to ExternalProjects. If we did not set
# it manually (because we use the system compiler), we get warnings due to
# undefined variables.
set(CMAKE_TOOLCHAIN_FILE)
endif()
if(MINGW)
find_program(WINDRES_EXECUTABLE NAMES windres)
set(CMAKE_RC_COMPILER_INIT ${WINDRES_EXECUTABLE})
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> \"-I${CMAKE_SOURCE_DIR}/data/pkg\" -i <SOURCE> -o <OBJECT>")
# make sure MinGW doesn't screw up packing the radiocommands
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields")
# sse floats are already the default for x64
if(MINGW32)
# use sse floats, not the insane x87 fpu where intermediate values
# may have up to 80bit precision, instead of the expected 32bit for floats
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse")
endif()
endif(MINGW)
if(APPLE)
# the option "S" prevents execution of ranlib
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Sqc <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Sqc <TARGET> <LINK_FLAGS> <OBJECTS>")
# silence ranlib "has no symbols"-warning
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols <TARGET>")
endif()
# Find cross compilers
macro(find_cross_compiler VARIABLE NAME)
find_program(${VARIABLE} NAMES ${NAME})
mark_as_advanced(${VARIABLE})
if("${ARGN}" STREQUAL "REQUIRED")
if(NOT ${VARIABLE})
message("${NAME} not found, some targets will not be available.")
endif()
endif()
endmacro(find_cross_compiler)
find_cross_compiler(ARM_C_CROSS_COMPILER arm-none-eabi-gcc REQUIRED)
find_cross_compiler(ARM_CXX_CROSS_COMPILER arm-none-eabi-g++)
if(NOT ARM_C_CROSS_COMPILER)
message(STATUS "No suitable cross compiler found, firmware will be unavailable")
set(BUILD_FIRMWARE FALSE CACHE BOOL "Build the firmware" FORCE)
else()
set(BUILD_FIRMWARE TRUE CACHE BOOL "Build the firmware")
endif()
# downloads
add_custom_target(download)
include(EnvHelper)
find_package(OpenGL REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
include(BuildProtobuf)
# Try to auto-locate Qt5 on MacOS (won't work with custom installs)
# TODO change this to qt6 and hope nothing explodes
if (APPLE)
if (EXISTS /usr/local/opt/qt@5)
set(Qt5_DIR "/usr/local/opt/qt@5/lib/cmake/Qt5")
elseif(EXISTS /usr/local/opt/qt5)
set(Qt5_DIR "/usr/local/opt/qt5/lib/cmake/Qt5")
else()
message(FATAL_ERROR "Could not find Qt5. Please install with `brew install qt@5`.")
endif()
endif()
set(CMAKE_AUTOMOC ON)
find_package(Qt6 COMPONENTS Core Widgets OpenGLWidgets Network OpenGL Gui REQUIRED)
find_package(Qt6 COMPONENTS Svg)
if (NOT TARGET Qt6::Svg)
message(STATUS "Qt svg component not found. Svg screenshots will not be supported.")
endif()
# Qt6 depends on Freetype which depends on bzip2 and for some reason, when cross compiling bzip is not added to the link arguments
if(CMAKE_CROSSCOMPILING)
find_package(BZip2 REQUIRED)
target_link_libraries(Qt6::Core INTERFACE BZip2::BZip2)
endif()
if(UNIX AND NOT APPLE)
# file open dialogs crash on mac
# memory corruption with crash on windows
find_package(Jemalloc)
endif()
find_package(USB)
set(DEPENDENCY_DOWNLOADS "${CMAKE_BINARY_DIR}/dependencies")
if(MINGW AND NOT TARGET lib::usb)
include(BuildUSB)
endif()
# sdl2 version 2.0.2 required for loading controller mappings from config file
find_package(SDL2 2.0.2)
if (SDL2_FOUND)
if (CMAKE_CROSS_COMPILING)
add_library(lib::sdl2 ALIAS SDL2::SDL2-static)
else()
add_library(lib::sdl2 ALIAS SDL2::SDL2)
endif()
else()
include(BuildSDL2)
endif()
include(BuildBullet)
include(BuildEigen)
include(BuildSourceMap)
include(BuildLibGit2)
include(BuildLuaJIT2)
include(BuildGoogleTest)
include(GetGameController)
find_package(V8 10.5.7)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(src)
if(UNIX AND NOT APPLE)
configure_file(data/pkg/ra.desktop.in ra.desktop)
configure_file(data/pkg/ra-logplayer.desktop.in ra-logplayer.desktop)
add_custom_target(install-menu
COMMAND xdg-desktop-menu install --novendor ${CMAKE_BINARY_DIR}/ra.desktop ${CMAKE_BINARY_DIR}/ra-logplayer.desktop
COMMENT "Installing menu entries" VERBATIM
)
endif()
include(AddLanguageServices)
if(MINGW)
include(CollectWindows)
endif()