Search code examples
androidc++cmakepoco-librariesconan

Building Poco C++ libraries with Conan profiles for Android


I am trying to use Poco C++ Libraries in the project and I ran into some problems when building for Android.

I am using Conan C++ package manager as a base but I included Poco sources into the project and including its subdirectory into project's top level CMakeLists.txt to make the process more transparent.

If I build project with Poco libraries which don't depend on OpenSSL it builds fine. If I add Poco's NetSSL then I get some math.h related problems:

In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Crypto/src/Cipher.cpp:15:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Crypto/include/Poco/Crypto/Cipher.h:22:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/RefCountedObject.h:22:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/MemoryPool.h:24:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/NestedDiagnosticContext.h:24:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/OrderedMap.h:28:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/ordered_hash.h:31:
/home/uname/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++/include/cmath:313:9: error: no member named 'signbit' in the global
      namespace; did you mean '__signbit'?
using ::signbit;
      ~~^
/usr/include/bits/mathcalls-helper-functions.h:25:20: note: '__signbit' declared here
__MATHDECL_1 (int, __signbit,, (_Mdouble_ __value))

As far as I know this is due to the C-only math.h beeing included earlier in path as libc++ math.h . Does anyone have an idea how to solve that problem?

Actually I am trying to find a solution to build and link Poco libraries which do not build correctly for Android (due to some build issues with OpenSSL dependency) when using Conan dependencies and build requirements android-ndk/r18@theodelrieu/testing or android_ndk_installer/r19b@bincrafters/stable on Ubuntu 18.04. Therefore I'm trying to build Poco libraries and OpenSSL it without using Conan packages.

Thank you in advance for any hint or idea!

This is my Conan profile for Android:

# --------------------------------------------------------------------------------------------------------------------
# PARAMETERS

    #standalone_toolchain=/home/uname/Android/ndk/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64

    target_host=armv7a-linux-androideabi
    ar_host=arm-linux-androideabi

    api_level=21
    cc_compiler=clang
    cxx_compiler=clang++

# --------------------------------------------------------------------------------------------------------------------

[settings]

    os_build=Linux
    arch_build=x86_64

    compiler=clang
    compiler.version=7.0
    compiler.libcxx=libc++
    os=Android
    os.api_level=$api_level
    arch=armv7

    #Debug/Release
    build_type=Debug

# --------------------------------------------------------------------------------------------------------------------

[build_requires]

    android-ndk/r18@theodelrieu/testing
    #android_ndk_installer/r19b@bincrafters/stable

# --------------------------------------------------------------------------------------------------------------------

[options]

    *:shared=False
    #Poco:no_asm=True

# --------------------------------------------------------------------------------------------------------------------

[env]

    CONAN_CMAKE_FIND_ROOT_PATH=$standalone_toolchain/sysroot
    PATH=[$standalone_toolchain/bin]
    CHOST=$target_host

    # Flags can be also appended after the path to the compiler
    CC=$target_host$api_level-$cc_compiler
    CXX=$target_host$api_level-$cxx_compiler

    CMAKE_C_COMPILER=$CC
    CMAKE_CXX_COMPILER=$CXX

    AR=$ar_host-ar
    AS=$ar_host-as

    RANLIB=$target_host-ranlib
    LD=$target_host-ld
    STRIP=$target_host-strip
    CFLAGS= -fPIE -fPIC -I$standalone_toolchain/include/c++/4.9.x
    CXXFLAGS= -fPIE -fPIC -I$standalone_toolchain/include/c++/4.9.x
    LDFLAGS= -pie

    export ANDROID_API=$api_level

    OpenSSL:compiler=clang
    OpenSSL:options.no_zlib=True

And root CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(-some-project-)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

## Experimental POCO

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl/include) # Path whererever the openssl-dev headers are present

# When compiling the POCO C++ Libraries for a Android target, as well as when including POCO C++ Libraries headers in a project for a Android target, the preprocessor macro POCO_ANDROID must be defined. This is because the Android NDK GCC compiler does not provide a predefined macro that allows for reliable detection of an Android target.
IF(ANDROID)
SET(POCO_ANDROID)
ENDIF()

SET(ENABLE_ENCODINGS OFF)
SET(ENABLE_ENCODINGS_COMPILER OFF)
SET(ENABLE_XML OFF)
SET(ENABLE_JSON ON)
SET(ENABLE_MONGODB OFF)
SET(ENABLE_REDIS OFF)
SET(ENABLE_PDF OFF)
SET(ENABLE_UTIL OFF)
SET(ENABLE_NET ON)
SET(ENABLE_NETSSL ON)
SET(ENABLE_NETSSL_WIN OFF)
SET(ENABLE_CRYPTO OFF)
SET(ENABLE_DATA OFF)
SET(ENABLE_DATA_SQLITE OFF)
SET(ENABLE_DATA_MYSQL OFF)
SET(ENABLE_DATA_ODBC OFF)
SET(ENABLE_SEVENZIP OFF)
SET(ENABLE_ZIP OFF)
SET(ENABLE_APACHECONNECTOR OFF)
SET(ENABLE_CPPPARSER OFF)
SET(ENABLE_POCODOC OFF)
SET(ENABLE_PAGECOMPILER OFF)
SET(ENABLE_PAGECOMPILER_FILE2PAGE OFF)

SET(FORCE_OPENSSL OFF)      # Force usage of OpenSSL even under windows
SET(ENABLE_TESTS OFF)       # Set to OFF|ON (default is OFF) to control build of POCO tests & samples
SET(POCO_STATIC ON)         # Set to OFF|ON (default is OFF) to control build of POCO as STATIC library
SET(POCO_UNBUNDLED OFF)     # Set to OFF|ON (default is OFF) to control linking dependencies as external

SET(POCO_BUILD_TYPE "Release")

add_subdirectory(thirdparty/poco)

#SET(OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl")

## \Experimental POCO

add_subdirectory(src)

IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(test)
ENDIF()

PS: Am I using the right approach or should I try to include and build Poco libraries and OpenSSL for Android differently? Main targets are Android and iOS devices and local macOS or Linux for development and testing.


Solution

  • While this issue is not yet solved by the way exposed above, I figured out that it works with conan packages by using the following combination:

    conanfile.py:

    requires = "OpenSSL/1.0.2r@conan/stable", "Poco/1.9.0@pocoproject/stable"
    

    ~/.conan/profiles/android

    # ------------------------------------------------------------------------------
    # PARAMETERS
    
        target_host=armv7a-linux-androideabi
        ar_host=arm-linux-androideabi
    
        api_level=21
        cc_compiler=clang
        cxx_compiler=clang++
    
    # ------------------------------------------------------------------------------
    
    [settings]
    
        os_build=Linux
        arch_build=x86_64
    
        compiler=clang
        compiler.version=8
        compiler.libcxx=libc++
        os=Android
        os.api_level=$api_level
        arch=armv7
    
        build_type=Release
    
    # ------------------------------------------------------------------------------
    
    [build_requires]
    
        android_ndk_installer/r19b@bincrafters/stable
    
    # ------------------------------------------------------------------------------
    
    [options]
    
        OpenSSL:shared=False
    
        OpenSSL:no_threads=False
        OpenSSL:no_zlib=False
        OpenSSL:no_asm=True
        OpenSSL:386=False
        OpenSSL:no_sse2=False
        OpenSSL:no_bf=False
        OpenSSL:no_cast=False
        OpenSSL:no_des=False
        OpenSSL:no_dh=False
        OpenSSL:no_cast=False
        OpenSSL:no_dsa=False
        OpenSSL:no_hmac=False
        OpenSSL:no_md2=False
        OpenSSL:no_md5=False
        OpenSSL:no_rc2=False
        OpenSSL:no_rc4=False
        OpenSSL:no_rc5=False
        OpenSSL:no_rsa=False
        OpenSSL:no_sha=False
    
        Poco:shared=False
    
        Poco:enable_tests=False
        Poco:cxx_14=True
        Poco:force_openssl=True
    
        Poco:enable_xml=True
        Poco:enable_json=True
        Poco:enable_mongodb=False
        Poco:enable_pdf=False
        Poco:enable_util=True
        Poco:enable_net=True
        Poco:enable_netssl=True
        Poco:enable_netssl_win=False
        Poco:enable_crypto=True
        Poco:enable_data=False
        Poco:enable_data_sqlite=False
        Poco:enable_data_mysql=False
        Poco:enable_data_odbc=False
        Poco:enable_sevenzip=False
        Poco:enable_zip=True
        Poco:enable_sevenzip=True
        Poco:enable_apacheconnector=False
        Poco:enable_cppparser=True
        Poco:enable_pocodoc=False
        Poco:enable_pagecompiler=False
        Poco:enable_pagecompiler_file2page=False