forked from chenxiaolong/DualBootPatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
197 lines (172 loc) · 6.65 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
cmake_minimum_required(VERSION 3.1)
project(DualBootPatcher CXX C)
set(MBP_VERSION_MAJOR 8)
set(MBP_VERSION_MINOR 99)
set(MBP_VERSION_PATCH 17)
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)
# - signtool: Builds only the code signing tool
# (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 signtool)
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 r11
if(${MBP_BUILD_TARGET} STREQUAL android-app
OR ${MBP_BUILD_TARGET} STREQUAL android-system)
if(ANDROID_NDK_RELEASE_NUM LESS 11000)
message(FATAL_ERROR "Only android-ndk r11 or newer is supported")
elseif(ANDROID_NDK_RELEASE_NUM GREATER 12000 OR
ANDROID_NDK_RELEASE_NUM EQUAL 12000)
message(FATAL_ERROR "android-ndk r12 is broken for compiling static executables")
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
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)
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)
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)
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)
elseif(${MBP_BUILD_TARGET} STREQUAL signtool)
set(MBP_TARGET_CONFIG_FILE cmake/ConfigSignTool.cmake)
set(MBP_TOP_LEVEL_BUILD FALSE)
set(MBP_INTERNAL_BUILD 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})
# Compile and link flags
include(cmake/CompilerFlags.cmake)
# Third party binaries
add_subdirectory(thirdparty)
# Dependencies
include(cmake/Dependencies.cmake)
set(MBP_GLOBAL_INCLUDE_DIRS
libmbcommon/include
libmblog/include
libmbpio/include
libmbp/include
libmbsign/include
libmbsparse/include
libmbutil/include
)
include_directories(${MBP_GLOBAL_INCLUDE_DIRS})
# Main patcher
add_subdirectory(libmbcommon)
add_subdirectory(libmblog)
add_subdirectory(libmbpio)
add_subdirectory(libmbp)
add_subdirectory(libmbsign)
add_subdirectory(libmbsparse)
add_subdirectory(libmbutil)
add_subdirectory(data)
add_subdirectory(mbtool)
add_subdirectory(mbbootui)
add_subdirectory(cryptfstool)
add_subdirectory(odinupdater)
add_subdirectory(libmiscstuff)
add_subdirectory(Android_GUI)
add_subdirectory(gui)
add_subdirectory(bootimgtool)
add_subdirectory(examples)
add_subdirectory(utilities)
add_subdirectory(signtool)
add_subdirectory(signtool/wrapped)
add_subdirectory(android)
# Must go after signtool since it references SIGNTOOL_COMMAND
configure_file(
cmake/SignFiles.cmake.in
${CMAKE_BINARY_DIR}/cmake/SignFiles.cmake
@ONLY
)
include(CPack)