diff --git a/Build_android/configure.sh b/Build_android/configure.sh index fd17fb7007..562aa9cd69 100755 --- a/Build_android/configure.sh +++ b/Build_android/configure.sh @@ -13,9 +13,8 @@ set -e -# Note: we require android ndk r10e available from -# http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.tar.bz2 -# http://dl.google.com/android/ndk/android-ndk-r10e-windows-x86_64.zip +# The Android NDK r10e or later is required. To download, see the following link: +# https://developer.android.com/ndk/downloads/index.html # ----------------- # Parse args @@ -25,14 +24,24 @@ DO_BOOST=1 DO_OPENSSL=1 DO_CPPRESTSDK=1 +BOOSTVER=1.59.0 +OPENSSLVER=1.0.2k + +API=15 +STL=c++_static + function usage { echo "Usage: $0 [--skip-boost] [--skip-openssl] [--skip-cpprestsdk] [-h] [--ndk ]" echo "" echo " --skip-boost Skip fetching and compiling boost" echo " --skip-openssl Skip fetching and compiling openssl" echo " --skip-cpprestsdk Skip compiling cpprestsdk" - echo " -h,--help,-? Display this information" + echo " --boost Override the Boost version to build (default is ${BOOSTVER})" + echo " --openssl Override the OpenSSL version to build (default is ${OPENSSLVER})" echo " --ndk If specified, overrides the ANDROID_NDK environment variable" + echo " --api Selects the Android API level (default is ${API})" + echo " --stl Selects the C++ runtime (c++_shared, c++_static, gnustl_shared, gnustl_static)" + echo " -h,--help,-? Display this information" } while [[ $# > 0 ]] @@ -47,14 +56,32 @@ do "--skip-cpprestsdk") DO_CPPRESTSDK=0 ;; - "-?"|"-h"|"--help") - usage - exit + "--boost") + shift + DO_BOOST=1 + BOOSTVER=$1 + ;; + "--openssl") + shift + DO_OPENSSL=1 + OPENSSLVER=$1 ;; "--ndk") shift export ANDROID_NDK=$1 ;; + "--api") + shift + API=$1 + ;; + "--stl") + shift + STL=$1 + ;; + "-?"|"-h"|"--help") + usage + exit + ;; *) usage exit 1 @@ -107,13 +134,12 @@ then ( if [ ! -d "openssl" ]; then mkdir openssl; fi cd openssl - cp "${DIR}/openssl/Makefile" . - export ANDROID_NDK_ROOT="${NDK_DIR}" - make all + cp -af "${DIR}/openssl/." . + make all ANDROID_NDK="${NDK_DIR}" ANDROID_TOOLCHAIN=clang ANDROID_GCC_VERSION=4.9 ANDROID_API=$API ANDROID_ABI=armeabi-v7a OPENSSL_PREFIX=armeabi-v7a OPENSSL_VERSION=$OPENSSLVER + make all ANDROID_NDK="${NDK_DIR}" ANDROID_TOOLCHAIN=clang ANDROID_GCC_VERSION=4.9 ANDROID_API=$API ANDROID_ABI=x86 OPENSSL_PREFIX=x86 OPENSSL_VERSION=$OPENSSLVER ) fi - # ----- # Boost # ----- @@ -136,106 +162,77 @@ then touch cpprestsdk.patched.stamp fi - PATH="$PATH:$NDK_DIR" ./build-android.sh --boost=1.55.0 --with-libraries=random,date_time,filesystem,system,thread,chrono "${NDK_DIR}" || exit 1 - ) - - ( - if [ ! -d "Boost-for-Android-x86" ] - then - git clone Boost-for-Android Boost-for-Android-x86 - fi - cd Boost-for-Android-x86 - if [ ! -e "cpprestsdk.patched.stamp" ] - then - git checkout 1c95d349d5f92c5ac1c24e0ec6985272a3e3883c - git reset --hard HEAD - git apply "$DIR/boost-for-android-x86.patch" - ln -s ../Boost-for-Android/boost_1_55_0.tar.bz2 . - touch cpprestsdk.patched.stamp - fi - - PATH="$PATH:$NDK_DIR" ./build-android.sh --boost=1.55.0 --with-libraries=atomic,random,date_time,filesystem,system,thread,chrono "${NDK_DIR}" || exit 1 - ) + PATH="$PATH:$NDK_DIR" \ + CXXFLAGS="-std=gnu++11" \ + ./build-android.sh \ + --boost=$BOOSTVER \ + --arch=armeabi-v7a,x86 \ + --with-libraries=atomic,random,date_time,filesystem,system,thread,chrono \ + --api=$API \ + --stl=$STL \ + "${NDK_DIR}" || exit 1 ) fi -if [ "${DO_CPPRESTSDK}" == "1" ] -then -( -# ------------- -# android-cmake -# ------------- - if [ ! -e android-cmake ] - then - git clone https://github.com/taka-no-me/android-cmake.git - fi - # ---------- # casablanca # ---------- - ( - mkdir -p build.armv7.debug - cd build.armv7.debug - cmake "$DIR/../Release/" \ - -DCMAKE_TOOLCHAIN_FILE=../android-cmake/android.toolchain.cmake \ - -DANDROID_ABI=armeabi-v7a \ - -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.8 \ - -DANDROID_STL=none \ - -DANDROID_STL_FORCE_FEATURES=ON \ - -DANDROID_NATIVE_API_LEVEL=android-9 \ - -DANDROID_GOLD_LINKER=OFF \ - -DCMAKE_BUILD_TYPE=Debug \ - -DANDROID_NDK="${ANDROID_NDK}" - make -j 1 - ) +if [ "${DO_CPPRESTSDK}" == "1" ] +then +( - ( - mkdir -p build.armv7.release - cd build.armv7.release - cmake "$DIR/../Release/" \ - -DCMAKE_TOOLCHAIN_FILE=../android-cmake/android.toolchain.cmake \ - -DANDROID_ABI=armeabi-v7a \ - -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.8 \ - -DANDROID_STL=none \ - -DANDROID_STL_FORCE_FEATURES=ON \ - -DANDROID_NDK="${ANDROID_NDK}" \ - -DANDROID_NATIVE_API_LEVEL=android-9 \ - -DANDROID_GOLD_LINKER=OFF \ - -DCMAKE_BUILD_TYPE=Release - make -j 1 - ) +# Determine which CMake toolchain configuartion to use +if [ -f "${NDK_DIR}/build/cmake/android.toolchain.cmake" ]; then + # Use the builtin CMake toolchain configuration that comes with the NDK + function build_cpprestsdk { + ( + mkdir -p $1 + cd $1 + cmake "${DIR}/../Release/" \ + -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ + -DANDROID_NDK="${ANDROID_NDK}" \ + -DANDROID_TOOLCHAIN=clang \ + -DANDROID_STL=$STL \ + -DANDROID_ABI=$2 \ + -DANDROID_PLATFORM=android-$API \ + -DANDROID_NATIVE_API_LEVEL=android-$API \ + -DBOOST_VERSION="${BOOSTVER}" \ + -DCMAKE_BUILD_TYPE=$3 + make -j 1 + ) + } +else + # Download android-cmake for use with NDK r10e + if [ ! -e android-cmake ]; then + git clone https://github.com/taka-no-me/android-cmake.git + fi - ( - mkdir -p build.x86.debug - cd build.x86.debug - cmake "$DIR/../Release/" \ - -DCMAKE_TOOLCHAIN_FILE=../android-cmake/android.toolchain.cmake \ - -DANDROID_ABI=x86 \ - -DANDROID_TOOLCHAIN_NAME=x86-clang3.8 \ - -DANDROID_STL=none \ - -DANDROID_STL_FORCE_FEATURES=ON \ - -DANDROID_NATIVE_API_LEVEL=android-9 \ - -DANDROID_GOLD_LINKER=OFF \ - -DCMAKE_BUILD_TYPE=Debug \ - -DANDROID_NDK="${ANDROID_NDK}" - make -j 1 - ) + function build_cpprestsdk { + ( + mkdir -p $1 + cd $1 + cmake "${DIR}/../Release/" \ + -DCMAKE_TOOLCHAIN_FILE="../android-cmake/android.toolchain.cmake" \ + -DANDROID_NDK="${ANDROID_NDK}" \ + -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.8 \ + -DANDROID_STL=$STL \ + -DANDROID_ABI=$2 \ + -DANDROID_STL_FORCE_FEATURES=ON \ + -DANDROID_NATIVE_API_LEVEL=android-$API \ + -DANDROID_GOLD_LINKER=OFF \ + -DBOOST_VERSION="${BOOSTVER}" \ + -DCMAKE_BUILD_TYPE=$3 + make -j 1 + ) + } +fi + +# Build the cpprestsdk for each target configuration +build_cpprestsdk build.armv7.debug armeabi-v7a Debug +build_cpprestsdk build.armv7.release armeabi-v7a Release +build_cpprestsdk build.x86.debug x86 Debug +build_cpprestsdk build.x86.release x86 Release - ( - mkdir -p build.x86.release - cd build.x86.release - cmake "$DIR/../Release/" \ - -DCMAKE_TOOLCHAIN_FILE=../android-cmake/android.toolchain.cmake \ - -DANDROID_ABI=x86 \ - -DANDROID_TOOLCHAIN_NAME=x86-clang3.8 \ - -DANDROID_STL=none \ - -DANDROID_STL_FORCE_FEATURES=ON \ - -DANDROID_NDK="${ANDROID_NDK}" \ - -DANDROID_NATIVE_API_LEVEL=android-9 \ - -DANDROID_GOLD_LINKER=OFF \ - -DCMAKE_BUILD_TYPE=Release - make -j 1 - ) ) fi diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt index 3e0871c99c..3f7b27dc61 100644 --- a/Release/CMakeLists.txt +++ b/Release/CMakeLists.txt @@ -110,34 +110,15 @@ else() endif() set(WARNINGS) -set(ANDROID_STL_FLAGS) +set(ANDROID_LIBS) # Platform (not compiler) specific settings if(IOS) # The cxx_flags must be reset here, because the ios-cmake toolchain file unfortunately sets "-headerpad_max_install_names" which is not a valid clang flag. set(CMAKE_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden") elseif(ANDROID) - if(ARM) - set(LIBCXX_STL "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/thumb/libgnustl_static.a") - else() - set(LIBCXX_STL "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/libs/x86/libgnustl_static.a") - endif() # These are used in the shared library case - set(ANDROID_STL_FLAGS - ${LIBCXX_STL} - atomic - dl - gcc - c - m - -nodefaultlibs - ) - - include_directories(SYSTEM - "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/include" - "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include" - "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/include/backward" - ) + set(ANDROID_LIBS atomic dl) elseif(UNIX) # This includes OSX elseif(WIN32) add_definitions(-DUNICODE -D_UNICODE -DWIN32 -D_SCL_SECURE_NO_WARNINGS) @@ -162,8 +143,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS) message("-- Setting clang options") if(ANDROID) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -Wno-pointer-arith") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic -Wno-attributes -Wno-pointer-arith") elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") set(WARNINGS -Wall -Wextra -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls) set(LINUX_SUPPRESSIONS -Wno-overloaded-virtual -Wno-sign-conversion -Wno-deprecated -Wno-unknown-pragmas -Wno-reorder -Wno-char-subscripts -Wno-switch -Wno-unused-parameter -Wno-unused-variable -Wno-deprecated -Wno-unused-value -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-unused-function -Wno-sign-compare -Wno-shorten-64-to-32 -Wno-reorder -Wno-unused-local-typedefs) @@ -233,7 +213,7 @@ function(add_casablanca_test NAME SOURCES_VAR) cpprest common_utilities unittestpp - ${ANDROID_STL_FLAGS} + ${ANDROID_LIBS} ) if (BUILD_SHARED_LIBS) add_test(NAME ${NAME} diff --git a/Release/cmake/cpprest_find_boost.cmake b/Release/cmake/cpprest_find_boost.cmake index 298b080aae..91729541c9 100644 --- a/Release/cmake/cpprest_find_boost.cmake +++ b/Release/cmake/cpprest_find_boost.cmake @@ -1,3 +1,23 @@ +macro(cpprestsdk_find_boost_android_package) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + if(CMAKE_HOST_WIN32) + set(WIN32 1) + set(UNIX) + elseif(CMAKE_HOST_APPLE) + set(APPLE 1) + set(UNIX) + endif() + find_package(${ARGN}) + set(APPLE) + set(WIN32) + set(UNIX 1) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) +endmacro() + function(cpprest_find_boost) if(TARGET cpprestsdk_boost_internal) return() @@ -10,13 +30,13 @@ function(cpprest_find_boost) elseif(ANDROID) set(Boost_COMPILER "-clang") if(ARM) - set(BOOST_ROOT "${CMAKE_BINARY_DIR}/../Boost-for-Android/build" CACHE INTERNAL "") - set(BOOST_LIBRARYDIR "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/lib" CACHE INTERNAL "") + set(BOOST_ROOT "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/armeabi-v7a" CACHE INTERNAL "") + set(BOOST_LIBRARYDIR "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/armeabi-v7a/lib" CACHE INTERNAL "") else() - set(BOOST_ROOT "${CMAKE_BINARY_DIR}/../Boost-for-Android-x86/build" CACHE INTERNAL "") - set(BOOST_LIBRARYDIR "${CMAKE_BINARY_DIR}/../Boost-for-Android-x86/build/lib" CACHE INTERNAL "") + set(BOOST_ROOT "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/x86" CACHE INTERNAL "") + set(BOOST_LIBRARYDIR "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/x86/lib" CACHE INTERNAL "") endif() - find_host_package(Boost 1.55 EXACT REQUIRED COMPONENTS random system thread filesystem chrono atomic) + cpprestsdk_find_boost_android_package(Boost ${BOOST_VERSION} EXACT REQUIRED COMPONENTS random system thread filesystem chrono atomic) elseif(UNIX) find_package(Boost REQUIRED COMPONENTS random system thread filesystem chrono atomic date_time regex) else() diff --git a/Release/include/cpprest/details/basic_types.h b/Release/include/cpprest/details/basic_types.h index eadba01684..e9477c736a 100644 --- a/Release/include/cpprest/details/basic_types.h +++ b/Release/include/cpprest/details/basic_types.h @@ -20,8 +20,10 @@ #include "cpprest/details/cpprest_compat.h" #ifndef _WIN32 -# define __STDC_LIMIT_MACROS -# include +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#include #else #include #endif diff --git a/Release/src/http/client/http_client_asio.cpp b/Release/src/http/client/http_client_asio.cpp index 4ba3e0851b..cf9877df72 100644 --- a/Release/src/http/client/http_client_asio.cpp +++ b/Release/src/http/client/http_client_asio.cpp @@ -1645,7 +1645,7 @@ class asio_context : public request_context, public std::enable_shared_from_this timedout }; -#if defined(ANDROID) || defined(__ANDROID__) +#if (defined(ANDROID) || defined(__ANDROID__)) && !defined(_LIBCPP_VERSION) boost::chrono::microseconds m_duration; #else std::chrono::microseconds m_duration; diff --git a/Release/src/pch/stdafx.h b/Release/src/pch/stdafx.h index 1532db2f54..389b5757cb 100644 --- a/Release/src/pch/stdafx.h +++ b/Release/src/pch/stdafx.h @@ -53,7 +53,7 @@ #include #include #include "pthread.h" -#if (defined(ANDROID) || defined(__ANDROID__)) +#if (defined(ANDROID) || defined(__ANDROID__)) && !defined(_LIBCPP_VERSION) // Boost doesn't recognize libstdcpp on top of clang correctly #include "boost/config.hpp" #include "boost/config/stdlib/libstdcpp3.hpp"