the_Foundation [release-1.2]

Preliminary/incomplete support for Android NDK CMake builds

=> 2c7472e6e307bd3f03e3f401b3cf8e86cbb3cb62

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3285f3..0cd2b4d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,12 @@
 cmake_minimum_required (VERSION 3.1)
 
-project (the_Foundation VERSION 1.0.2 LANGUAGES C)
+project (the_Foundation VERSION 1.1.0 LANGUAGES C)
 set (CMAKE_PROJECT_DESCRIPTION "Opinionated C11 library for low-level functionality")
 
 include (CheckIncludeFile)
 include (CheckCSourceCompiles)
 include (CheckFunctionExists)
+include (CheckSymbolExists)
 include (CMakePackageConfigHelpers)
 include (GNUInstallDirs)
 include (TestBigEndian)
@@ -71,6 +72,7 @@ check_include_file (sys/dirent.h iHaveSysDirent)
 
 # C11 threads
 check_include_file (pthread.h iHavePThread)
+check_symbol_exists (pthread_cancel pthread.h iHavePThreadCancel)
 #check_include_file (threads.h iHaveC11Threads)
 set (iHaveC11Threads NO) # TODO: Should use either this OR pthread, not both!
 if (FREEBSD OR NETBSD)
@@ -223,6 +225,10 @@ if (APPLE)
 elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
     set (iPlatformLinux YES)
     set (SOURCES ${SOURCES} src/platform/linux.c)
+elseif (ANDROID)
+    set (iPlatformLinux YES)
+    set (iPlatformAndroid YES)
+    set (SOURCES ${SOURCES} src/platform/linux.c)
 elseif (WIN32)
     set (iPlatformWindows YES)
     set (SOURCES ${SOURCES} src/platform/windows.c)
@@ -304,7 +310,7 @@ if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
         OUTPUT_STRIP_TRAILING_WHITESPACE
     )
 endif ()
-configure_file (config.h.in config.h)
+configure_file (config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
 
 set (TFDN_LIB the_Foundation)
 if (TFDN_STATIC_LIBRARY)
@@ -364,7 +370,7 @@ configure_file (
 )
 
 # Dependencies.
-if (NOT iHaveC11Threads)
+if (NOT iHaveC11Threads AND NOT ANDROID)
     # phtread is exposed via header file usage, so it must be linked publicly.
     target_link_libraries (${TFDN_LIB} PUBLIC pthread)
 endif ()
diff --git a/Depends.cmake b/Depends.cmake
index 482cf54..03c4077 100644
--- a/Depends.cmake
+++ b/Depends.cmake
@@ -1,5 +1,5 @@
 # Dependencies for the_Foundation
-if (NOT IOS)
+if (NOT IOS AND NOT ANDROID)
     find_package (PkgConfig)
     pkg_check_modules (ZLIB zlib)
     pkg_check_modules (PCRE libpcre)    # Regular expressions
@@ -35,7 +35,7 @@ if (NOT IOS)
         set (UNISTRING_INCLUDE_DIRS ${UNISTRING_DIR}/include)
         set (UNISTRING_LIBRARIES -L${UNISTRING_DIR}/lib unistring)
     endif ()
-else ()
+elseif (IOS)
     if (IOS_DIR STREQUAL "")
         message (FATAL_ERROR "iOS dependencies not found (set IOS_DIR)")
     endif ()
@@ -60,6 +60,24 @@ else ()
     endif ()
     set (UNISTRING_INCLUDE_DIRS ${IOS_DIR}/include)
     set (UNISTRING_LIBRARIES ${IOS_DIR}/lib/libunistring.a;${IOS_DIR}/lib/libiconv.a)
+elseif (ANDROID)
+    if (ANDROID_DIR STREQUAL "")
+        message (FATAL_ERROR "Android dependencies not found (set ANDROID_DIR)")
+    endif ()
+    set (ZLIB_FOUND YES)
+    set (ZLIB_LIBRARIES z)
+    set (PCRE_FOUND YES)
+    set (PCRE_INCLUDE_DIRS ${ANDROID_DIR}/libpcre-android/include)
+    set (PCRE_LIBRARIES ${ANDROID_DIR}/libpcre-android/lib/libpcre.a)
+    if (TFDN_ENABLE_TLSREQUEST)
+        set (OPENSSL_FOUND YES)
+        set (OPENSSL_INCLUDE_DIRS ${ANDROID_DIR}/openssl-android/include)
+        set (OPENSSL_LDFLAGS ${ANDROID_DIR}/openssl-android/lib/libssl.a;${ANDROID_DIR}/openssl-android/lib/libcrypto.a)
+    else ()
+        set (OPENSSL_FOUND NO)
+    endif ()
+    set (UNISTRING_INCLUDE_DIRS ${ANDROID_DIR}/libunistring-android/include)
+    set (UNISTRING_LIBRARIES ${ANDROID_DIR}/libunistring-android/lib/libunistring.a;${ANDROID_DIR}/libiconv-android/lib/libiconv.so)
 endif ()
 
 if (ZLIB_FOUND)
diff --git a/config.h.in b/config.h.in
index fe73fc0..9252123 100644
--- a/config.h.in
+++ b/config.h.in
@@ -30,13 +30,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define iFoundationLibraryVersion { ${the_Foundation_VERSION_MAJOR}, ${the_Foundation_VERSION_MINOR}, ${the_Foundation_VERSION_PATCH} }
 #define iFoundationLibraryGitTag "${iFoundationLibraryGitTag}"
 
+#cmakedefine iPlatformAndroid
 #cmakedefine iPlatformApple
 #cmakedefine iPlatformCygwin
+#cmakedefine iPlatformHaiku
 #cmakedefine iPlatformLinux
-#cmakedefine iPlatformWindows
 #cmakedefine iPlatformMsys
-#cmakedefine iPlatformHaiku
 #cmakedefine iPlatformOther
+#cmakedefine iPlatformWindows
 
 #cmakedefine iHaveDebugOutput
 #cmakedefine iHaveBigEndian
@@ -48,6 +49,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #cmakedefine iHaveOpenSSL
 #cmakedefine iHavePcre
 #cmakedefine iHavePThread
+#cmakedefine iHavePThreadCancel
 #cmakedefine iHavePThreadTimedMutex
 #cmakedefine iHaveRegExp
 #cmakedefine iHaveStrnstr
diff --git a/src/fileinfo.c b/src/fileinfo.c
index d97f459..dc398fb 100644
--- a/src/fileinfo.c
+++ b/src/fileinfo.c
@@ -60,6 +60,8 @@ static int access(const char *path, int mode) {
 #   include 
 #   if defined (iHaveSysDirent)
 #       include 
+#   elif defined (iPlatformAndroid)
+#       include 
 #   elif !defined (iPlatformHaiku)
 #       include 
 #   endif
diff --git a/src/platform/posix/address.c b/src/platform/posix/address.c
index 407439f..cde94bd 100644
--- a/src/platform/posix/address.c
+++ b/src/platform/posix/address.c
@@ -58,7 +58,7 @@ struct Impl_Address {
 
 iDefineAudienceGetter(Address, lookupFinished)
 
-#if defined (iPlatformHaiku) || defined (iPlatformOther)
+#if defined (iPlatformHaiku) || defined (iPlatformAndroid) || defined (iPlatformOther)
 #   if defined (AI_V4MAPPED_CFG)
 #       undef AI_V4MAPPED_CFG
 #   endif
@@ -391,6 +391,7 @@ iString *toStringFlags_Address(const iAddress *d, int flags, int family) {
 
 iObjectList *networkInterfaces_Address(void) {
     iObjectList *list = new_ObjectList();
+#if !defined (iPlatformAndroid) /* not supported; see https://github.com/oliviertilmans/android-ifaddrs */
     struct ifaddrs *addrs = NULL;
     if (!getifaddrs(&addrs)) {
         for (struct ifaddrs *i = addrs; i; i = i->ifa_next) {
@@ -411,6 +412,7 @@ iObjectList *networkInterfaces_Address(void) {
         }
         freeifaddrs(addrs);
     }
+#endif
     return list;
 }
 
diff --git a/src/platform/posix/process.c b/src/platform/posix/process.c
index 1ce5cc0..3d8ed76 100644
--- a/src/platform/posix/process.c
+++ b/src/platform/posix/process.c
@@ -102,6 +102,10 @@ void setWorkingDirectory_Process(iProcess *d, const iString *cwd) {
 }
 
 iBool start_Process(iProcess *d) {
+#if defined (iPlatformAndroid)
+    /* posix_spawn requires API level 28 */
+    return iFalse;
+#else
     posix_spawn_file_actions_t facts;
     int rc;
     const char **argv;
@@ -147,6 +151,7 @@ iBool start_Process(iProcess *d) {
     close(input_Pipe(&d->pout));
     close(input_Pipe(&d->perr));
     return rc == 0;
+#endif
 }
 
 iProcessId pid_Process(const iProcess *d) {
diff --git a/src/thread.c b/src/thread.c
index 4709ff6..98af25b 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -77,7 +77,7 @@ static int run_Threads_(void *arg) {
 #endif
     }
     if (d->flags & terminationEnabled_ThreadFlag) {
-#if defined (iHavePThread)
+#if defined (iHavePThreadCancel)
         pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 #endif
     }
@@ -186,7 +186,7 @@ void join_Thread(iThread *d) {
 
 void terminate_Thread(iThread *d) {
     iAssert(d->flags & terminationEnabled_ThreadFlag);
-#if defined (iHavePThread)
+#if defined (iHavePThreadCancel)
     pthread_cancel(d->id);
 #endif
 }
Proxy Information
Original URL
gemini://git.skyjake.fi/the_Foundation/release-1.2/cdiff/2c7472e6e307bd3f03e3f401b3cf8e86cbb3cb62
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
30.398275 milliseconds
Gemini-to-HTML Time
0.502978 milliseconds

This content has been proxied by September (3851b).