forked from MishkaRogachev/JAGCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
194 lines (157 loc) · 4.64 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
# CMake version string
cmake_minimum_required(VERSION 3.0)
# Project
set(PROJECT jagcs)
project(${PROJECT})
# CMake modules
include(cmake/RecurseSubdirs.cmake)
# Versions
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
set(VERSION_PATCH 1)
# Get git revision hash
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get version from git
add_definitions(-DVERSION_MAJOR=${VERSION_MAJOR})
add_definitions(-DVERSION_MINOR=${VERSION_MINOR})
add_definitions(-DVERSION_PATCH=${VERSION_PATCH})
add_definitions(-DGIT_REVISION="${GIT_REVISION}")
# Minimum Qt version
set(QT_REQUIRED_VERSION 5.9.0)
# Set default output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/result)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/result)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Add compiler flags
set(CMAKE_CXX_STANDARD 11)
add_compile_options(-Wall -fPIC)
# Enable globaly some Qt modules
find_package(Qt5 COMPONENTS
Core
Network
SerialPort
Sql
Svg
Gui
Quick
LinguistTools
Multimedia
Positioning
Location
Charts
QuickControls2
Gamepad
REQUIRED)
# Common libraries
set(LIBRARIES
)
# Windows stuff
if (WIN32)
set(LIBRARIES
${LIBRARIES}
opengl32
)
# RC compiler
string(REPLACE "gcc" "windres" CMAKE_RC_COMPILER_INIT ${CMAKE_C_COMPILER})
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff -o <OBJECT> <SOURCE> -I ${CMAKE_SOURCE_DIR}/platforms/windows/")
configure_file(${CMAKE_SOURCE_DIR}/platforms/windows/jagcs.rc.in ${CMAKE_CURRENT_BINARY_DIR}/jagcs.rc)
set(META_SOURCES jagcs.rc)
endif(WIN32)
# Android stuff
if (ANDROID)
find_package(Qt5AndroidExtras)
set(LIBS
${LIBS}
Qt5::AndroidExtras
android
# TODO: add to 3rd party openssl android library, avoid https://bugreports.qt.io/browse/QTBUG-57922
)
endif(ANDROID)
# Common includes
include_directories("3rdparty/mavlink_v2")
include_directories("3rdparty/mavlink_v2/ardupilotmega")
# Internal sources
add_subdirectory(sources)
# NOTE: temporary solution for Q_NAMESPACE
# qt5_generate_moc(sources/domain/types/modes.h ${MOC_SOURCES})
qt5_wrap_cpp(MOC_SOURCES sources/domain/types/modes.h)
# Application sources
add_subdirectory(app)
# Translations
file(GLOB TS_FILES "translations/*.ts")
# Qt5 add translation sourses from translation files
qt5_add_translation(QM_FILES ${TS_FILES})
# Create translations QRC file
set(TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/jagcs_ts.qrc")
file(WRITE ${TRANSLATIONS_QRC} "<RCC>\n\t<qresource prefix=\"/\">")
foreach(QM_FILE ${QM_FILES})
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
file(APPEND ${TRANSLATIONS_QRC} "\n\t\t<file alias=\"${QM_FILE_NAME}\">${QM_FILE_NAME}</file>")
endforeach()
file(APPEND ${TRANSLATIONS_QRC} "\n\t</qresource>\n</RCC>")
list(APPEND QRC_FILES ${TRANSLATIONS_QRC})
# Resources
file(GLOB_RECURSE QRC_FILES "*.qrc")
# Qt5 add resources
qt5_add_resources(QRC_SOURCES ${QRC_FILES})
include_directories(${INCLUDES})
# Target
if(ANDROID)
include_directories(${ANDROID_SYSROOT}/usr/include)
add_library(${PROJECT} SHARED ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${META_SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION
${VERSION_MAJOR} "." ${VERSION_MINOR} "." ${VERSION_PATCH})
else(ANDROID)
add_executable(${PROJECT} ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${META_SOURCES})
endif()
# Link Libraries
target_link_libraries (${PROJECT} ${LIBRARIES})
# Use qt5 modules
qt5_use_modules(${PROJECT}
Core
Network
SerialPort
Sql
Svg
Gui
Quick
Multimedia
Positioning
Location
Charts
QuickControls2
Gamepad
)
if(ANDROID)
set (QT_ANDROID_APP_NAME ${PROJECT_NAME})
include(3rdparty/qt-android-cmake/AddQtAndroidApk.cmake)
add_qt_android_apk(${PROJECT_NAME}_apk.
${PROJECT_NAME}
NAME "JAGCS"
PACKAGE_NAME "mishkarogachev.jagcs"
PACKAGE_SOURCES ${CMAKE_SOURCE_DIR}/platforms/android
BUILDTOOLS_REVISION "23.0.3"
VERSION_CODE 5
)
endif()
# CPack Debian package
option(WITH_DEBIAN "Include instructions to make Debian package")
if (WITH_DEBIAN)
# https://cmake.org/Bug/view.php?id=14444
install(TARGETS ${PROJECT} DESTINATION "/usr/local/bin/")
add_subdirectory(platforms/debian)
endif (WITH_DEBIAN)
# Tests
option(WITH_TESTS "Include tests")
if(WITH_TESTS)
add_subdirectory(tests)
endif(WITH_TESTS)