diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cabbe05..06e870f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,226 +1,225 @@ #============================================================================= # Copyright 2011 Alex Neundorf # Copyright 2014-2015 Alex Merry # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #============================================================================= # We need to set a language to find CMake packages installed in # architecture-dependent locations (like /usr/lib64). # We only set this for the tests, making sure it does not interfere # with other files (as ECM itself is architecture-independent). project(ECMTests C) find_package(Qt5LinguistTools CONFIG) set_package_properties( Qt5LinguistTools PROPERTIES URL "http://www.qt.io/" DESCRIPTION "Qt5 linguist tools." TYPE OPTIONAL PURPOSE "Required to run tests for the ECMPoQmTools module." ) find_package(Qt5Core CONFIG) set_package_properties( Qt5Core PROPERTIES URL "http://www.qt.io/" DESCRIPTION "Qt5 core library." TYPE OPTIONAL PURPOSE "Required to run tests for the ECMQtDeclareLoggingCategory module, and for some tests of the KDEInstallDirs module." ) add_subdirectory(ECMAddTests) add_subdirectory(ECMGenerateHeadersTest) add_subdirectory(ECMSetupVersionTest) add_subdirectory(ECMGeneratePkgConfigFile) -add_subdirectory(ECMToolchainAndroidTest) # a macro for tests that have a simple format where the name matches the # directory and project macro(add_test_variant NAME BASE COMMAND) string(REPLACE "." "/" src_dir "${BASE}") string(REPLACE "." "/" build_dir "${NAME}") string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}") add_test(${NAME} ${CMAKE_CTEST_COMMAND} --build-and-test "${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}" "${CMAKE_CURRENT_BINARY_DIR}/${build_dir}" --build-two-config --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-project ${proj} ${${NAME}_EXTRA_OPTIONS} --test-command ${COMMAND} ${ARGN}) endmacro() macro(add_test_macro NAME) add_test_variant("${NAME}" "${NAME}" ${ARGN}) endmacro() list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/find-modules) # Skip if PyQt not available find_file(SIP_Qt5Core_Mod_FILE NAMES QtCoremod.sip PATH_SUFFIXES share/sip/PyQt5/QtCore ) if(NOT SIP_Qt5Core_Mod_FILE) message(STATUS "WARNING: skipping tests that require PyQt") else() find_package(PythonModuleGeneration) foreach(pyversion 2 3) if (GPB_PYTHON${pyversion}_COMMAND) if (pythonCommands) list(APPEND pythonCommands " && ") endif() set(pythonCommands ${GPB_PYTHON${pyversion}_COMMAND} "${CMAKE_CURRENT_SOURCE_DIR}/GenerateSipBindings/testscript.py" "${CMAKE_CURRENT_BINARY_DIR}/GenerateSipBindings/py${pyversion}" ) endif() endforeach() if (pythonCommands) add_test_macro(GenerateSipBindings ${pythonCommands}) else() message(STATUS "WARNING: skipping GenerateSipBindings test") endif() endif() add_test_macro(ExecuteCoreModules dummy) add_test_macro(ExecuteKDEModules dummy) add_test_macro(KDEFetchTranslations dummy) add_test_macro(KDEInstallDirsTest.relative_or_absolute dummy) add_test_variant(KDEInstallDirsTest.vars_in_sync_no_args KDEInstallDirsTest.vars_in_sync dummy) add_test_macro(KDEInstallDirsTest.not_cache_variable dummy) set(KDEInstallDirsTest.vars_in_sync_kde_arg_EXTRA_OPTIONS --build-options -DKDE_INSTALL_BINDIR=altbin -DBINDIR_expected_value=altbin -DCMAKE_WARN_DEPRECATED=TRUE ) add_test_variant(KDEInstallDirsTest.vars_in_sync_kde_arg KDEInstallDirsTest.vars_in_sync dummy) set(KDEInstallDirsTest.vars_in_sync_cmake_arg_EXTRA_OPTIONS --build-options -DCMAKE_INSTALL_BINDIR=altbin -DBINDIR_expected_value=altbin -DCMAKE_WARN_DEPRECATED=TRUE ) add_test_variant(KDEInstallDirsTest.vars_in_sync_cmake_arg KDEInstallDirsTest.vars_in_sync dummy) set(KDEInstallDirsTest.vars_in_sync_oldstyle_arg_EXTRA_OPTIONS --build-options -DBIN_INSTALL_DIR=altbin -DBINDIR_expected_value=altbin -DCMAKE_WARN_DEPRECATED=TRUE ) add_test_variant(KDEInstallDirsTest.vars_in_sync_oldstyle_arg KDEInstallDirsTest.vars_in_sync dummy) set(KDEInstallDirsTest.relative_or_absolute_usr_EXTRA_OPTIONS --build-options -DCMAKE_INSTALL_PREFIX=/usr -DKDE_INSTALL_USE_QT_SYS_PATHS=FALSE -DAUTOSTARTDIR_should_be_absolute=TRUE -DCONFDIR_should_be_absolute=TRUE -DSYSCONFDIR_should_be_absolute=TRUE ) add_test_variant(KDEInstallDirsTest.relative_or_absolute_usr KDEInstallDirsTest.relative_or_absolute dummy) if (TARGET Qt5::qmake) set(KDEInstallDirsTest.relative_or_absolute_qt_EXTRA_OPTIONS --build-options -DKDE_INSTALL_USE_QT_SYS_PATHS=TRUE -DPLUGINDIR_should_be_absolute=TRUE -DQMLDIR_should_be_absolute=TRUE -DQTQCHDIR_should_be_absolute=TRUE -DQTPLUGINDIR_should_be_absolute=TRUE -DQTQUICKIMPORTSDIR_should_be_absolute=TRUE ) add_test_variant(KDEInstallDirsTest.relative_or_absolute_qt KDEInstallDirsTest.relative_or_absolute dummy) endif () if (Qt5Core_FOUND) add_test_macro(ECMQtDeclareLoggingCategoryTest testmain) endif() add_test_macro(FindModules dummy) add_test_macro(UseFindModules dummy) set(ECMAddAppIconTest_EXTRA_OPTIONS --build-target all --build-options "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMAddAppIconTest/InstallDirectory" ) add_test_macro(ECMAddAppIconTest ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMAddAppIconTest/check_files.cmake" ) set(ECMInstallIconsTest_EXTRA_OPTIONS --build-target install --build-options "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMInstallIconsTest/InstallDirectory" ) add_test_macro(ECMInstallIconsTest ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMInstallIconsTest/check_tree.cmake" ) add_test_macro(ECMToolchainAndroidTest dummy) set(KDEPackageAppTemplatesTest_EXTRA_OPTIONS --build-target install --build-options "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/KDEPackageAppTemplatesTest/InstallDirectory" ) add_test_macro(KDEPackageAppTemplatesTest ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/KDEPackageAppTemplatesTest/check.cmake" ) if (Qt5Core_FOUND AND Qt5LinguistTools_FOUND) set(ECMPoQmToolsTest_EXTRA_OPTIONS --build-target install --build-options "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMPoQmToolsTest/InstallDirectory" ) add_test_macro(ECMPoQmToolsTest ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMPoQmToolsTest/check.cmake" ) endif() find_package(Qt5Quick CONFIG) set_package_properties( Qt5Quick PROPERTIES URL "http://www.qt.io/" DESCRIPTION "Qt5 Quick library." TYPE OPTIONAL PURPOSE "Required to run tests for the ECMQMLModules module." ) if (TARGET Qt5::Quick) add_test_macro(ECMQMLModules dummy) endif() diff --git a/tests/ECMToolchainAndroidTest/CMakeLists.txt b/tests/ECMToolchainAndroidTest/CMakeLists.txt deleted file mode 100644 index eb2ae29..0000000 --- a/tests/ECMToolchainAndroidTest/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -project(AndroidToolchainTest) -cmake_minimum_required(VERSION 2.8.12) - -set(CMAKE_MODULE_PATH - ${CMAKE_CURRENT_SOURCE_DIR}/../../modules - ${CMAKE_CURRENT_SOURCE_DIR}/../../toolchain -) - -set(TARGET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/testlinkfile") -set(TARGET_NAME "testtarget") -set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/androidtest_output.txt") -set(INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/testlinkfile/outputfake.json") - -# test correct include resolution -include(specifydependencies) - -file(READ "${OUTPUT_FILE}" TEST_RESULT) -string(FIND ${TEST_RESULT} "libKF5Attica.so" CMP_RESULT) -if (${CMP_RESULT} EQUAL -1) - message(SEND_ERROR "Could not find relative library libKF5Attica.so") -endif() - -add_executable(dummy main.c) diff --git a/tests/ECMToolchainAndroidTest/main.c b/tests/ECMToolchainAndroidTest/main.c deleted file mode 100644 index c13815c..0000000 --- a/tests/ECMToolchainAndroidTest/main.c +++ /dev/null @@ -1,4 +0,0 @@ -int main() -{ - return 0; -} diff --git a/tests/ECMToolchainAndroidTest/testlinkfile/CMakeFiles/testtarget.dir/link.txt b/tests/ECMToolchainAndroidTest/testlinkfile/CMakeFiles/testtarget.dir/link.txt deleted file mode 100644 index 17da75d..0000000 --- a/tests/ECMToolchainAndroidTest/testlinkfile/CMakeFiles/testtarget.dir/link.txt +++ /dev/null @@ -1 +0,0 @@ -/usr/bin/c++ -pipe -DQT_STRICT_ITERATORS -DQURL_NO_CAST_FROM_STRING -DQT_NO_HTTP -DQT_NO_FTP -Wformat -Werror=format-security -Werror=return-type -Wno-variadic-macros -Wlogical-op -std=c++0x -fno-exceptions -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -pedantic -g -Wl,--enable-new-dtags CMakeFiles/persontest.dir/persontest.cpp.o CMakeFiles/persontest.dir/persontest_automoc.cpp.o -o testtarget -rdynamic /opt/qt5/qtbase/lib/libQt5Test.so.5.6.1 ../src/libKF5Attica.so.5.23.0 /opt/qt5/qtbase/lib/libQt5Network.so.5.6.1 /opt/qt5/qtbase/lib/libQt5Core.so.5.6.1 -Wl,-rpath,/opt/qt5/qtbase/lib:/opt/kde/build/frameworks/attica/src diff --git a/tests/ECMToolchainAndroidTest/testlinkfile/outputfake.json b/tests/ECMToolchainAndroidTest/testlinkfile/outputfake.json deleted file mode 100644 index cf482d0..0000000 --- a/tests/ECMToolchainAndroidTest/testlinkfile/outputfake.json +++ /dev/null @@ -1 +0,0 @@ -##EXTRALIBS## diff --git a/toolchain/Android.cmake b/toolchain/Android.cmake index 3c587fa..3069061 100644 --- a/toolchain/Android.cmake +++ b/toolchain/Android.cmake @@ -1,258 +1,258 @@ #.rst: # AndroidToolchain # ---------------- # # Enable easy compilation of cmake projects on Android. # # By using this android toolchain, the projects will be set up to compile the # specified project targeting an Android platform, depending on its input. # Furthermore, if desired, an APK can be directly generated by using the # `androiddeployqt `_ tool. # # .. note:: # # This module requires CMake 3.1. # # Since 1.7.0. # # Usage # ===== # # To use this file, you need to set the ``CMAKE_TOOLCHAIN_FILE`` to point to # ``AndroidToolchain.cmake`` on the command line:: # # cmake -DCMAKE_TOOLCHAIN_FILE=/usr/share/ECM/toolchain/AndroidToolchain.cmake # # You will also need to provide the locations of the Android NDK and SDK. This # can be done on the commandline or with environment variables; in either case # the variable names are: # # ``ANDROID_NDK`` # The NDK root path. # ``ANDROID_SDK_ROOT`` # The SDK root path. # # Additional options are specified as cache variables (eg: on the command line): # # ``ANDROID_ARCHITECTURE`` # The architecture to compile for. Default: ``arm``. # ``ANDROID_TOOLCHAIN`` # The toolchain to use. See the ``toolchains`` directory of the NDK. # Default: ``arm-linux-androideabi``. # ``ANDROID_ABI`` # The ABI to use. See the ``sources/cxx-stl/gnu-libstdc++/*/libs`` # directories in the NDK. Default: ``armeabi-v7a``. # ``ANDROID_GCC_VERSION`` # The GCC version to use. Default: ``4.9``. # ``ANDROID_API_LEVEL`` # The `API level # `_ # to require. Default: ``14``. # ``ANDROID_SDK_BUILD_TOOLS_REVISION`` # The build tools version to use. Default: ``21.1.1``. # # For integrating other libraries which are not part of the Android toolchain, # like Qt5, and installed to a separate prefix on the host system, the install # prefixes of those libraries would be passed as alternative roots as list via # ``ECM_ADDITIONAL_FIND_ROOT_PATH``. Since 5.30.0. # # For example, for integrating a Qt5 for Android with armv7 target present at # ``/opt/android/Qt5/5.7/android_armv7`` and some other libraries installed to # the prefix ``/opt/android/foo``, you would use:: # # cmake \ # -DCMAKE_TOOLCHAIN_FILE=/usr/share/ECM/toolchain/AndroidToolchain.cmake \ # -DECM_ADDITIONAL_FIND_ROOT_PATH="/opt/android/Qt5/5.7/android_armv7;/opt/android/foo" # # If your project uses ``find_package()`` to locate build tools on the host # system, make sure to pass ``CMAKE_FIND_ROOT_PATH_BOTH`` or # ``NO_CMAKE_FIND_ROOT_PATH`` as argument in the call. See the # ``find_package()`` documentation for more details. # # Deploying Qt Applications # ========================= # # After building the application, you will need to generate an APK that can be # deployed to an Android device. This module integrates androiddeployqt support # to help with this for Qt-based projects. To enable this, set the # ``QTANDROID_EXPORTED_TARGET`` variable to the target you wish to export as an # APK, as well as ``ANDROID_APK_DIR`` to a directory containing some basic # information. This will create a ``create-apk-`` target that will # generate the APK file. See the `Qt on Android deployment documentation # `_ for more information. # # For example, you could do:: # # cmake \ # -DCMAKE_TOOLCHAIN_FILE=/usr/share/ECM/toolchain/AndroidToolchain.cmake \ # -DQTANDROID_EXPORTED_TARGET=myapp \ # -DANDROID_APK_DIR=myapp-apk # make # make create-apk-myapp # # The APK would then be found in ``myapp_build_apk/bin`` in the build directory. # # The create-apk-myapp target will be able to take an ARGS parameter with further # arguments for androiddeployqt. For example, one can use:: # # make create-apk-myapp ARGS="--install" # # To install the apk to test. To generate a signed apk, one can do it with the # following syntax:: # # make create-apk-myapp ARGS="--sign ~/my.keystore alias_name" # # See Android documentation on how to create a keystore to use # ============================================================================= # Copyright 2014 Aleix Pol i Gonzalez # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cmake_minimum_required(VERSION "3.1") #input set(ANDROID_NDK "$ENV{ANDROID_NDK}" CACHE path "Android NDK path") set(ANDROID_SDK_ROOT "$ENV{ANDROID_SDK_ROOT}" CACHE path "Android SDK path") set(ANDROID_ARCHITECTURE "arm" CACHE string "Used Architecture, related to the ABI and TOOLCHAIN") set(ANDROID_TOOLCHAIN "arm-linux-androideabi" CACHE string "Used SDK") set(ANDROID_ABI "armeabi-v7a" CACHE string "Used ABI") set(ANDROID_GCC_VERSION "4.9" CACHE string "Used GCC version" ) set(ANDROID_API_LEVEL "14" CACHE string "Android API Level") set(ANDROID_SDK_BUILD_TOOLS_REVISION "21.1.1" CACHE string "Android API Level") set(_HOST "${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}") string(TOLOWER "${_HOST}" _HOST) get_filename_component(_CMAKE_ANDROID_DIR "${CMAKE_TOOLCHAIN_FILE}" PATH) cmake_policy(SET CMP0011 OLD) cmake_policy(SET CMP0017 OLD) set(CMAKE_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_ARCHITECTURE}") if(NOT EXISTS ${CMAKE_SYSROOT}) message(FATAL_ERROR "Couldn't find the Android NDK Root in ${CMAKE_SYSROOT}") endif() #actual code SET(CMAKE_SYSTEM_NAME Android) SET(CMAKE_SYSTEM_VERSION 1) if (NOT DEFINED ECM_ADDITIONAL_FIND_ROOT_PATH) SET(ECM_ADDITIONAL_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH}) endif() SET(CMAKE_FIND_ROOT_PATH ${ANDROID_NDK} ${ECM_ADDITIONAL_FIND_ROOT_PATH}) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN}-${ANDROID_GCC_VERSION}/prebuilt/${_HOST}/bin") set(ANDROID_LIBS_ROOT "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}") # includes include_directories(SYSTEM "${CMAKE_SYSROOT}/usr/include" "${ANDROID_LIBS_ROOT}/include/" "${ANDROID_LIBS_ROOT}/libs/${ANDROID_ABI}/include" ) # libraries set(ANDROID_LIBRARIES_PATH "${CMAKE_SYSROOT}/usr/lib") set(CMAKE_SYSTEM_LIBRARY_PATH ${ANDROID_LIBRARIES_PATH} "${ANDROID_LIBS_ROOT}/libs/${ANDROID_ABI}/" ) set(CMAKE_FIND_LIBRARY_SUFFIXES ".so") set(CMAKE_FIND_LIBRARY_PREFIXES "lib") # Settling hard on gnustl_shared as C++ helper runtime for now, # given this is most similar to what is on GNU/Linux, which is what # the average software targetted by this toolchain is built against otherwise. # If requested by devs, the used helper runtime could be made an option later. # Related info: https://developer.android.com/ndk/guides/cpp-support.html find_library(GNUSTL_SHARED gnustl_shared) if(NOT GNUSTL_SHARED) message(FATAL_ERROR "Selected Android platform does not provide gnustl_shared: ${CMAKE_SYSTEM_LIBRARY_PATH}") endif() link_directories(${CMAKE_SYSTEM_LIBRARY_PATH}) set(CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN}-gcc") set(CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN}-g++") set(CMAKE_EXE_LINKER_FLAGS "${GNUSTL_SHARED} -Wl,-rpath-link,${ANDROID_LIBRARIES_PATH} -llog -lz -lm -ldl -lc -lgcc" CACHE STRING "") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "") #we want executables to be shared libraries, hooks will invoke the exported cmake function set(CMAKE_CXX_LINK_EXECUTABLE " -o " ) # needed for Qt to define Q_OS_ANDROID add_definitions(-DANDROID) set(ECM_DIR "${CMAKE_CURRENT_LIST_DIR}/../cmake" CACHE STRING "") ######### generation set(CREATEAPK_TARGET_NAME "create-apk-${QTANDROID_EXPORTED_TARGET}") # Need to ensure we only get in here once, as this file is included twice: # from CMakeDetermineSystem.cmake and from CMakeSystem.cmake generated within the # build directory. if(DEFINED QTANDROID_EXPORTED_TARGET AND NOT TARGET ${CREATEAPK_TARGET_NAME}) if(NOT DEFINED ANDROID_APK_DIR) message(FATAL_ERROR "Define an apk dir to initialize from using -DANDROID_APK_DIR=. The specified directory must contain the AndroidManifest.xml file.") elseif(NOT EXISTS "${ANDROID_APK_DIR}/AndroidManifest.xml") message(FATAL_ERROR "Cannot find ${ANDROID_APK_DIR}/AndroidManifest.xml according to ANDROID_APK_DIR") endif() find_package(Qt5Core REQUIRED) set(EXPORT_DIR "${CMAKE_BINARY_DIR}/${QTANDROID_EXPORTED_TARGET}_build_apk/") set(EXECUTABLE_DESTINATION_PATH "${EXPORT_DIR}/libs/${ANDROID_ABI}/lib${QTANDROID_EXPORTED_TARGET}.so") configure_file("${_CMAKE_ANDROID_DIR}/deployment-file.json.in" "${QTANDROID_EXPORTED_TARGET}-deployment.json.in") if (CMAKE_GENERATOR STREQUAL "Unix Makefiles") set(arguments "\\$(ARGS)") endif() add_custom_target(${CREATEAPK_TARGET_NAME} COMMAND cmake -E echo "Generating $ with $/androiddeployqt" COMMAND cmake -E remove_directory "${EXPORT_DIR}" COMMAND cmake -E copy_directory "${ANDROID_APK_DIR}" "${EXPORT_DIR}" COMMAND cmake -E copy "$" "${EXECUTABLE_DESTINATION_PATH}" - COMMAND cmake -DINPUT_FILE="${QTANDROID_EXPORTED_TARGET}-deployment.json.in" -DOUTPUT_FILE="${QTANDROID_EXPORTED_TARGET}-deployment.json" "-DTARGET_DIR=$" "-DTARGET_NAME=${QTANDROID_EXPORTED_TARGET}" "-DEXPORT_DIR=${CMAKE_INSTALL_PREFIX}" -P ${_CMAKE_ANDROID_DIR}/specifydependencies.cmake + COMMAND LANG=C cmake -DINPUT_FILE="${QTANDROID_EXPORTED_TARGET}-deployment.json.in" -DOUTPUT_FILE="${QTANDROID_EXPORTED_TARGET}-deployment.json" "-DTARGET=$" "-DOUTPUT_DIR=$" "-DEXPORT_DIR=${CMAKE_INSTALL_PREFIX}" "-DECM_ADDITIONAL_FIND_ROOT_PATH=\"${ECM_ADDITIONAL_FIND_ROOT_PATH}\"" -P ${_CMAKE_ANDROID_DIR}/specifydependencies.cmake COMMAND $/androiddeployqt --gradle --input "${QTANDROID_EXPORTED_TARGET}-deployment.json" --output "${EXPORT_DIR}" --deployment bundled ${arguments} ) add_custom_target(install-apk-${QTANDROID_EXPORTED_TARGET} COMMAND adb install -r "${EXPORT_DIR}/build/outputs/apk/${QTANDROID_EXPORTED_TARGET}_build_apk-debug.apk" ) else() message(STATUS "You can export a target by specifying -DQTANDROID_EXPORTED_TARGET=") endif() diff --git a/toolchain/specifydependencies.cmake b/toolchain/specifydependencies.cmake index 65e875b..8965d6d 100644 --- a/toolchain/specifydependencies.cmake +++ b/toolchain/specifydependencies.cmake @@ -1,45 +1,47 @@ -file(READ "${TARGET_DIR}/CMakeFiles/${TARGET_NAME}.dir/link.txt" out) +execute_process(COMMAND readelf --wide --dynamic ${TARGET} ERROR_VARIABLE readelf_errors OUTPUT_VARIABLE out RESULT_VARIABLE result) -string(FIND "${out}" "-o ${TARGET_NAME}" POS) #we trim the initial arguments, we want the ones in the end. we find the target -string(SUBSTRING "${out}" ${POS} -1 out) #we -string(REGEX MATCHALL "(/|\\.\\./|\\./)[^ ]+\\.so" outout "${out}") -string(STRIP "${outout}" outout) -string(REPLACE " /" ";/" outout "${outout}") +if (NOT result EQUAL 0) + message(FATAL_ERROR "readelf failed on ${TARGET} exit(${result}): ${readelf_errors}") +endif() +string(REPLACE "\n" ";" lines "${out}") set(extralibs) -foreach(lib IN LISTS outout) #now we filter Qt5 libraries, because Qt wants to take care about these itself - if(NOT ${lib} MATCHES ".*/libQt5.*") - # resolve relative paths - if(${lib} MATCHES "^(\\.\\./|\\./)") - set(lib "${TARGET_DIR}/${lib}") - endif() - if(extralibs) - set(extralibs "${extralibs},${lib}") +foreach(line ${lines}) + string(REGEX MATCH ".*\\(NEEDED\\) +Shared library: +\\[(.+)\\]$" matched ${line}) + set(currentLib ${CMAKE_MATCH_1}) + + if(NOT ${currentLib} MATCHES "libQt5.*" AND matched) + find_file(ourlib-${currentLib} ${currentLib} HINTS ${OUTPUT_DIR} ${EXPORT_DIR} ${ECM_ADDITIONAL_FIND_ROOT_PATH} NO_DEFAULT_PATH PATH_SUFFIXES lib) + + if(ourlib-${currentLib}) + list(APPEND extralibs "${ourlib-${currentLib}}") else() - set(extralibs "${lib}") + message(STATUS "could not find ${currentLib} in ${OUTPUT_DIR} ${EXPORT_DIR}/lib/ ${ECM_ADDITIONAL_FIND_ROOT_PATH}") endif() endif() endforeach() + if(extralibs) - set(extralibs "\"android-extra-libs\": \"${extralibs}\",") + string(REPLACE ";" "," libs "${extralibs}") + set(extralibs "\"android-extra-libs\": \"${libs}\",") endif() set(extraplugins) foreach(folder "share" "lib/qml") #now we check for folders with extra stuff set(plugin "${EXPORT_DIR}/${folder}") if(EXISTS "${plugin}") if(extraplugins) set(extraplugins "${extraplugins},${plugin}") else() set(extraplugins "${plugin}") endif() endif() endforeach() if(extraplugins) set(extraplugins "\"android-extra-plugins\": \"${extraplugins}\",") endif() file(READ "${INPUT_FILE}" CONTENTS) string(REPLACE "##EXTRALIBS##" "${extralibs}" NEWCONTENTS "${CONTENTS}") string(REPLACE "##EXTRAPLUGINS##" "${extraplugins}" NEWCONTENTS "${NEWCONTENTS}") file(WRITE "${OUTPUT_FILE}" ${NEWCONTENTS})