From 8c6d0b51c719e1817e308375d129b17ede3b82fc Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 7 Nov 2016 22:15:07 +0000 Subject: Use CMake's Android generators to crosscompile --- src/OSSupport/CMakeLists.txt | 8 -------- src/OSSupport/Errors.cpp | 2 +- src/OSSupport/File.cpp | 6 +++++- src/OSSupport/NetworkInterfaceEnum.cpp | 14 +++++++------- src/OSSupport/NetworkSingleton.cpp | 15 +++++++++++++++ src/OSSupport/StackTrace.cpp | 4 ++-- 6 files changed, 30 insertions(+), 19 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 876b4f789..22699f7cd 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -43,12 +43,4 @@ endif() if(NOT MSVC) add_library(OSSupport ${SRCS} ${HDRS}) - - if(UNIX) - if(NOT APPLE) - target_link_libraries(OSSupport rt) - endif() - - target_link_libraries(OSSupport pthread event_core event_extra) - endif() endif() diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index a05650111..004cbaccc 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if defined(__GLIBC__) && defined( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() + #if defined(__GLIBC__) && defined( _GNU_SOURCE) && !defined(ANDROID) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer)); if (res != nullptr) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index a59f599ae..062161144 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -653,9 +653,13 @@ unsigned cFile::GetLastModificationTime(const AString & a_FileName) { return 0; } - #ifdef _WIN32 + #if defined(_WIN32) // Windows returns times in local time already return static_cast(st.st_mtime); + #elif defined(ANDROID) + // Identical to Linux below, but st_mtime is an unsigned long, so cast is needed: + auto Time = static_cast(st.st_mtime); + return static_cast(mktime(localtime(&Time))); #else // Linux returns UTC time, convert to local timezone: return static_cast(mktime(localtime(&st.st_mtime))); diff --git a/src/OSSupport/NetworkInterfaceEnum.cpp b/src/OSSupport/NetworkInterfaceEnum.cpp index d3a254c23..439710c38 100644 --- a/src/OSSupport/NetworkInterfaceEnum.cpp +++ b/src/OSSupport/NetworkInterfaceEnum.cpp @@ -7,10 +7,10 @@ #include "Network.h" #include "event2/util.h" -#ifdef _WIN32 +#if defined(_WIN32) #include #pragma comment(lib, "IPHLPAPI.lib") -#else // _WIN32 +#elif !defined(ANDROID) // _WIN32 #include #include #include @@ -21,7 +21,7 @@ -#ifdef _WIN32 +#if defined(_WIN32) /** Converts the SOCKET_ADDRESS structure received from the OS into an IP address string. */ static AString PrintAddress(SOCKET_ADDRESS & a_Addr) @@ -50,7 +50,7 @@ static AString PrintAddress(SOCKET_ADDRESS & a_Addr) return IP; } -#else // _WIN32 +#elif !defined(ANDROID) // _WIN32 static AString PrintAddress(ifaddrs * InterfaceAddress) { @@ -82,7 +82,7 @@ static AString PrintAddress(ifaddrs * InterfaceAddress) } } -#endif // else _WIN32 +#endif // else !ANDROID @@ -92,7 +92,7 @@ AStringVector cNetwork::EnumLocalIPAddresses(void) { AStringVector res; - #ifdef _WIN32 + #if defined(_WIN32) // Query the OS for all adapters' addresses: char buffer[64 KiB]; // A buffer backing the address list @@ -129,7 +129,7 @@ AStringVector cNetwork::EnumLocalIPAddresses(void) } // for pUnicast } // for pCurrAddresses - #else // _WIN32 + #elif !defined(ANDROID) // _WIN32 struct ifaddrs * ifAddrStruct = nullptr; getifaddrs(&ifAddrStruct); diff --git a/src/OSSupport/NetworkSingleton.cpp b/src/OSSupport/NetworkSingleton.cpp index dcf17bccb..3a8dbbdc7 100644 --- a/src/OSSupport/NetworkSingleton.cpp +++ b/src/OSSupport/NetworkSingleton.cpp @@ -13,6 +13,11 @@ #include "IPLookup.h" #include "HostnameLookup.h" +#ifdef ANDROID + // For DNS server retrieval + #include +#endif + @@ -89,6 +94,16 @@ void cNetworkSingleton::Initialise(void) abort(); } + #ifdef ANDROID + char PropertyBuffer[PROP_VALUE_MAX]; + + __system_property_get("net.dns1", PropertyBuffer); + evdns_base_nameserver_ip_add(m_DNSBase, PropertyBuffer); + + __system_property_get("net.dns2", PropertyBuffer); + evdns_base_nameserver_ip_add(m_DNSBase, PropertyBuffer); + #endif + // Create the event loop thread: m_HasTerminated = false; m_EventLoopThread = std::thread(RunEventLoop, this); diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp index 030566065..c84e2cbca 100644 --- a/src/OSSupport/StackTrace.cpp +++ b/src/OSSupport/StackTrace.cpp @@ -7,7 +7,7 @@ #include "StackTrace.h" #ifdef _WIN32 #include "../StackWalker.h" -#else +#elif !defined(ANDROID) // The Android NDK has no execinfo header #ifdef __GLIBC__ #include #endif @@ -32,7 +32,7 @@ void PrintStackTrace(void) } } sw; sw.ShowCallstack(); - #else + #elif !defined(ANDROID) #ifdef __GLIBC__ // Use the backtrace() function to get and output the stackTrace: // Code adapted from https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes -- cgit v1.2.3