forked from WearCode/magiskboot_build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.compat.txt
119 lines (102 loc) · 3.94 KB
/
CMakeLists.compat.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
string(TOLOWER "${CMAKE_SYSTEM_NAME}" CXXBRIDGE_GEN_TARGET_OS)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# no-op
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
# no-op
elseif (APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL")
if (CMAKE_CROSSCOMPILING)
message(STATUS "Homebrew is disabled due to cross-compiling")
else()
find_program(HOMEBREW_EXECUTABLE brew REQUIRED)
execute_process(
COMMAND ${HOMEBREW_EXECUTABLE} --prefix
OUTPUT_VARIABLE "HOMEBREW_PREFIX"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${HOMEBREW_EXECUTABLE} --version
OUTPUT_VARIABLE "HOMEBREW_VERSION"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (HOMEBREW_VERSION MATCHES "^Homebrew[ \t]+")
string(REGEX MATCH "^Homebrew[ \t]+[^\n]+" HOMEBREW_VERSION ${HOMEBREW_VERSION})
string(REGEX REPLACE "^Homebrew[ \t]+" "" HOMEBREW_VERSION ${HOMEBREW_VERSION})
else()
set(HOMEBREW_VERSION "unknown")
endif()
if (EXISTS ${HOMEBREW_PREFIX})
message(STATUS "Found Homebrew: ${HOMEBREW_EXECUTABLE} (version ${HOMEBREW_VERSION})")
else()
message(WARNING "Cannot find Homebrew")
endif()
list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${HOMEBREW_PREFIX})
endif()
elseif (WIN32)
# force struct stat to use 64-bit time_t (to match Rust's libc crate)
add_compile_definitions(__MINGW_USE_VC2005_COMPAT)
# handled in CMakeLists.stub.txt
elseif (CYGWIN)
add_compile_definitions(__USE_LINUX_IOCTL_DEFS)
elseif (EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
# exists in musl but not in rust libc crate
list(APPEND RUSTFLAGS --cfg mbb_stubs_SYS_dup3)
else()
message(WARNING "
New platform: ${CMAKE_SYSTEM_NAME}
You can file an Issue about this platform at https://github.com/ookiineko/magiskboot_build/issues if the build fails")
endif()
include(CheckSymbolExists)
check_symbol_exists(_GNU_SOURCE "features.h" HAVE__GNU_SOURCE)
if(NOT HAVE__GNU_SOURCE)
add_compile_definitions(_GNU_SOURCE)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE")
endif()
add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE64_SOURCE)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
list(APPEND CMAKE_REQUIRED_INCLUDES "sys/types.h")
include(CheckTypeSize)
check_type_size(off64_t SIZEOF_off64_t)
if(NOT HAVE_off64_t)
add_compile_definitions(off64_t=off_t)
endif()
include(CheckSymbolExists)
check_symbol_exists(lseek64 "unistd.h" LSEEK64_EXISTS)
if(NOT LSEEK64_EXISTS)
add_compile_definitions(lseek64=lseek)
list(APPEND RUSTFLAGS --cfg mbb_stubs_lseek64)
endif()
check_symbol_exists(lseek64 "unistd.h" FTRUNCATE64_EXISTS)
if(NOT FTRUNCATE64_EXISTS)
add_compile_definitions(ftruncate64=ftruncate)
endif()
check_symbol_exists(O_PATH "fcntl.h" HAVE_O_PATH)
if(NOT HAVE_O_PATH)
list(APPEND RUSTFLAGS --cfg mbb_stubs_O_PATH)
endif()
check_symbol_exists(SYS_dup3 "sys/syscall.h" HAVE_SYS_dup3)
if(NOT HAVE_SYS_dup3)
list(APPEND RUSTFLAGS --cfg mbb_stubs_SYS_dup3)
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Android")
message(STATUS "Fortify enabled")
add_compile_options(-D_FORTIFY_SOURCE=2)
else()
message(STATUS "Fortify disabled")
# Couldn't bypass fortify, so disable it
# see also: include-android/fortify_stub.h
add_compile_options(-U_FORTIFY_SOURCE)
include(CMakeLists.android.txt)
endif()
check_symbol_exists(sendfile "sys/sendfile.h" HAVE_sendfile)
if (NOT HAVE_sendfile)
list(APPEND RUSTFLAGS --cfg mbb_stubs_sendfile)
endif()
check_symbol_exists(__errno "errno.h" HAVE___errno)
if(NOT HAVE___errno)
list(APPEND RUSTFLAGS --cfg mbb_stubs___errno)
endif()