CMake Generator for IOS/Android projects?



  • Hi there,
    few days ago I downloaded and installed the new Qt 5.2.0 with QtCreator 3.0 with additional Support for IOS and Android mobile applications. I used the Wizard to build a pretty easy project for Android as well as for IOS using QML - it worked like charm with the provided emulators.

    The next step was trying to compile a much more bigger project that is actually maintained with CMake and was previously successfully compiled with QtCreator for all major desktop-like platforms (Win,Mac,Linux). I hoped, with the new QtCreator and it's powerful integration it would be easy o just compile our sources and get an IOS project just like the Wizard offers, but eventually got stuck in the middle of the process.

    When I open my top-level CMakeLists.txt with "Open File or Project" I'm only able to choose CMake-generators for Desktop applications. Is there a way tu persuade CMake and/or QtCreator to build a project using the IOS toolchain right now? If not, what would be the smoothest way to bring my CMake maintained QML application to compile with the provided IOS toolchain using QtCreator as IDE?

    Any help is appreciated!



  • Hi, Hyblade.
    Have you tried to create project for Xcode?
    If not, then you may run the following command:

    @cmake -G Xcode path_to_project@

    This one should generate 'your_project.xcodeproj' which you can open with Xcode.



  • Hey Alex,
    yes sure, I can use XCode generator to create an XCode project, but it only allows my to compile my sources for a Mac desktop application not an IOS application.



  • Hi Hyblade,

    I have a similar scenario and hope to be looking at this more in the coming weeks - I'd be keen to hear any progress you have made now or into the future.

    We have a large Qt4/CMake framework currently built for Win/Mac/Linux and the goal is to work out if we can also build and deploy to Android and iOS from a single codebase.

    From my searches so far the plan seems to be to look at the magic sauce QtCreator is currently producing for these platforms and figure out how to do it in CMake using these two toolchains
    https://code.google.com/p/ios-cmake/
    https://code.google.com/p/android-cmake/

    These post may also provide some leads to possibly contact for hints:
    http://lists.qt-project.org/pipermail/android-development/2013-May/000104.html
    https://groups.google.com/forum/#!topic/android-qt/etTTswePSdg

    I'll be sure to share any success (and failures) I have on this journey and would love to hear how you go as well. I've seen a few comments here and there to suggest figuring this out would be of interest to a number of people.

    All the best
    Matt



  • Hey Matt,
    nice to hear that other folks ran into the same issues as I did. I also did some research and stumbled across the two toolchains you mentioned. Unfortunately they did not resolve the issue alone since the toolchains do not reproduce the hole building toolchain which actually should result in a working ios/android application.

    My research took me as far as to say that there is - right now - no other way than to use QtCreator's capabilities to create ios/android application. The only problem is, that you cannot use any generator/toolchain combinations out of CMake to create a QtCreator project that would allow you to build for ios/android. The only way I was able to get things to work was creating .pro-files and configure them with QtCreator using the kits I needed to build for mobile devices.

    Since I didn't wanted to re-write/transform all my CMake-projekts into Qt-project-files I thought of a process that does most of the work.

    Here is what I did so far:

    1. I used the toolchain files https://code.google.com/p/ios-cmake/ and https://code.google.com/p/android-cmake/ to configure my CMake-Projects. (Note: I had to modify the ios toolchain file to use clang instead of forcing gcc/g++)

    2. Next I wrote some CMake macros that will automatically create a .pro files out auf a (generic) CMAKE_TARGET definition. This is used on all my executables.

    2.1 These macros will create .pro-files that contain all files that are needed for the compilation process of the executable project. Furthermore they will trigger (automatically) the compilation of the library part of the CMake project and link against the resulting libraries.

    2.2 It is essential that the compilation of the library part is done using the previously mentoined toolchain files that correspond to the compilation kit inside QtCreator (android/android-simulator/ios/ios-simulator) so that the linker can do it's work

    I have had some success with this approach, but the macros are way distant from perfect. If it helps I could share these macros/pro-file generator with you or start an github project where we can work on a feasible process together.



  • Here is the (essential) part of the macros:

    @
    macro(ADD_QT_PROJECT target_name qt_resources out_file_path)
    set(PRO_FILE_CONTENT)

    ADDING CONFIG AND TARGET NAME

    QMAKE_ADD_LINE(PRO_FILE_CONTENT "CONFIG += qt c++11 resources" )
    QMAKE_ADD_LINE(PRO_FILE_CONTENT "TARGET = ${target_name}" )
    QMAKE_ADD_LINE(PRO_FILE_CONTENT "QT += core gui network opengl sql svg xml widgets quick declarative" )

    set(TARGET_RC_FILES ${qt_resources})
    QMAKE_ADD_FILES(PRO_FILE_CONTENT TARGET_RC_FILES)

    SETTING UP TARGET TYPE

    get_target_property(TARGET_CMAKE_TYPE ${target_name} TYPE)
    if(${TARGET_CMAKE_TYPE} STREQUAL "EXECUTABLE")
    QMAKE_ADD_LINE(PRO_FILE_CONTENT "TEMPLATE = app")
    else()
    QMAKE_ADD_LINE(PRO_FILE_CONTENT "TEMPLATE = lib")
    endif()

    ADDING LINK SOURCES

    get_target_property(TARGET_SOURCES ${target_name} SOURCES)
    QMAKE_ADD_FILES(PRO_FILE_CONTENT TARGET_SOURCES)

    ADDING INCLUDE DIRECTORIES

    get_target_property(TARGET_INCLUDE_DIRECTORIES ${target_name} INCLUDE_DIRECTORIES)
    QMAKE_ADD_INCLUDE_DIRECTORIES(PRO_FILE_CONTENT TARGET_INCLUDE_DIRECTORIES)

    ADDING LINK DIRECTORIES

    get_property(TARGET_LINK_DIRECTORIES DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY LINK_DIRECTORIES)
    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_LINK_DIRECTORIES)

    get_target_property(TARGET_ARCHIVE_OUTPUT_DIRECTORY ${target_name} ARCHIVE_OUTPUT_DIRECTORY)
    get_target_property(TARGET_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${target_name} ARCHIVE_OUTPUT_DIRECTORY_DEBUG)
    get_target_property(TARGET_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${target_name} ARCHIVE_OUTPUT_DIRECTORY_RELEASE)
    get_target_property(TARGET_LIBRARY_OUTPUT_DIRECTORY ${target_name} LIBRARY_OUTPUT_DIRECTORY)
    get_target_property(TARGET_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${target_name} LIBRARY_OUTPUT_DIRECTORY_DEBUG)
    get_target_property(TARGET_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${target_name} LIBRARY_OUTPUT_DIRECTORY_RELEASE)

    if(${TARGET_ARCHIVE_OUTPUT_DIRECTORY_DEBUG} STREQUAL "TARGET_ARCHIVE_OUTPUT_DIRECTORY_DEBUG_NOTFOUND")
    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_ARCHIVE_OUTPUT_DIRECTORY_DEBUG)
    endif()
    if(${TARGET_ARCHIVE_OUTPUT_DIRECTORY_RELEASE} STREQUAL "TARGET_ARCHIVE_OUTPUT_DIRECTORY_RELEASE_NOTFOUND")
    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_ARCHIVE_OUTPUT_DIRECTORY_RELEASE)
    endif()
    if(${TARGET_LIBRARY_OUTPUT_DIRECTORY_DEBUG} STREQUAL "TARGET_LIBRARY_OUTPUT_DIRECTORY_DEBUG_NOTFOUND")
    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_LIBRARY_OUTPUT_DIRECTORY_DEBUG)
    endif()
    if(${TARGET_LIBRARY_OUTPUT_DIRECTORY_RELEASE} STREQUAL "TARGET_LIBRARY_OUTPUT_DIRECTORY_RELEASE_NOTFOUND")
    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_LIBRARY_OUTPUT_DIRECTORY_RELEASE)
    endif()

    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_ARCHIVE_OUTPUT_DIRECTORY)
    QMAKE_ADD_LINK_DIRECTORIES(PRO_FILE_CONTENT TARGET_LIBRARY_OUTPUT_DIRECTORY)

    ADDING LINK LIBRARIES

    get_target_property(TARGET_LINK_LIBRARIES ${target_name} LINK_LIBRARIES)
    QMAKE_ADD_TARGET_LINK_LIBRARIES(PRO_FILE_CONTENT TARGET_LINK_LIBRARIES)

    #get_target_property(TARGET_COMPILE_FLAGS ${target_name} COMPILE_FLAGS)
    #PRINT_TARGET_PROPERTY(${target_name} COMPILE_FLAGS)

    #get_target_property(TARGET_COMPILE_DEFINITIONS ${target_name} COMPILE_DEFINITIONS)
    #PRINT_TARGET_PROPERTY(${target_name} COMPILE_DEFINITIONS)

    #get_target_property(TARGET_RESOURCE ${target_name} COMPILE_DEFINITIONS_DEBUG)
    #PRINT_TARGET_PROPERTY(${target_name} COMPILE_DEFINITIONS_DEBUG)

    #get_target_property(TARGET_RESOURCE ${target_name} COMPILE_DEFINITIONS_RELEASE)
    #PRINT_TARGET_PROPERTY(${target_name} COMPILE_DEFINITIONS_RELEASE)

    #get_target_property(TARGET_RESOURCE ${target_name} LINK_FLAGS)
    #PRINT_TARGET_PROPERTY(${target_name} LINK_FLAGS)

    #get_target_property(TARGET_RESOURCE ${target_name} LINK_FLAGS_DEBUG)
    #PRINT_TARGET_PROPERTY(${target_name} LINK_FLAGS_DEBUG)

    #get_target_property(TARGET_RESOURCE ${target_name} LINK_FLAGS_RELEASE)
    #PRINT_TARGET_PROPERTY(${target_name} LINK_FLAGS_RELEASE)

    #get_target_property(TARGET_RESOURCE ${target_name} RESOURCE)
    #PRINT_TARGET_PROPERTY(${target_name} RESOURCE)

    RUNTIME

    get_target_property(TARGET_RUNTIME_OUTPUT_DIRECTORY ${target_name} RUNTIME_OUTPUT_DIRECTORY)
    #QMAKE_ADD_LINE(PRO_FILE_CONTENT "DESTDIR = ${TARGET_RUNTIME_OUTPUT_DIRECTORY}")
    QMAKE_ADD_LINE(PRO_FILE_CONTENT "system(cd ${PROJECT_BINARY_DIR} && make)")
    #QMAKE_ADD_LINE(PRO_FILE_CONTENT "# Please do not modify the following two lines. Required for deployment." )
    #QMAKE_ADD_LINE(PRO_FILE_CONTENT "include(qtquick2applicationviewer/qtquick2applicationviewer.pri)")
    #QMAKE_ADD_LINE(PRO_FILE_CONTENT "qtcAddDeployment()")

    #message(${PRO_FILE_CONTENT})
    file(WRITE ${out_file_path} ${PRO_FILE_CONTENT} )

    endmacro(ADD_QT_PROJECT)
    @



  • Hi Hyblade,

    Great to see you've at least created some sort of solution. I'd really be hoping to create a toolchain totally independent from QtCreator is possible. Maybe I'm going to have to try and do some digging through the creator source :(



  • If anyone else stumbles across this thread and also wishes they could build iOS and Android targets with CMake (as you can for desktop applications) then please vote for this feature request on Qt's bug tracker

    https://bugreports.qt-project.org/browse/QTBUG-36384



  • Hi Hyblade,

    I think I'm having exactly the same problem as you had. Trying to migrate a huge CMake-based project (compiled with Visual Syudio on PC) to a QtCreator-based project (to target Android). I could do that for a helloworld sample program by writting a pro file manually and am now investigating how to generate .pro files automatically.

    Your macro looks good so I wanted to try it. But you did not post all. I'm missing the QMAKE_ADD_* macros, can you post them too?

    Thanks

    Jean



  • Hi all,

    Is there an update to this? I'm very interested in this as well.



  • Hi Elador,

    With CMake, it's pretty easy to generate a .pro file manually. The syntax is very simple, only add your files and some keywords.

    I think today this is the best solution to compile CMake projects with QtCreator.

    Jean



  • Hi

    After being bored by writing duplicate .pro and CMake files for every new project, I ended up writing a CMake utility that combines every useful piece of code/information that I found on the subject. It uses an Android toolchain and the androidqtdeploy tool, to build and deploy APK files without QMake/QtCreator.

    This utility may be useful to anyone doing Qt/Android development with CMake. Don't hesitate to use or modify it freely.

    https://github.com/LaurentGomila/qt-android-cmake



  • Hi

    After being bored by writing duplicate .pro and CMake files for every new project, I ended up writing a CMake utility that combines every useful piece of code/information that I found on the subject. It uses an Android toolchain and the androidqtdeploy tool, to build and deploy APK files without QMake/QtCreator.

    This utility may be useful to anyone doing Qt/Android development with CMake. Don't hesitate to use or modify it freely.

    https://github.com/LaurentGomila/qt-android-cmake


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Looks pretty interesting ! Did you thought about contributing it to the Qt project ? That way more user may benefit from it


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Looks pretty interesting ! Did you thought about contributing it to the Qt project ? That way more user may benefit from it



  • I don't know if it would fit in the Qt project itself. Previous requests for a better CMake integration for Android were all rejected.

    Anyway, if someone wants to integrate it, I'll be happy to help.



  • I don't know if it would fit in the Qt project itself. Previous requests for a better CMake integration for Android were all rejected.

    Anyway, if someone wants to integrate it, I'll be happy to help.


  • Lifetime Qt Champion

    I'd say it's worth asking on the "android-development mailing list":http://lists.qt-project.org/mailman/listinfo/android-development :)


  • Lifetime Qt Champion

    I'd say it's worth asking on the "android-development mailing list":http://lists.qt-project.org/mailman/listinfo/android-development :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.