forked from WearCode/magiskboot_build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.stub.txt
134 lines (112 loc) · 5.6 KB
/
CMakeLists.stub.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
include(CheckSymbolExists)
check_symbol_exists(
"strlcpy"
"string.h"
HAVE_STRLCPY)
if (HAVE_STRLCPY)
target_compile_definitions(libbase PRIVATE
-DHAVE_STRLCPY)
endif()
add_library(platform_stubs STATIC
src/libc-compat/placeholder.c)
target_include_directories(platform_stubs PUBLIC src/libc-compat/include)
if (NOT HAVE_sendfile)
message(STATUS "Using generic sendfile replacement")
target_sources(platform_stubs PRIVATE
src/libc-compat/non-linux/sendfile_fallback.c)
endif()
if (NOT HAVE_STRLCPY)
message(STATUS "Using bundled libbsd strlcpy implementation")
target_sources(platform_stubs PRIVATE
src/libc-compat/libbsd/str.c)
endif()
if(NOT HAVE___errno)
target_sources(platform_stubs PRIVATE
src/libc-compat/common/__errno.c)
# e.g Linux and Emscripten
check_symbol_exists(__errno_location "errno.h" HAVE___errno_location)
if (HAVE___errno_location)
set_source_files_properties(src/libc-compat/common/__errno.c PROPERTIES
COMPILE_FLAGS -DHAVE___errno_location)
else()
# e.g macOS
check_symbol_exists(__error "errno.h" HAVE___error)
if (HAVE___error)
set_source_files_properties(src/libc-compat/common/__errno.c PROPERTIES
COMPILE_FLAGS -DHAVE___error)
else()
# e.g MinGW
check_symbol_exists(_errno "errno.h" HAVE__errno)
if (HAVE__errno)
set_source_files_properties(src/libc-compat/common/__errno.c PROPERTIES
COMPILE_FLAGS -DHAVE__errno)
else()
message(FATAL_ERROR "Don't know errno implementation on this platform")
endif()
endif()
endif()
message(STATUS "Using __errno alias")
endif()
if (WIN32)
message(STATUS "Using win32 libc-compat")
target_sources(platform_stubs PRIVATE
src/libc-compat/winsup/acl.c
src/libc-compat/winsup/at.c
src/libc-compat/winsup/dirent.c
src/libc-compat/winsup/file.c
src/libc-compat/winsup/io.c
src/libc-compat/winsup/link.c
src/libc-compat/winsup/mkdir.c
src/libc-compat/winsup/mknod_stub.c
src/libc-compat/winsup/open.c
src/libc-compat/winsup/stat.c
src/libc-compat/winsup/str.c
src/libc-compat/winsup/uio.c
src/libc-compat/winsup/internal/assert.c
src/libc-compat/winsup/internal/errno.c
src/libc-compat/winsup/internal/fd.c)
target_link_libraries(platform_stubs INTERFACE shlwapi)
# these source files contains symbols that must not be excluded from the final executable
target_sources(magiskboot_exe PRIVATE
src/libc-compat/winsup/crt_flags.c)
add_library(libmman STATIC
src/mman-win32/mman.c)
target_compile_definitions(libmman PRIVATE -DWITH_WINSUP)
target_include_directories(libmman PUBLIC src/mman-win32)
target_link_libraries(platform_stubs INTERFACE libmman)
add_library(libgetline STATIC
src/msvc_getline/getline.c)
target_include_directories(libgetline PUBLIC src/msvc_getline)
target_link_libraries(platform_stubs INTERFACE libgetline)
target_include_directories(android_libbase PRIVATE src/libc-compat/include)
# libc-compat overrides
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=creat -Wl,--wrap=open -Wl,--wrap=fopen")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=fdopen -Wl,--wrap=fstat -Wl,--wrap=CreateFileW")
# Rust STD is directly using these
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=_creat -Wl,--wrap=_open -Wl,--wrap=_fdopen -Wl,--wrap=_fstat64")
# llvm-mingw uses a different mangling
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=CreateFileW@28")
endif()
if (EMSCRIPTEN)
target_sources(magiskboot_exe PRIVATE
src/web-shims/conio_hack.cc)
set_source_files_properties(src/Magisk/native/src/boot/main.cpp PROPERTIES
COMPILE_FLAGS -Dmain=__mbb_main)
target_link_libraries(magiskboot_exe embind)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=printf -Wl,--wrap=iprintf -Wl,--wrap=write")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=fprintf -Wl,--wrap=fiprintf -Wl,--wrap=exit")
message(STATUS "Using custom HTML wrapper")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sFORCE_FILESYSTEM -sEXPORTED_RUNTIME_METHODS=ENV,FS,TTY,callMain,abort,mbb_get_wasm_name,mbb_set_this_prog")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --pre-js=${CMAKE_CURRENT_SOURCE_DIR}/src/web-shims/impl.pre.js")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --js-library=${CMAKE_CURRENT_SOURCE_DIR}/src/web-shims/utils.lib.js")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --shell-file=${CMAKE_CURRENT_SOURCE_DIR}/src/web-shims/shfile.in.html")
set_target_properties(magiskboot_exe PROPERTIES LINK_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/web-shims/impl.pre.js;${CMAKE_CURRENT_SOURCE_DIR}/src/web-shims/utils.lib.js;${CMAKE_CURRENT_SOURCE_DIR}/src/web-shims/shfile.in.html")
message(STATUS "Using Emscripten mmap stubs")
target_sources(platform_stubs PRIVATE
src/libc-compat/emsup/mmap_hack.c)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH -Wl,-u,ntohs -Wl,-u,htons -Wl,-u,htonl")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--wrap=close -Wl,--wrap=fclose")
endif()
target_link_libraries(libbase platform_stubs)
target_link_libraries(magiskboot_exe platform_stubs)