This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.magisk.txt
78 lines (73 loc) · 3.74 KB
/
CMakeLists.magisk.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
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/flags.h)
find_package(Git REQUIRED)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/Magisk/.git)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/Magisk"
OUTPUT_VARIABLE "MAGISK_VERSION"
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
message(FATAL_ERROR "Cannot find Magisk")
endif()
# fallback version
set(MAGISK_VER_CODE 1000000)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/Magisk/gradle.properties)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/src/Magisk/gradle.properties MAGISK_CONFIG_CONTENTS)
foreach (MAGISK_CONFIG_LINE ${MAGISK_CONFIG_CONTENTS})
string(REGEX REPLACE "^[ ]+" "" MAGISK_CONFIG_LINE ${MAGISK_CONFIG_LINE})
if (MAGISK_CONFIG_LINE STREQUAL "" OR MAGISK_CONFIG_LINE MATCHES "^#")
continue()
else()
string(REGEX MATCH "^[^=]+=[^=#]+" MAGISK_CONFIG_KV ${MAGISK_CONFIG_LINE})
if (MAGISK_CONFIG_KV STREQUAL "")
continue()
else()
if (MAGISK_CONFIG_KV MATCHES "^magisk\\.")
string(REGEX REPLACE "^magisk\\." "" MAGISK_CONFIG_KV ${MAGISK_CONFIG_KV})
string(REGEX MATCH "^[^=]+" MAGISK_CONFIG_KEY ${MAGISK_CONFIG_KV})
string(REGEX REPLACE "^${MAGISK_CONFIG_KEY}=" "" MAGISK_CONFIG_VALUE ${MAGISK_CONFIG_KV})
if (MAGISK_CONFIG_KEY STREQUAL "versionCode")
set(MAGISK_VER_CODE "${MAGISK_CONFIG_VALUE}")
else()
continue()
endif()
else()
continue()
endif()
endif()
endif()
endforeach()
endif()
message(STATUS "Magisk version: ${MAGISK_VERSION} (version code \"${MAGISK_VER_CODE}\")")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/flags.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/flags.h @ONLY)
endif()
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(MAGISK_DEBUG "1")
else()
set(MAGISK_DEBUG "0")
endif()
find_program(sed_EXECUTABLE sed REQUIRED)
message(STATUS "Found sed: ${sed_EXECUTABLE}")
# https://unix.stackexchange.com/questions/715352/using-sed-with-i-option-creates-strangely-named-new-file-while-leaving-the
if (APPLE)
# need a space
set(sed_REPLACE_COMMAND ${sed_EXECUTABLE} -i '')
else()
# need no space
set(sed_REPLACE_COMMAND ${sed_EXECUTABLE} -i'')
endif()
add_custom_target(generate_flags_h_in
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/flags.h
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h.in
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/generated
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/flags.h ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h.in
COMMAND ${sed_REPLACE_COMMAND} "s/!MAGISK_DEBUG!/${MAGISK_DEBUG}/g" ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h.in
COMMENT "Generating C header flags.h.in")
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h.in
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h
COMMENT "Preparing C header flags.h")
add_custom_target(prepared_generated_directory
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated/flags.h)