Ubuntu IDE tries to run CMake-based ARM projects on desktop instead of device: bug or what?
I have imported CMake-based project into Ubuntu IDE. It uses plain C++ with no QML components. When I try to run it, it does not deploy to device, but runs on desktop (unsuccessfully, reporting it can't find armhf ld library), even though I selected armhf SDK and in Kits tab, my device is selected for current kit, and tooltip in lower-left corner shows that app is going to be installed on device.
When I open Run tab in Project settings, my CMake-based project differs from QMake-based projects in that it has "Command Line Arguments" and "Current Working Directory" fields, but do not "Override app if installed" and "Uninstall app after debugging" (I don't remember exact text now). From this, I conclude that Ubuntu IDE sees my app not as Ubuntu Touch targeted, but as Desktop-targeted. What marks a CMake-based project as Ubuntu Touch targeted fomr IDE?
Is it even possible to run CMake-based project without QML on device? SDK does not have template for this use-case: all CMake-based templates use QML, and the only plain C++ project (QtQuick App) uses QMake.
I have no such problems with QMake-based projects, and presently I use CMake to build a library instead of executable, and then link it into executable with dummy QMake project. But it seems like a kludge.
22 Answers
Ok, so if you are using the desktop Kit and cmake complains about that it cannot find armhf tools, you probably did not have cmake installed on the desktop in the first place (there is a problem with dependencies that we are trying to solve atm) and QtCreator is using a cmake installation from one of the click chroots you have created for device support.
So what to do:
- Close Ubuntu SDK IDE
- Install cmake "apt install cmake"
- Start Ubuntu SDK IDE
- go to: Options -> Build & Run and click the CMake tab
- make sure /usr/bin/cmake is selected as the default
- Open the Kits tab, there select your Desktop Kit and make sure that /usr/bin/cmake is used as the cmake tool.
- Delete the buildfolders for your projects and build again
There is no need to change the Kits for the devices since these are automatically checked on each start.
If you want to package your own cmake project you need to make sure that it is packaged correctly for the phone. Your best bet is to check out one of the original ubuntu SDK templates to see how it is done.
4OK, after a lot of experiments, I found what I did wrong.
So, to make Ubuntu IDE create a configuration that runs your CMake-based project on device, all you need is to have UBUNTU_MANIFEST_FILE variable to be set in your CMakeLists.txt, AND it needs explicitly to be marked CACHE INTERNAL. It's kind of obvious when you know how Ubuntu QtCreator plug-in works, but otherwise, not so much.
So, just add
set(UBUNTU_MANIFEST_PATH "manifest.json" CACHE INTERNAL "Path to manifest file")to your CMakeLists.txt and you're NEARLY good.
However, I also encountered a problem that this won't work if I specify "${CMAKE_SOURCE_DIR}/manifest.json" as UBUNTU_MANIFEST_PATH, even though the file is exactly there.
The bad part, is that Ubuntu IDE still will create TWO run configurations for project. The first one, the default one, which has name based on your executable target's name, will still try to run armhf code on desktop. I think it's a bug.
The second one has name that depends on what you written in "hooks" section of your .desktop file. If that name equals with executable name, then that configuration will have "2" added to it (i.e. cmake_test2). This second configuration is the one to use - it runs project on device, but you have to choose it in "Run" section of "Projects" page - by default, the wrong run configuration is selected.
All in all, it seems like CMake support in Ubuntu IDE is still kinda fragile/buggy.