[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    =?utf-8?q?=5Bgraphics/krita=5D_/=3A_Android=3A_enable_building_GMic_as_a_plugin?=
From:       L. E. Segovia <null () kde ! org>
Date:       2021-08-17 16:35:57
Message-ID: 20210817163557.6D2601241B12 () leptone ! kde ! org
[Download RAW message or body]

Git commit 2e0c862adb2856067fcf6c7cf4a6a546896a4f73 by L. E. Segovia.
Committed on 17/08/2021 at 16:34.
Pushed by lsegovia into branch 'master'.

Android: enable building GMic as a plugin

This commit adds a *completely optional* step to build GMic as a plugin
for Android. It also adds a workaround to ensure that its project
can pick CMAKE_FIND_ROOT_PATH up.

BUG: 428995

CCMAIL: kimageshop@kde.org

M  +10   -1    3rdparty/CMakeLists.txt
M  +11   -1    3rdparty_plugins/CMakeLists.txt
M  +1    -0    3rdparty_plugins/ext_gmic/CMakeLists.txt
M  +11   -0    CMakeLists.txt
M  +43   -1    packaging/android/androidbuild.sh

https://invent.kde.org/graphics/krita/commit/2e0c862adb2856067fcf6c7cf4a6a546896a4f73

diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt
index 72cd5ba25a..2f4b949ac4 100644
--- a/3rdparty/CMakeLists.txt
+++ b/3rdparty/CMakeLists.txt
@@ -163,12 +163,21 @@ if (ANDROID)
   # HACK: copied from ECM, this makes sure that we don't build an executable (kf5s \
do that), but a DSO.  set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> \
<CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> \
<SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")  
+  # Increase the stack size to match MinGW's. Prevents crashes with GMic.
+  set(SECURITY_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
-Wl,-z,stack-size=4194304") +  set(SECURITY_SHARED_LINKER_FLAGS \
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,stack-size=4194304") +  \
set(SECURITY_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} \
-Wl,-z,stack-size=4194304") +
   set (GLOBAL_PROFILE ${GLOBAL_PROFILE}
                      -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                      -DANDROID_PLATFORM=${ANDROID_PLATFORM}
                      -DANDROID_ABI=${ANDROID_ABI}
                      -DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH}
-                     -DCMAKE_CXX_LINK_EXECUTABLE=${CMAKE_CXX_LINK_EXECUTABLE})
+                     -DCMAKE_CXX_LINK_EXECUTABLE=${CMAKE_CXX_LINK_EXECUTABLE}
+                     -DCMAKE_EXE_LINKER_FLAGS=${SECURITY_EXE_LINKER_FLAGS}
+                     -DCMAKE_SHARED_LINKER_FLAGS=${SECURITY_SHARED_LINKER_FLAGS}
+                     -DCMAKE_MODULE_LINKER_FLAGS=${SECURITY_MODULE_LINKER_FLAGS}
+                     )
 
   # see: https://github.com/android/ndk/issues/929
   unset (CMAKE_SYSROOT)
diff --git a/3rdparty_plugins/CMakeLists.txt b/3rdparty_plugins/CMakeLists.txt
index d0ee19626e..8d6f4df1ee 100644
--- a/3rdparty_plugins/CMakeLists.txt
+++ b/3rdparty_plugins/CMakeLists.txt
@@ -119,11 +119,21 @@ if (APPLE)
 endif ()
 
 if (ANDROID)
+ # Increase the stack size to match MinGW's. Prevents crashes with GMic.
+  set(SECURITY_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
-Wl,-z,stack-size=4194304") +  set(SECURITY_SHARED_LINKER_FLAGS \
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,stack-size=4194304") +  \
set(SECURITY_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} \
-Wl,-z,stack-size=4194304") +
+  string(REPLACE ";" "|" _escape_find_root_path "${CMAKE_FIND_ROOT_PATH}")
   set (GLOBAL_PROFILE ${GLOBAL_PROFILE}
                      -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                      -DANDROID_PLATFORM=${ANDROID_PLATFORM}
                      -DANDROID_ABI=${ANDROID_ABI}
-                     -DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH})
+                     -DCMAKE_FIND_ROOT_PATH="${_escape_find_root_path}"
+                     -DCMAKE_EXE_LINKER_FLAGS=${SECURITY_EXE_LINKER_FLAGS}
+                     -DCMAKE_SHARED_LINKER_FLAGS=${SECURITY_SHARED_LINKER_FLAGS}
+                     -DCMAKE_MODULE_LINKER_FLAGS=${SECURITY_MODULE_LINKER_FLAGS}
+                     )
 
   # see: https://github.com/android/ndk/issues/929
   unset (CMAKE_SYSROOT)
diff --git a/3rdparty_plugins/ext_gmic/CMakeLists.txt \
b/3rdparty_plugins/ext_gmic/CMakeLists.txt index f648158095..667cc1db15 100644
--- a/3rdparty_plugins/ext_gmic/CMakeLists.txt
+++ b/3rdparty_plugins/ext_gmic/CMakeLists.txt
@@ -10,6 +10,7 @@ ExternalProject_Add( ext_gmic
     INSTALL_DIR ${PREFIX_ext_gmic}
 
     CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${PREFIX_ext_gmic} -DGMIC_QT_HOST=krita-plugin \
-DCMAKE_BUILD_TYPE=${GLOBAL_BUILD_TYPE} ${GLOBAL_PROFILE} +    LIST_SEPARATOR "|"
 
     UPDATE_COMMAND ""
 )
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0207f869ae..248c8896cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -195,6 +195,11 @@ add_feature_info("Dr. Mingw" USE_DRMINGW "Enable the Dr. Mingw \
crash handler")  add_link_options(/GUARD:CF)
         endif (USE_CONTROL_FLOW_GUARD)
     endif (MINGW)
+elseif(ANDROID)
+    # Increase the stack size to match MinGW's. Prevents crashes with GMic.
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
-Wl,-z,stack-size=4194304") +    set(CMAKE_SHARED_LINKER_FLAGS \
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,stack-size=4194304") +    \
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} \
-Wl,-z,stack-size=4194304")  endif ()
 
 option(HIDE_SAFE_ASSERTS "Don't show message box for \"safe\" asserts, just ignore \
them automatically and dump a message to the terminal." ON) @@ -814,6 +819,12 @@ \
set_package_properties(FFTW3 PROPERTIES  macro_bool_to_01(FFTW3_FOUND HAVE_FFTW3)
 if (FFTW3_FOUND)
     list (APPEND ANDROID_EXTRA_LIBS ${FFTW3_LIBRARY})
+
+    # GMic uses the Threads library if available.
+    find_library(FFTW3_THREADS_LIB fftw3_threads PATHS ${FFTW3_LIBRARY_DIRS})
+    if(FFTW3_THREADS_LIB)
+        list(APPEND ANDROID_EXTRA_LIBS ${FFTW3_THREADS_LIB})
+    endif()
 endif()
 
 find_package(OCIO 1.1.1 EXACT)
diff --git a/packaging/android/androidbuild.sh b/packaging/android/androidbuild.sh
index 7a7c32b374..9151371e36 100755
--- a/packaging/android/androidbuild.sh
+++ b/packaging/android/androidbuild.sh
@@ -5,11 +5,14 @@
 
 # Example: androidbuild.sh -p=all --src=/home/sh_zam/workspace/krita \
--build-type=Release --build-root=/home/sh_zam/workspace/test-kreeta \
--ndk-path=/home/sh_zam/Android/Sdk/ndk-bundle --sdk-path=/home/sh_zam/Android/Sdk \
--api-level=21 --android-abi=armeabi-v7a \
--qt-path=/home/sh_zam/Qt/5.12.1/android_armv7  
+set -e
+set -x
+
 echoerr() { printf "ERROR: %s\n" "$*" >&2;  }
 
 print_usage() {
     printf "\nUsage: "$0" [-p=PACKAGE] [ARGUMENTS..]\n"
-    printf "Packages: [all|krita-bin|apk|qt|3rdparty|boost|kf5]\n"
+    printf "Packages: [all|krita-bin|apk|qt|3rdparty|plugins|boost|kf5]\n"
     printf "Arguments: \n"
     printf  "\t--src=PATH                  Source files\n"
     printf  "\t--build-type=TYPE          TYPE=[Debug|RelWithDebInfo|Release]\n"
@@ -33,6 +36,7 @@ check_exists() {
 setup_directories() {
     export DOWNLOADS_DIR=$BUILD_ROOT/d
     export DEPS_BUILD=$BUILD_ROOT/b
+    export PLUGINS_BUILD=$BUILD_ROOT/p
     export THIRDPARTY_INSTALL=$BUILD_ROOT/i
 
     if [[ ! -d $DOWNLOADS_DIR ]]; then
@@ -43,6 +47,10 @@ setup_directories() {
         mkdir $DEPS_BUILD -p
     fi
 
+    if [[ ! -d $PLUGINS_BUILD ]]; then
+        mkdir $PLUGINS_BUILD -p
+    fi
+
     if [[ ! -d $THIRDPARTY_INSTALL ]]; then
         mkdir $THIRDPARTY_INSTALL -p
     fi
@@ -62,6 +70,20 @@ configure_ext() {
     cd $BUILD_ROOT
 }
 
+configure_plugins() {
+    cd $PLUGINS_BUILD
+    cmake $KRITA_ROOT/3rdparty_plugins \
+        -DINSTALL_ROOT=$INSTALL_PREFIX                                               \
\ +        -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOADS_DIR                                    \
\ +        -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX                                     \
\ +        -DCMAKE_TOOLCHAIN_FILE=$CMAKE_ANDROID_NDK/build/cmake/android.toolchain.cmake \
\ +        -DANDROID_ABI=$ANDROID_ABI                                                 \
\ +        -DANDROID_PLATFORM=$ANDROID_NATIVE_API_LEVEL                               \
\ +        -DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT                                       \
\ +        -DCMAKE_FIND_ROOT_PATH="$QT_ANDROID;$BUILD_ROOT/i;$INSTALL_PREFIX"
+    cd $BUILD_ROOT
+}
+
 PROC_COUNT=`grep processor /proc/cpuinfo | wc -l`
 
 build_qt() {
@@ -104,6 +126,21 @@ build_ext() {
     cd $BUILD_ROOT
 }
 
+build_plugins() {
+    if [[ ! -d $QT_ANDROID ]]; then
+        echoerr "qt libs not found"
+        echo "Please run -p=qt prior to this"
+        exit
+    fi
+
+    configure_plugins
+    cd $PLUGINS_BUILD
+    # Please do not change the order
+    cmake --build . --config $BUILD_TYPE --target ext_gmic -- -j$PROC_COUNT
+
+    cd $BUILD_ROOT
+}
+
 build_boost() {
     configure_ext
     cd $DEPS_BUILD
@@ -263,12 +300,14 @@ case $PACKAGE in
         build_ext
         build_boost
         build_krita
+        # build_plugins
         build_apk
         ;;
     krita-bin)
         build_krita
         ;;
     apk)
+        # build_plugins
         build_apk
         ;;
     qt)
@@ -277,6 +316,9 @@ case $PACKAGE in
     3rdparty)
         build_ext
         ;;
+    plugins)
+        build_plugins
+        ;;
     boost)
         build_boost
         ;;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic