Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Build CMake based project for Android/iOS using QtCreator

Tags:

c++

android

ios

qt

I have created a Non-Qt C++ (CMake) project using Qt, and I am able to build it using MinGW, MSVC compiler.

So in short, when I am opening my test project I can select the generators under Run CMake Window. I have issue with other platforms.

When I am trying to Add a kit for Android, there are no generators available in the list. I tried the same thing on Macbook, there also the same problem.

I need help on this issue, I couldn't get the proper steps to build the CMake based project for Android/iOS using QtCreator.

P.S. Installed CMake version is 3.2.1 and Qt Version is 5.5, I have installed Android SDK, NDK , and and Java

like image 347
user3567711 Avatar asked Oct 29 '15 07:10

user3567711


People also ask

How do you use CMake Qtcreator?

Qt Creator uses the default CMake if it does not have enough information to choose the CMake to use. To set the selected CMake executable as the default, select Make Default. To remove the selected CMake executable from the list, select Remove. Select the Kits tab to add the CMake tool to a build and run kit.

What is .CMake file?

CMake is an open-source, cross-platform tool that uses compiler and platform independent configuration files to generate native build tool files specific to your compiler and platform. The CMake Tools extension integrates Visual Studio Code and CMake to make it easy to configure, build, and debug your C++ project.


1 Answers

I would love to tell you "just check this box in the options dialog and it will work", but, unfortunately, there is no generator that you can use to build an Android/iOS project from a CMakeLists.txt file.

I found alternatives, in all cases, I don't think your have a chance to port a whole huge CMake-based project that used to work on Windows (with lots of libraries and 3rd party libraries) work on Android in less than a few days of work....;-)

  • Personnaly, I wrote a small CMake function generating the .pro file manually from my CMake scripts. It started small but is now huge and it's difficult to share it with you. But, basically, I started from this post on a Qt forum. It creates a simple .pro file that does not work that bad and then you can extend it for your own needs. I like this solution because I have full control on generated .pro file (mine can now build on PC, Android and iOS...but I had a hard time to have this fully work).

  • Apparently, there's also a way to add a Qt-android CMake support using this open source stuff: https://github.com/LaurentGomila/qt-android-cmake. But I never tried it. You may want to have a look to it. If it works, it may be more convenient that writting your own script generating .pro files. Apparently, it builds an Android apk using androidqtdeploy but without using QtCreator. There's also an iOS support.

  • Finally, the best may be to have CMake propose a QtCreator "generator" (it would generate .pro files, like CMake generates sln/vcproj files when using Visual Studio generator or makefiles for g++ generator....), but there is no such generator supported. I reported this to CMake team some time ago hoping they could fix that. I understood that there was and would be no plan to do that because CMake targets only "compilers" as "generators" and "QtCreator" is not really a "compiler", it's a "IDE" using external "compilers" to build (MinGW, MSVC, CLang, Android's NDK g++...). It's a shame because CMake known all your project information and could easily generate a .pro file....so, as, CMake is opensource, one may extend CMake with a custom QtCreator file generator...and share it with the whole world,it would be wonderful!

Hope this will help you!

like image 141
jpo38 Avatar answered Nov 14 '22 21:11

jpo38