forked from chenxiaolong/DualBootPatcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
222 lines (193 loc) · 7.75 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
cmake_minimum_required(VERSION 3.7)
# Add our custom module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
project(DualBootPatcher CXX C ASM)
set(MBP_VERSION_MAJOR 9)
set(MBP_VERSION_MINOR 3)
set(MBP_VERSION_PATCH 0)
set(MBP_VERSION "${MBP_VERSION_MAJOR}.${MBP_VERSION_MINOR}.${MBP_VERSION_PATCH}")
# Build target and type
set(MBP_BUILD_TARGET "desktop"
CACHE STRING "Target platform (desktop or android)")
set(MBP_BUILD_TYPE "debug"
CACHE STRING "Target build type (release, debug, or ci)")
set(MBP_SYSTEM_BUILD_TYPE "release"
CACHE STRING "Target build type for Android system components (release or debug)")
# Build types:
# - desktop: Standard build for PCs
# - android: Standard build for Android
# - android-app: Build libraries to be used for the Android app
# (not to be built manually)
# - android-system: Build executables to be included in the distrbution
# (not to be built manually)
# - hosttools: Builds tools needed on the host when cross-compiling
# (not to be built manually)
# Verify build target and type
if(NOT ${MBP_BUILD_TARGET} STREQUAL desktop
AND NOT ${MBP_BUILD_TARGET} STREQUAL android
AND NOT ${MBP_BUILD_TARGET} STREQUAL android-app
AND NOT ${MBP_BUILD_TARGET} STREQUAL android-system
AND NOT ${MBP_BUILD_TARGET} STREQUAL hosttools)
message(FATAL_ERROR "Invalid build target: ${MBP_BUILD_TARGET}")
endif()
if(NOT ${MBP_BUILD_TYPE} STREQUAL release
AND NOT ${MBP_BUILD_TYPE} STREQUAL debug
AND NOT ${MBP_BUILD_TYPE} STREQUAL ci)
message(FATAL_ERROR "Invalid build type: ${MBP_BUILD_TYPE}")
endif()
if(NOT ${MBP_SYSTEM_BUILD_TYPE} STREQUAL release
AND NOT ${MBP_SYSTEM_BUILD_TYPE} STREQUAL debug)
message(FATAL_ERROR "Invalid system build type: ${MBP_SYSTEM_BUILD_TYPE}")
endif()
# Require at least Android NDK r15
if(${MBP_BUILD_TARGET} STREQUAL android-app
OR ${MBP_BUILD_TARGET} STREQUAL android-system)
# r13 bug: ANDROID_NDK_RELEASE has newline at the end
string(REGEX REPLACE "^r(.+)[\r\n]+$" "\\1" ndk_release "${ANDROID_NDK_RELEASE}")
set(ndk_min_version 161.0)
set(ndk_max_version 162.0)
# FIXME: Due to https://github.com/android-ndk/ndk/issues/222, we need a
# custom toolchain file. Since we can't guarantee that the custom toolchain
# file will work with newer versions of the NDK, we'll depend on an exact
# version.
set(ndk_version_whitelist
161.4479499
)
if(DEFINED ndk_version_whitelist
AND NOT ndk_release IN_LIST ndk_version_whitelist)
message(FATAL_ERROR
"Requires NDK version in list: ${ndk_version_whitelist}"
" (detected: ${ndk_release})")
elseif(ndk_release VERSION_LESS ndk_min_version
OR NOT ndk_release VERSION_LESS ndk_max_version)
message(FATAL_ERROR
"Requires ${ndk_min_version} <= NDK version < ${ndk_max_version}"
" (detected: ${ndk_release})")
endif()
endif()
# Allow version to be overridden in Jenkins
set(MBP_CI_VERSION "" CACHE STRING "Override version (continuous integration)")
if(MBP_CI_VERSION)
if(NOT ${MBP_BUILD_TYPE} STREQUAL ci)
message(FATAL_ERROR "Cannot override version number for non-CI builds")
endif()
set(MBP_VERSION ${MBP_CI_VERSION})
endif()
# Tests
set(MBP_ENABLE_TESTS TRUE CACHE BOOL "Enable building of tests")
if(MBP_ENABLE_TESTS)
enable_testing()
endif()
# CPack versions
set(CPACK_PACKAGE_VERSION_MAJOR ${MBP_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${MBP_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${MBP_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${MBP_VERSION})
# Ensure CMAKE_BUILD_TYPE is set
if(NOT CMAKE_BUILD_TYPE)
if(${MBP_BUILD_TYPE} STREQUAL release)
set(NEW_CMAKE_BUILD_TYPE Release)
elseif(${MBP_BUILD_TYPE} STREQUAL debug)
set(NEW_CMAKE_BUILD_TYPE Debug)
elseif(${MBP_BUILD_TYPE} STREQUAL ci)
set(NEW_CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Setting CMAKE_BUILD_TYPE to ${NEW_CMAKE_BUILD_TYPE} because it wasn't explicitly specified")
set(CMAKE_BUILD_TYPE ${NEW_CMAKE_BUILD_TYPE} CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
FORCE)
unset(NEW_CMAKE_BUILD_TYPE)
endif()
# Ensure CMAKE_BUILD_TYPE is set to Release or Debug when targeting Android as
# the NDK toolchain file does not support other build types
if(${MBP_BUILD_TARGET} STREQUAL android
AND NOT ${CMAKE_BUILD_TYPE} STREQUAL Release
AND NOT ${CMAKE_BUILD_TYPE} STREQUAL Debug)
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be set to Release or Debug for the 'android' target")
endif()
# Sets:
# - MBP_TOP_LEVEL_BUILD: Whether this is a parent CMake build
# - MBP_INTERNAL_BUILD: Whether this is a recursive CMake build
# - MBP_TARGET_CONFIG_FILE: Config file for the current build target
# - MBP_TARGET_HAS_BUILDS: Whether this target builds anything
if(${MBP_BUILD_TARGET} STREQUAL android)
set(MBP_TARGET_CONFIG_FILE cmake/ConfigAndroid.cmake)
set(MBP_TOP_LEVEL_BUILD TRUE)
set(MBP_INTERNAL_BUILD FALSE)
set(MBP_TARGET_HAS_BUILDS FALSE)
elseif(${MBP_BUILD_TARGET} STREQUAL desktop)
set(MBP_TARGET_CONFIG_FILE cmake/ConfigDesktop.cmake)
set(MBP_TOP_LEVEL_BUILD TRUE)
set(MBP_INTERNAL_BUILD FALSE)
set(MBP_TARGET_HAS_BUILDS TRUE)
elseif(${MBP_BUILD_TARGET} STREQUAL android-app)
set(MBP_TARGET_CONFIG_FILE cmake/ConfigAndroidApp.cmake)
set(MBP_TOP_LEVEL_BUILD FALSE)
set(MBP_INTERNAL_BUILD TRUE)
set(MBP_TARGET_HAS_BUILDS TRUE)
elseif(${MBP_BUILD_TARGET} STREQUAL android-system)
set(MBP_TARGET_CONFIG_FILE cmake/ConfigAndroidSystem.cmake)
set(MBP_TOP_LEVEL_BUILD FALSE)
set(MBP_INTERNAL_BUILD TRUE)
set(MBP_TARGET_HAS_BUILDS TRUE)
elseif(${MBP_BUILD_TARGET} STREQUAL hosttools)
set(MBP_TARGET_CONFIG_FILE cmake/ConfigHostTools.cmake)
set(MBP_TOP_LEVEL_BUILD FALSE)
set(MBP_INTERNAL_BUILD TRUE)
set(MBP_TARGET_HAS_BUILDS TRUE)
endif()
# Screw Ubuntu's multiarch. FIND_LIBRARY_USE_LIB64_PATHS is disabled when
# /etc/debian_version exists, but we need lib64 in the library search path
# because the x86_64 NDK libraries are in:
# <ndk>/platforms/android-21/arch-x86_64/usr/lib64/
if(${MBP_BUILD_TARGET} STREQUAL android-app
OR ${MBP_BUILD_TARGET} STREQUAL android-system)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
endif()
# Code signing options
include(cmake/SigningConfigReader.cmake)
include(cmake/ConfigSigning.cmake)
# Build target config
include(${MBP_TARGET_CONFIG_FILE})
# Implicit system include directories
include(cmake/ImplicitIncludeDirs.cmake)
# Helper functions to backup/restore variables
include(cmake/VariableBackup.cmake)
# Compile and link flags
include(cmake/CompilerFlags.cmake)
# Third party binaries
add_subdirectory(thirdparty)
# Dependencies
include(cmake/Dependencies.cmake)
add_subdirectory(hosttools)
add_subdirectory(libmbcommon)
add_subdirectory(libmbbootimg)
add_subdirectory(libmbdevice)
add_subdirectory(libmblog)
add_subdirectory(libmbpio)
add_subdirectory(libmbpatcher)
add_subdirectory(libmbsign)
add_subdirectory(libmbsparse)
add_subdirectory(libmbutil)
add_subdirectory(data)
add_subdirectory(mbtool)
add_subdirectory(mbbootui)
add_subdirectory(odinupdater)
add_subdirectory(misc)
add_subdirectory(libmiscstuff-jni)
add_subdirectory(Android_GUI)
add_subdirectory(gui)
add_subdirectory(bootimgtool)
add_subdirectory(examples)
add_subdirectory(utilities)
add_subdirectory(signtool)
add_subdirectory(devicesgen)
add_subdirectory(android)
add_cxx_hack_to_all_targets()
# Must go after signtool since it references SIGNTOOL_COMMAND
configure_file(
cmake/SignFiles.cmake.in
${CMAKE_BINARY_DIR}/cmake/SignFiles.cmake
@ONLY
)
include(CPack)