Android build cleanup (#4734)
* Android build cleanup * Remove unnecessary workaround * Remove more unnecessities * Bump cmake version
This commit is contained in:
parent
84289a2ba9
commit
e053f72db8
@ -1,28 +1,15 @@
|
|||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.12.4)
|
||||||
project(Cuberite)
|
project(Cuberite)
|
||||||
|
|
||||||
# Set up Android parameters
|
# Set up Android parameters
|
||||||
add_definitions(-DANDROID)
|
|
||||||
set(ANDROID TRUE)
|
set(ANDROID TRUE)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
|
|
||||||
|
|
||||||
# We're crosscompiling for Android
|
# We're crosscompiling for Android
|
||||||
set(NO_NATIVE_OPTIMIZATION TRUE)
|
set(NO_NATIVE_OPTIMIZATION TRUE)
|
||||||
|
|
||||||
# SYSTEM flag to silence warnings for external headers
|
|
||||||
include_directories(SYSTEM
|
|
||||||
../lib/
|
|
||||||
../src/
|
|
||||||
../lib/jsoncpp/include/
|
|
||||||
../lib/polarssl/include/
|
|
||||||
../lib/sqlitecpp/include/
|
|
||||||
../lib/sqlitecpp/sqlite3/
|
|
||||||
../lib/libevent/include/
|
|
||||||
)
|
|
||||||
|
|
||||||
# Disable some compiler warnings (the lazy way out)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion -Wno-sign-conversion -Wno-unused-command-line-argument -s")
|
|
||||||
|
|
||||||
# Build the rest of the server
|
# Build the rest of the server
|
||||||
add_subdirectory(../ Cuberite)
|
add_subdirectory(../ Cuberite)
|
||||||
|
|
||||||
|
# Strip debug symbols to reduce binary size
|
||||||
|
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
|
||||||
|
@ -4,7 +4,7 @@ set -e
|
|||||||
|
|
||||||
# This script cross-compiles cuberite for the android platform. It uses
|
# This script cross-compiles cuberite for the android platform. It uses
|
||||||
# the following enviroment variables
|
# the following enviroment variables
|
||||||
# CMAKE: Should be the path to a cmake executable of version 3.7+
|
# CMAKE: Should be the path to a cmake executable of version 3.12.4+
|
||||||
# NDK: Should be the path to the android ndk root
|
# NDK: Should be the path to the android ndk root
|
||||||
# (optional) TYPE: either Release or Debug, sets the build type
|
# (optional) TYPE: either Release or Debug, sets the build type
|
||||||
# (optional) THREADS: The number of threads to use, default 4
|
# (optional) THREADS: The number of threads to use, default 4
|
||||||
|
@ -230,7 +230,7 @@ std::unique_ptr<cLogger::cListener> MakeConsoleListener(bool a_IsService)
|
|||||||
{
|
{
|
||||||
return cpp14::make_unique<cVanillaCPPConsoleListener>();
|
return cpp14::make_unique<cVanillaCPPConsoleListener>();
|
||||||
}
|
}
|
||||||
#elif (defined (__linux) && !defined(ANDROID)) || defined (__APPLE__)
|
#elif defined (__linux) || defined (__APPLE__)
|
||||||
// TODO: lookup terminal in terminfo
|
// TODO: lookup terminal in terminfo
|
||||||
if (isatty(fileno(stdout)))
|
if (isatty(fileno(stdout)))
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "StackTrace.h"
|
#include "StackTrace.h"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "WinStackWalker.h"
|
#include "WinStackWalker.h"
|
||||||
#elif !defined(ANDROID) // The Android NDK has no execinfo header
|
#else
|
||||||
#ifdef __GLIBC__
|
#ifdef __GLIBC__
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#endif
|
#endif
|
||||||
@ -30,7 +30,7 @@ void PrintStackTrace(void)
|
|||||||
}
|
}
|
||||||
} sw;
|
} sw;
|
||||||
sw.ShowCallstack();
|
sw.ShowCallstack();
|
||||||
#elif !defined(ANDROID)
|
#else
|
||||||
#ifdef __GLIBC__
|
#ifdef __GLIBC__
|
||||||
// Use the backtrace() function to get and output the stackTrace:
|
// 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
|
// Code adapted from https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
|
||||||
|
@ -134,20 +134,20 @@ protected:
|
|||||||
{
|
{
|
||||||
if (m_HasIPv6)
|
if (m_HasIPv6)
|
||||||
{
|
{
|
||||||
sendto(m_MainSock, m_Data.data(), static_cast<socklen_t>(m_Data.size()), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv6), static_cast<socklen_t>(sizeof(m_AddrIPv6)));
|
sendto(m_MainSock, m_Data.data(), m_Data.size(), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv6), static_cast<socklen_t>(sizeof(m_AddrIPv6)));
|
||||||
}
|
}
|
||||||
else if (m_HasIPv4)
|
else if (m_HasIPv4)
|
||||||
{
|
{
|
||||||
// If the secondary socket is valid, it is an IPv4 socket, so use that:
|
// If the secondary socket is valid, it is an IPv4 socket, so use that:
|
||||||
if (m_SecondSock != -1)
|
if (m_SecondSock != -1)
|
||||||
{
|
{
|
||||||
sendto(m_SecondSock, m_Data.data(), static_cast<socklen_t>(m_Data.size()), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv4), static_cast<socklen_t>(sizeof(m_AddrIPv4)));
|
sendto(m_SecondSock, m_Data.data(), m_Data.size(), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv4), static_cast<socklen_t>(sizeof(m_AddrIPv4)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Need an address conversion from IPv4 to IPv6-mapped-IPv4:
|
// Need an address conversion from IPv4 to IPv6-mapped-IPv4:
|
||||||
ConvertIPv4ToMappedIPv6(m_AddrIPv4, m_AddrIPv6);
|
ConvertIPv4ToMappedIPv6(m_AddrIPv4, m_AddrIPv6);
|
||||||
sendto(m_MainSock, m_Data.data(), static_cast<socklen_t>(m_Data.size()), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv6), static_cast<socklen_t>(sizeof(m_AddrIPv6)));
|
sendto(m_MainSock, m_Data.data(), m_Data.size(), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv6), static_cast<socklen_t>(sizeof(m_AddrIPv6)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -164,7 +164,7 @@ protected:
|
|||||||
LOGD("UDP endpoint queued sendto: Name not resolved to IPv4 for an IPv4-only socket");
|
LOGD("UDP endpoint queued sendto: Name not resolved to IPv4 for an IPv4-only socket");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendto(m_MainSock, m_Data.data(), static_cast<socklen_t>(m_Data.size()), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv4), static_cast<socklen_t>(sizeof(m_AddrIPv4)));
|
sendto(m_MainSock, m_Data.data(), m_Data.size(), 0, reinterpret_cast<const sockaddr *>(&m_AddrIPv4), static_cast<socklen_t>(sizeof(m_AddrIPv4)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,19 +284,19 @@ bool cUDPEndpointImpl::Send(const AString & a_Payload, const AString & a_Host, U
|
|||||||
if (IsValidSocket(m_SecondarySock))
|
if (IsValidSocket(m_SecondarySock))
|
||||||
{
|
{
|
||||||
// The secondary socket, which is always IPv4, is present:
|
// The secondary socket, which is always IPv4, is present:
|
||||||
NumSent = static_cast<int>(sendto(m_SecondarySock, a_Payload.data(), static_cast<socklen_t>(a_Payload.size()), 0, reinterpret_cast<const sockaddr *>(&sa), static_cast<socklen_t>(salen)));
|
NumSent = static_cast<int>(sendto(m_SecondarySock, a_Payload.data(), a_Payload.size(), 0, reinterpret_cast<const sockaddr *>(&sa), static_cast<socklen_t>(salen)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Need to convert IPv4 to IPv6 address before sending:
|
// Need to convert IPv4 to IPv6 address before sending:
|
||||||
sockaddr_in6 IPv6;
|
sockaddr_in6 IPv6;
|
||||||
ConvertIPv4ToMappedIPv6(*reinterpret_cast<sockaddr_in *>(&sa), IPv6);
|
ConvertIPv4ToMappedIPv6(*reinterpret_cast<sockaddr_in *>(&sa), IPv6);
|
||||||
NumSent = static_cast<int>(sendto(m_MainSock, a_Payload.data(), static_cast<socklen_t>(a_Payload.size()), 0, reinterpret_cast<const sockaddr *>(&IPv6), static_cast<socklen_t>(sizeof(IPv6))));
|
NumSent = static_cast<int>(sendto(m_MainSock, a_Payload.data(), a_Payload.size(), 0, reinterpret_cast<const sockaddr *>(&IPv6), static_cast<socklen_t>(sizeof(IPv6))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NumSent = static_cast<int>(sendto(m_MainSock, a_Payload.data(), static_cast<socklen_t>(a_Payload.size()), 0, reinterpret_cast<const sockaddr *>(&sa), static_cast<socklen_t>(salen)));
|
NumSent = static_cast<int>(sendto(m_MainSock, a_Payload.data(), a_Payload.size(), 0, reinterpret_cast<const sockaddr *>(&sa), static_cast<socklen_t>(salen)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -304,7 +304,7 @@ bool cUDPEndpointImpl::Send(const AString & a_Payload, const AString & a_Host, U
|
|||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
{
|
{
|
||||||
reinterpret_cast<sockaddr_in6 *>(&sa)->sin6_port = htons(a_Port);
|
reinterpret_cast<sockaddr_in6 *>(&sa)->sin6_port = htons(a_Port);
|
||||||
NumSent = static_cast<int>(sendto(m_MainSock, a_Payload.data(), static_cast<socklen_t>(a_Payload.size()), 0, reinterpret_cast<const sockaddr *>(&sa), static_cast<socklen_t>(salen)));
|
NumSent = static_cast<int>(sendto(m_MainSock, a_Payload.data(), a_Payload.size(), 0, reinterpret_cast<const sockaddr *>(&sa), static_cast<socklen_t>(salen)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -563,10 +563,9 @@ void cUDPEndpointImpl::Callback(evutil_socket_t a_Socket, short a_What)
|
|||||||
{
|
{
|
||||||
// Receive datagram from the socket:
|
// Receive datagram from the socket:
|
||||||
char buf[64 KiB];
|
char buf[64 KiB];
|
||||||
socklen_t buflen = static_cast<socklen_t>(sizeof(buf));
|
|
||||||
sockaddr_storage sa;
|
sockaddr_storage sa;
|
||||||
socklen_t salen = static_cast<socklen_t>(sizeof(sa));
|
socklen_t salen = static_cast<socklen_t>(sizeof(sa));
|
||||||
auto len = recvfrom(a_Socket, buf, buflen, 0, reinterpret_cast<sockaddr *>(&sa), &salen);
|
auto len = recvfrom(a_Socket, buf, sizeof(buf), 0, reinterpret_cast<sockaddr *>(&sa), &salen);
|
||||||
if (len >= 0)
|
if (len >= 0)
|
||||||
{
|
{
|
||||||
// Convert the remote IP address to a string:
|
// Convert the remote IP address to a string:
|
||||||
|
14
src/main.cpp
14
src/main.cpp
@ -10,20 +10,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
// Workaround for Android NDK builds that do not support std::to_string
|
|
||||||
namespace std
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
std::string to_string(T Value)
|
|
||||||
{
|
|
||||||
std::ostringstream TempStream;
|
|
||||||
TempStream << Value;
|
|
||||||
return TempStream.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <dbghelp.h>
|
#include <dbghelp.h>
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
|
Loading…
Reference in New Issue
Block a user