From fe730114224b05cab25f32607af69a80d7b660dd Mon Sep 17 00:00:00 2001 From: xiphon Date: Wed, 21 Oct 2020 16:19:26 +0000 Subject: [PATCH] cmake: Android cross compilation support --- CMakeLists.txt | 37 ++++++++++++++++++++++++++++++++----- src/CMakeLists.txt | 27 +++++++++++++++++++-------- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 197e7c30..c39e29c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,9 +149,11 @@ message(STATUS "libusb: include dir at ${LibUSB_INCLUDE_DIRS}") message(STATUS "libusb: libraries at ${LibUSB_LIBRARIES}") # HIDApi -find_package(HIDAPI REQUIRED) -message(STATUS "libhidapi: include dir at ${HIDAPI_INCLUDE_DIRS}") -message(STATUS "libhidapi: libraries at ${HIDAPI_LIBRARIES}") +if(NOT ANDROID) + find_package(HIDAPI REQUIRED) + message(STATUS "libhidapi: include dir at ${HIDAPI_INCLUDE_DIRS}") + message(STATUS "libhidapi: libraries at ${HIDAPI_LIBRARIES}") +endif() # Boost if(DEBUG) @@ -174,7 +176,7 @@ find_package(Boost 1.58 REQUIRED COMPONENTS program_options locale) -if(UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE AND NOT ANDROID) set(CMAKE_SKIP_RPATH ON) find_package(X11 REQUIRED) message(STATUS "X11_FOUND = ${X11_FOUND}") @@ -253,7 +255,15 @@ foreach(QT5_MODULE ${QT5_LIBRARIES}) include_directories(${${QT5_MODULE}_INCLUDE_DIRS}) endforeach() -pkg_check_modules(QT5_PKG_CONFIG REQUIRED ${QT5_LIBRARIES}) +if(NOT (CMAKE_CROSSCOMPILING AND ANDROID)) + pkg_check_modules(QT5_PKG_CONFIG REQUIRED ${QT5_LIBRARIES}) +else() + set(QT5_LIBRARIES_ABI) + foreach(QT5_MODULE ${QT5_LIBRARIES}) + list(APPEND QT5_LIBRARIES_ABI "${QT5_MODULE}_${CMAKE_ANDROID_ARCH_ABI}") + endforeach() + pkg_check_modules(QT5_PKG_CONFIG REQUIRED ${QT5_LIBRARIES_ABI}) +endif() if(QT5_PKG_CONFIG_FOUND) set(QT5_PKG_CONFIG "QT5_PKG_CONFIG") @@ -376,6 +386,23 @@ if(STATIC) endif() endif() +if(ANDROID) + set(QT5_EXTRA_LIBRARIES_LIST + GLESv2 + log + z + jnigraphics + android + EGL + Qt5VirtualKeyboard_${CMAKE_ANDROID_ARCH_ABI} + c++_shared + ) + foreach(LIBRARY ${QT5_EXTRA_LIBRARIES_LIST}) + find_library(${LIBRARY}_LIBRARY ${LIBRARY} PATHS "${ANDROID_TOOLCHAIN_ROOT}/sysroot/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/${ANDROID_PLATFORM_LEVEL}" REQUIRED) + list(APPEND QT5_LIBRARIES ${${LIBRARY}_LIBRARY}) + endforeach() +endif() + message(STATUS "Using Boost include dir at ${Boost_INCLUDE_DIRS}") message(STATUS "Using Boost libraries at ${Boost_LIBRARIES}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7822ee7..003dfe73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,13 +81,20 @@ if(APPLE) list(APPEND RESOURCES ${ICON}) endif() -add_executable(monero-wallet-gui ${EXECUTABLE_FLAG} main/main.cpp +set(monero_wallet_gui_sources ${SOURCE_FILES} ${PASS_STRENGTH_FILES} ${QR_CODE_FILES} ${RESOURCES} ) +if(NOT ANDROID) + add_executable(monero-wallet-gui ${EXECUTABLE_FLAG} ${monero_wallet_gui_sources}) +else() + add_library(monero-wallet-gui SHARED ${monero_wallet_gui_sources}) + set_target_properties(monero-wallet-gui PROPERTIES COMPILE_DEFINITIONS "ANDROID") +endif() + set_target_properties(monero-wallet-gui PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" MACOSX_BUNDLE TRUE @@ -164,13 +171,17 @@ if(X11_FOUND) endif() if(WITH_SCANNER) - target_link_libraries(monero-wallet-gui - ${ZBAR_LIBRARIES} - jpeg - v4l2 - v4lconvert - rt - ) + if(NOT ANDROID) + target_link_libraries(monero-wallet-gui + ${ZBAR_LIBRARIES} + jpeg + v4l2 + v4lconvert + rt + ) + else() + target_link_libraries(monero-wallet-gui ${ZBAR_LIBRARIES}) + endif() endif() add_custom_command(TARGET monero-wallet-gui POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ $)