Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generator expressions for target locations; add LLVM/clang toolchain support. #27

Closed
wants to merge 6 commits into from

Conversation

nohype
Copy link

@nohype nohype commented Feb 6, 2019

Fix issue #26:

  • Replace the use of LOCATION properties by generator expressions to acquire dependency target locations.
  • Add an extra file(GENERATOR) call to evaluate generator expressions at build time.

Julian Weiß added 2 commits February 6, 2019 15:47
Fix issue LaurentGomila#26:
- Replace the use of LOCATION properties by generator expressions to acquire dependency target locations.
- Add an extra file(GENERATOR) call to evaluate generator expressions at build time.
@nohype
Copy link
Author

nohype commented Feb 7, 2019

Added support for the LLVM/clang toolchain. Since NDK r19, it seems to be the default and androiddeployqt fails when trying to use the gcc tool and toolchain paths.

idelsink added a commit to derpicated/articated that referenced this pull request Feb 10, 2019
This branch has support for the newest LLVM toolchain
Waiting on the pr of LaurentGomila/qt-android-cmake#27
@nohype nohype changed the title Use generator expressions for target locations. Use generator expressions for target locations; add LLVM/clang toolchain support. Feb 12, 2019
nohype and others added 4 commits February 15, 2019 16:15
Instead of the (DEBUG_)LOCATION property, use generator expressions to determine the app's target file path (main shared library).
Fixes issues with generator expressions in the target's source files.
Instead of the (DEBUG_)LOCATION property, use generator expressions to determine the app's target file path (main shared library).
Fixes issues with generator expressions in the target's source files.
@ghost
Copy link

ghost commented Mar 15, 2019

Hey all!!

Love the work! This project has been extremely helpful!!

I have come across a problem that has stumped me.

I am trying to build a qt-android-ndk-cmake project and I am using Qt5.10.0, android-ndk-r19b, Android-19, and the latest version of CMake under windows 10. r19b has to be build using clang (I believe gcc is depreciated in this release). So I keep getting this error where the hyphen "-" is added to the paths for the toolchain prebuilts like it would when using gcc. eg. instead of having a folder named "llvm". it might be "x86-4.9" or "x86_64-4.9".

Stripping libraries to minimize size.
Command does not exist: P:/Documents/Android_NDK/android-ndk-r19b/toolchains/llvm-/prebuilt/windows-x86_64/bin/llvm-strip.exe
make[2]: *** [src/CMakeFiles/epicAPK] Error 9
make[1]: *** [src/CMakeFiles/epicAPK.dir/all] Error 2
make: *** [all] Error 2

I have double check everything and made sure QT_ANDROID_TOOLCHAIN_VERSION is cleared with:
set(QT_ANDROID_TOOLCHAIN_VERSION)

I was wondering if I am missing something silly or if this is an issue with either ndk, skd, or qt? I will add more info if needed.

Cheers,

Simon

@nohype
Copy link
Author

nohype commented Mar 15, 2019

@Simon-Maddison-fd
Strange if you use these fixes.
The basic mechanics are:
If ANDROID_USE_LLVM is undefined, the ANDROID_TOOLCHAIN variable is checked to be "clang". It should be set by the NDK's toolchain file, but I haven't checked it for NDK r19b yet (only r19).
There's also the possibility to set ANDROID_USE_LLVM to TRUE/FALSE to circumvent the "automatic detection" and force the variable values to be set for llvm (if ANDROID_USE_LLVM=TRUE).
If llvm/clang is detected (or forced), QT_ANDROID_TOOLCHAIN_VERSION is automatically cleared.

Could you check/post how the generated "qtdeploy.json.in" and "qtdeploy.json" files look in your case?

@ghost
Copy link

ghost commented Mar 15, 2019

Hey freekee1!

Sorry I am not sure what you mean by "Stange if you use these fixes". I found myself here because I saw a commit on fixing windows issue. But after looking around I think I may have asked this question is the wrong spot.

I am still really new to the android ndk and your help is greatly appreciated.

I have been setting the ANDROID_USE_LLVM to true and I did check my qtdeploy.json to see if QT_ANDROID_TOOLCHAIN_VERSION was still getting set. Below both my qtdeploy.json.in and qtdeploy.json files.

qtdeploy.json

{
 "description": "This file is to be read by androiddeployqt",
 "qt": "C:/Qt/Qt5.9.0/5.9/android_x86",
 "sdk": "C:/Users/MadMan/Documents/code/app/sdk",
 "ndk": "C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b",
 "sdkBuildToolsRevision": "28.0.3",
 "toolchain-prefix": "llvm",
 "tool-prefix": "llvm",
 "toolchain-version": "",
 "ndk-host": "windows",
 "target-architecture": "x86",
 "application-binary": "C:/Users/MadMan/Documents/code/app/src-build/android/libs/libDemo.so",
 "android-package": "org.name.name",
 "android-app-name": "app",
 "qml-root-path": "",
 "stdcpp-path": "C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/sources/cxx-stl/llvm-libc++/libs/x86/libc++_shared.so",
 "useLLVM": true,
 
 "android-package-source-directory": "C:/Users/MadMan/Documents/code/app/src-build/src/package"
}

qtdeploy.json.in

{
 "description": "This file is to be read by androiddeployqt",
 "qt": "C:/Qt/Qt5.9.0/5.9/android_x86",
 "sdk": "C:/Users/MadMan/Documents/code/app/sdk",
 "ndk": "C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b",
 "sdkBuildToolsRevision": "28.0.3",
 "toolchain-prefix": "llvm",
 "tool-prefix": "llvm",
 "toolchain-version": "",
 "ndk-host": "windows",
 "target-architecture": "x86",
 "application-binary": "$<TARGET_FILE:Demo>",
 "android-package": "org.name.name",
 "android-app-name": "app",
 "qml-root-path": "",
 "stdcpp-path": "C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/sources/cxx-stl/llvm-libc++/libs/x86/libc++_shared.so",
 "useLLVM": true,
 
 "android-package-source-directory": "C:/Users/MadMan/Documents/code/app/src-build/src/package"
}

Here is everything else:

I have set up a fresh build environment on another computer with sdk{android;19,build-tools;28.0.3} ndk-r18b, Qt5.9.0, jdk-8u201-windows-x64. ,and these are the results I am getting. I

This is my command for building for x86 with clang/llvm

cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="C:\path\to\android.toolchain.cmake" -DCMAKE_MAKE_PROGRAM="C:\path\to\ndk\make.exe" -DANDROID_TOOLCHAIN=clang -DANDROID_PLATFORM=android-19 -DANDROID_STL=c++_shared -DANDROID_ABI=x86 -DCMAKE_BUILD_TYPE=Debug

This is the output I get after running that.

-- Check for working C compiler: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/toolchains/llvm/prebuilt/windows/bin/clang.exe
-- Check for working C compiler: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/toolchains/llvm/prebuilt/windows/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/toolchains/llvm/prebuilt/windows/bin/clang++.exe
-- Check for working CXX compiler: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/toolchains/llvm/prebuilt/windows/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_SUPPORTS_CXX11
-- Performing Test COMPILER_SUPPORTS_CXX11 - Success
-- Performing Test COMPILER_SUPPORTS_CXX0X
-- Performing Test COMPILER_SUPPORTS_CXX0X - Success
-- Building with android_x86 version of QT
-- Found Qt for Android: C:/Qt/Qt5.9.0/5.9/android_x86
-- Found Android SDK: C:/Users/MadMan/Documents/code/app/sdk
-- Found Android NDK: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b
-- Detected Android SDK build tools version 28.0.3
-- Used input AndroidManifest file QT_ANDROID_MANIFEST_IN_REAL_PATH : C:/Users/MadMan/Documents/code/app/qt-android-cmake/AndroidManifest.xml.in
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/MadMan/Documents/code/app/src-build

And this is what I get after running make.

[ 14%] Generating qrc_demo.cpp
[ 28%] Automatic MOC for target Demo
Generating MOC compilation mocs_compilation.cpp
[ 28%] Built target Demo_autogen
Scanning dependencies of target Demo
[ 42%] Building CXX object src/CMakeFiles/Demo.dir/demo.cpp.o
[ 57%] Building CXX object src/CMakeFiles/Demo.dir/qrc_demo.cpp.o
[ 71%] Building CXX object src/CMakeFiles/Demo.dir/Demo_autogen/mocs_compilation.cpp.o
[ 85%] Linking CXX shared library ../android/libs/libDemo.so
[100%] Built target Demo
Scanning dependencies of target epicAPK
package source in : C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/sources/cxx-stl/llvm-libc++/libs/x86/libc++_shared.so
Generating Android Package
  Input file: C:/Users/MadMan/Documents/code/app/src-build/src/qtdeploy.json
  Output directory: C:/Users/MadMan/Documents/code/app/src-build/src/Demo-x86/
  Application binary: C:/Users/MadMan/Documents/code/app/src-build/android/libs/libDemo.so
  Android build platform: android-19
  Install to device: No
Command does not exist: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/toolchains/llvm-/prebuilt/windows/bin/llvm-readelf.exe
Command does not exist: C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/toolchains/llvm-/prebuilt/windows/bin/llvm-readelf.exe
GNU STL library does not exist at C:/Users/MadMan/Documents/code/app/ndk/android-ndk-r18b/sources/cxx-stl/gnu-libstdc++//libs/x86/libgnustl_shared.so
make[2]: *** [src/CMakeFiles/epicAPK] Error 5
make[1]: *** [src/CMakeFiles/epicAPK.dir/all] Error 2
make: *** [all] Error 2

As you can see in the above log. It is still looking for "llvm-". Thanks for looking!!

Regards,

Simon M.

@nohype
Copy link
Author

nohype commented Mar 15, 2019

@Simon-Maddison-fd
My only experience is with Android for armv7. Did you build the Qt version yourself for "android-clang"?
I just remembered reading something in the docs. I'm not sure Qt 5.9 supports the newer ndk versions or clang.
This page says for Qt 5.9:

Android (API Level: 16) | GCC as provided by Google, MinGW 5.3

(The Qt 5.9.0 platform configurations also don't contain "clang" for any supported android platform.

And the getting started guide states:

Using Qt for Android with the GCC toolchain requires Android NDK version r10e. For Qt 5.12 or later, use the latest available version of NDK with android-clang toolchain.

Which doesn't sound like Qt 5.9 will work with anything other than r10e?
I'm totally guessing here, but maybe the androiddeployqt tool coming with Qt 5.9 is also not updated for newer ndk versions (or non-gcc toolchains). That might explain why the paths are built as if the llvm/clang toolchain wasn't used (because those values in qtdeploy.json might be unknown to the tool in that version)?

Maybe you could try getting the required versions together according to the docs, then see what happens?
It can be quite an annoying puzzle with all those version incompatibilities, esp. since there doesn't seem to be a central place with all of them listed. I'm also regularly struggling with that.

Another small thing, again I don't know if it's a problem or not, but on a windows host I use the MinGW generator (cmake -G"MinGW Makefiles").

Hope that gives you at least some starting points for more trial&error.

@ghost
Copy link

ghost commented Mar 17, 2019

@freekee1

Thanks so much for the suggestions. I will be sure to try the different variations.
To be honest, I actually didn't even look at the support pages for Qt and which versions support which. I think this might be the cause of my problem and I will start there.

I will let you know if I solve it. Thanks again for your time in replying to me.

Cheers,

SM.

@ghost
Copy link

ghost commented Mar 19, 2019

Hey @freekee1,

I just wanted to say thanks for your time and opinion. I ended up being able to build the project using clang! The problem was an issue between the ndk and qt versions.

Cheers,

SM.

@nohype
Copy link
Author

nohype commented Mar 20, 2019

@Simon-Maddison-fd
Glad to read that. And that it was rather straight-forward after all, no finicky debugging in search of details. :-)
Good luck with your project.

cheers

@LaurentGomila
Copy link
Owner

Closing this PR as all its commits are part of #25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants