Skip to content

Commit 939e4a3

Browse files
authored
Update CMakeLists.txt for NDK and Termux
1 parent 709525a commit 939e4a3

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

CMakeLists.txt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1+
# [ Deviato android fixes for PPPwn_cpp ]
2+
# This file is intended for use with NDK builder on Linux machines
3+
# If you want to compile this natively in Termux, just call the script with `cmake -B build -DTERMUX=1`
4+
# otherwise you have to set the options below to reflect your building system and your desired target.
5+
# I assumed a default download of NDK r25c in your ~/Android/Sdk/ndk (standard from android studio)
6+
# because it's the last one that supports Android sdk19 (KitKat 4.4) builds.
7+
# The default minimum target is set as Lollipop 5.0 (sdk 21) for arm64 processors.
8+
9+
# NDK Related, change to your needs
10+
if(NOT TERMUX)
11+
# Change to your ndk installation folder
12+
set(CMAKE_TOOLCHAIN_FILE "~/Android/Sdk/ndk/25.2.9519653/build/cmake/android.toolchain.cmake")
13+
# ANDROID_ABI is the target architercture, can be one of the following: armeabi-v7a, arm64-v8a, x86, x86_64
14+
set(ANDROID_ABI "arm64-v8a")
15+
# PLATFORM is the minimum supported android api level for your target. Notice: if you want to build for android KitKat 4.4.x
16+
# (sdk 19 and 20) you need to add the option -DMG_ENABLE_EPOLL=0 in `mongoose` module. Check further down on this file.
17+
# The issue is solved with Android 5 (sdk 21) which introduces the missing epoll_create1 syscall in kernel.
18+
set(ANDROID_PLATFORM "21")
19+
endif ()
20+
21+
# Termux specific, irrelevant to others. Fixes the `ld cannot find -lpthread` error when building static binary
22+
set(THREADS_PREFER_PTHREAD_FLAG ON)
23+
# Common to static building
24+
option(USE_SYSTEM_PCAP "Disable System PCAP for static build" OFF)
25+
set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static" CACHE STRING "" FORCE)
26+
127
cmake_minimum_required(VERSION 3.12)
228
include(CMakeDependentOption)
329
set(APP_BUILD_OPTIONS)
430
set(APP_LINK_LIB)
531

6-
#deviato android fixes
7-
option(USE_SYSTEM_PCAP "Disable System PCAP for static build" OFF)
8-
#fix ld cannot find -lpthread
9-
set(THREADS_PREFER_PTHREAD_FLAG ON)
10-
set(CMAKE_EXE_LINKER_FLAGS "-static")
11-
1232
# Zig makes cross-compiling easier and ignores glibc version issue
1333
# target can be: x86_64-macos-none, x86_64-macos.11.0-none, x86_64-windows-gnu, mipsel-linux-musl, x86_64-linux-gnu.2.17, ...
1434
# Using `zig targets | jq .libc` to get the list of targets
@@ -130,7 +150,9 @@ if (BUILD_CLI)
130150
FetchContent_MakeAvailable(mongoose)
131151

132152
add_library(mongoose STATIC ${mongoose_SOURCE_DIR}/mongoose.c)
133-
target_compile_options(mongoose PUBLIC -DMG_ENABLE_PACKED_FS=1)
153+
# Disable epoll for Android sdk 19: comment the next line and uncomment the second one
154+
#target_compile_options(mongoose PUBLIC -DMG_ENABLE_PACKED_FS=1)
155+
target_compile_options(mongoose PUBLIC -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_EPOLL=0)
134156
target_include_directories(mongoose PUBLIC ${mongoose_SOURCE_DIR})
135157

136158
add_custom_command(

0 commit comments

Comments
 (0)