How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

calmengineer
Just popping in
Just popping in
Posts: 3
Joined: Mon Jul 18, 2016 14:22

How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby calmengineer » Wed Jul 20, 2016 18:41

Hello forum.

I'm trying to build CEGUI for Android under Linux (with OGRE Renderer). I already managed to build Ogre 1.10 for Android and have bunch of static libs. If only OgreRenderer is going to be built then there is no need for Epoxy or other libs (just TinyXML for config reading and OIS for input). I want to build CEGUI as a static lib for later use. I've noticed that in project root there's an 'android' directory - with some shell scripts and configs - I didn't find any README on the matter so I'm trying to build CEGUI from command line instead.

Code: Select all

mkdir build-android-release
cd build-android-release

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake__orig -DANDROID_ABI=armeabi-v7a -DANDROID_NATIVE_API_LEVEL=10 -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DCEGUI_SAMPLES_ENABLED=ON -DCEGUI_BUILD_RENDERER_OPENGL=OFF -DCEGUI_BUILD_RENDERER_OPENGL3=OFF -DCEGUI_BUILD_RENDERER_OGRE=YES -DCEGUI_USE_GLEW=OFF -DCEGUI_USE_EPOXY=OFF -DCEGUI_USE_MINIBIDI=OFF -DCEGUI_USE_FRIBIDI=OFF ..

I'm also setting environment variable OGRE_HOME/SDK so it points to the location where Ogre libs and include files are installed (the CMake script in cmake/FindOGRE.cmake uses it). But configuration process still couldn't find Ogre.h or OgreBuildSettings.h. I already knew that something is off because file $OGRE_HOME/include/OGRE/Ogre.h exists! So cmake function find_path should find it...
Anyway I still tried to run make in the build folder because I was curious...

Code: Select all

Building CXX object cegui/src/CMakeFiles/CEGUIBase-0.dir/IconvStringTranscoder.cpp.o
/home/***/Downloads/Repositories.Develop/cegui-v0-repo/cegui/src/IconvStringTranscoder.cpp:30:19: fatal error: iconv.h: No such file or directory
 #include <iconv.h>
                   ^
compilation terminated.
make[2]: *** [cegui/src/CMakeFiles/CEGUIBase-0.dir/build.make:1071: cegui/src/CMakeFiles/CEGUIBase-0.dir/IconvStringTranscoder.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: cegui/src/CMakeFiles/CEGUIBase-0.dir/all] Error 2
make: *** [Makefile:150: all] Error 2

I just don't know what to try next.

How to build CEGUI for Android? With or without OGRE. Is there a manual? I couldn't find any specific info. BTW, I'm using Arch Linux, Android NDK r11c and cmake 3.5.2. Thanks in advance for any info on the matter.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby YaronCT » Wed Jul 20, 2016 19:06

@calmengineer: Sorry, Android support is still a work in progress. I'll try to help u though.

Let's start with Iconv. The official (Google's NDK) lacks Iconv. The simple solution is to use Crystax NDK, which has more features and less bugs. Otherwise, you'll have to download Iconv's source and cross-compile it for Android. You'll have to override "config.sub" and "config.guess" with the official ones from here, and apply this patch:

Code: Select all

--- orig/lib/Makefile.in   2011-08-07 20:48:03.000000000 +0300
+++ new/lib/Makefile.in   2015-08-29 00:02:16.899184315 +0300
@@ -68,7 +68,7 @@ OBJECTS_RES_no =
 all : libiconv.la
 
 libiconv.la : $(OBJECTS)
-   $(LIBTOOL_LINK) $(CC) $(LDFLAGS) $(CFLAGS) -o libiconv.la -rpath $(libdir) -version-info $(LIBICONV_VERSION_INFO) -no-undefined $(OBJECTS)
+   $(LIBTOOL_LINK) $(CC) $(LDFLAGS) $(CFLAGS) -o libiconv.la -rpath $(libdir) -avoid-version -no-undefined $(OBJECTS)
 
 iconv.lo : $(srcdir)/iconv.c $(srcdir)/converters.h \
            $(srcdir)/encodings.def $(srcdir)/encodings_aix.def $(srcdir)/encodings_osf1.def $(srcdir)/encodings_dos.def $(srcdir)/encodings_local.def \


Let's 1st get that working, then tackle the other problems..

lucebac
Just can't stay away
Just can't stay away
Posts: 193
Joined: Sat May 24, 2014 21:55

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby lucebac » Wed Jul 20, 2016 21:25

Have you tried to use cmake-gui to set up the build files? There should be something related to Android since we check for android things in CMakeLists.txt.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby YaronCT » Wed Jul 20, 2016 21:30

@lucebac: A simple glance at "CMakeLists.txt" shows there isn't any cmake option related to android.

calmengineer
Just popping in
Just popping in
Posts: 3
Joined: Mon Jul 18, 2016 14:22

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby calmengineer » Thu Jul 21, 2016 11:31

@YaronCT: Thanks for the information - it allowed me to move forward. Building iconv for Android was not an easy task, but I succeeded in making libiconv.so (note, that libiconv is under LGPL license so one needs to link to it dynamically). I didn't use patch that you mentioned earlier. Instead I used ndk-build and custom Application.mk and Android.mk configs. First I ran ./configure to generate iconv.h header. Next, I modified libcharset/config.h so it wouldn't include <langinfo.h> (nl_langinfo won't be available anyway). After that I manually copied headers and shared library to /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/user (folders 'lib' and 'include').

Next, I installed previously built Ogre 1.10 to /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/user - I've noticed that CMake with Android Toolchain automatically searches this paths for headers and libraries (also this is the default CMAKE_INSTALL_PREFIX when configuring project with Android Toolchain - at least on my system). I also installed ogre dependencies there (OIS, zzip, freetype, FreeImage). This allowed cmake to find Ogre along other dependencies.

But I also wanted to build only core CEGUI libraries (static) without samples and CEGUIOgreRenderer. I needed to change cegui/src/CMakeLists.txt, cmake/CEGUIMacros.make and cmake/FindOgre.cmake to achieve this. This should really be option to build only static libs. The 'CEGUI_BUILD_STATIC_CONFIGURATION' causes to build static libraries along with shared ones.

CMake configuration command:

Code: Select all

cmake -DCMAKE_BUILD_TYPE=Release -DCEGUI_BUILD_STATIC_CONFIGURATION=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake__orig -DANDROID_ABI=armeabi-v7a -DANDROID_NATIVE_API_LEVEL=10 -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DCEGUI_SAMPLES_ENABLED=OFF -DCEGUI_BUILD_RENDERER_OPENGL=OFF -DCEGUI_BUILD_RENDERER_OPENGL3=OFF -DCEGUI_BUILD_RENDERER_OGRE=YES -DCEGUI_USE_GLEW=OFF -DCEGUI_USE_EPOXY=OFF -DCEGUI_USE_MINIBIDI=OFF -DCEGUI_USE_FRIBIDI=OFF ..

Diff for cmake/FindOgre.cmake (this is so cmake won't complain about X11/XAW dependencies):

Code: Select all

diff -r ed25a866ade7 cmake/FindOgre.cmake
--- a/cmake/FindOgre.cmake   Thu Apr 28 21:53:04 2016 +0200
+++ b/cmake/FindOgre.cmake   Thu Jul 21 12:51:37 2016 +0200
@@ -234,7 +234,7 @@
         if (NOT FREETYPE_FOUND)
             set(OGRE_DEPS_FOUND FALSE)
         endif ()
-        if (UNIX AND NOT APPLE)
+        if (UNIX AND NOT APPLE AND NOT ANDROID)
             if (NOT X11_FOUND)
                 set(OGRE_DEPS_FOUND FALSE)
             endif ()

Diff for cmake/CEGUIMacros.cmake (so only static libraries are being added as targets in CEGUI):

Code: Select all

diff -r ed25a866ade7 cmake/CEGUIMacros.cmake
--- a/cmake/CEGUIMacros.cmake   Thu Apr 28 21:53:04 2016 +0200
+++ b/cmake/CEGUIMacros.cmake   Thu Jul 21 13:04:39 2016 +0200
@@ -49,11 +49,14 @@
 # Add libs to a target, and correctly handles static versions of libs built by the project
 #
 macro (cegui_target_link_libraries _TARGET_NAME)
-    target_link_libraries(${_TARGET_NAME} ${ARGN})
+    if(NOT ANDROID)
+        target_link_libraries(${_TARGET_NAME} ${ARGN})
+    endif()
 
     get_target_property(_TARGET_EXISTS ${_TARGET_NAME}_Static TYPE)
     if (_TARGET_EXISTS)
         foreach(_LIB ${ARGN})
+   
             if (${_LIB} STREQUAL optimized OR ${_LIB} STREQUAL debug OR ${_LIB} STREQUAL general)
                 set (_BUILD ${_LIB})
             else()
@@ -243,8 +246,9 @@
     ###########################################################################
     #                       SHARED LIBRARY SET UP
     ###########################################################################
-    add_library(${_LIB_NAME} ${_LIB_TYPE} ${${_SOURCE_FILES_VAR}} ${${_HEADER_FILES_VAR}})
-    set_target_properties(${_LIB_NAME} PROPERTIES DEFINE_SYMBOL ${_CEGUI_EXPORT_DEFINE})
+    if (NOT ANDROID)
+        add_library(${_LIB_NAME} ${_LIB_TYPE} ${${_SOURCE_FILES_VAR}} ${${_HEADER_FILES_VAR}})
+        set_target_properties(${_LIB_NAME} PROPERTIES DEFINE_SYMBOL ${_CEGUI_EXPORT_DEFINE})
 
     if (NOT CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES)
         # Starting with CMake 2.8.12 LINK_INTERFACE_LIBRARIES was renamed to INTERFACE_LINK_LIBRARIES
@@ -259,6 +263,8 @@
         endif()
     endif()
 
+    endif()
+
     if (APPLE)
         set_target_properties(${_LIB_NAME} PROPERTIES
             INSTALL_NAME_DIR ${CEGUI_APPLE_DYLIB_INSTALL_PATH}
@@ -299,11 +305,13 @@
             set(_CEGUI_LIB_DEST ${CEGUI_LIB_INSTALL_DIR})
         endif()
 
-        install(TARGETS ${_LIB_NAME}
-            RUNTIME DESTINATION bin
-            LIBRARY DESTINATION ${_CEGUI_LIB_DEST}
-            ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR}
-        )
+        if(NOT ANDROID)
+            install(TARGETS ${_LIB_NAME}
+                RUNTIME DESTINATION bin
+                LIBRARY DESTINATION ${_CEGUI_LIB_DEST}
+                ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR}
+            )
+        endif()
 
         if (CEGUI_BUILD_STATIC_CONFIGURATION)
             install(TARGETS ${_LIB_NAME}_Static
@@ -415,12 +423,14 @@
     # Each demo will become a dynamically linked library as plugin (module)
     cegui_add_library_impl(${CEGUI_TARGET_NAME} TRUE CORE_SOURCE_FILES CORE_HEADER_FILES FALSE FALSE)
 
-    # Setup custom install location
-    install(TARGETS ${CEGUI_TARGET_NAME}
-        RUNTIME DESTINATION bin
-        LIBRARY DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR}
-        ARCHIVE DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR}
-    )
+    if(NOT ANDROID)
+        # Setup custom install location
+        install(TARGETS ${CEGUI_TARGET_NAME}
+            RUNTIME DESTINATION bin
+            LIBRARY DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR}
+            ARCHIVE DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR}
+        )
+    endif()
 
     if (CEGUI_BUILD_STATIC_CONFIGURATION)
         install(TARGETS ${CEGUI_TARGET_NAME}_Static

Diff for cegui/src/CMakeLists.txt:

Code: Select all

diff -r ed25a866ade7 cegui/src/CMakeLists.txt
--- a/cegui/src/CMakeLists.txt   Thu Apr 28 21:53:04 2016 +0200
+++ b/cegui/src/CMakeLists.txt   Thu Jul 21 12:51:13 2016 +0200
@@ -58,7 +58,11 @@
 # multiple sub-dirs.
 cegui_add_library_impl(${CEGUI_TARGET_NAME} FALSE CORE_SOURCE_FILES ALL_HEADER_FILES TRUE FALSE)
 if (ANDROID)
-    target_link_libraries (${CEGUI_TARGET_NAME} log)
+    if(CEGUI_BUILD_STATIC_CONFIGURATION)
+        target_link_libraries (${CEGUI_TARGET_NAME}_Static log)
+    else()
+        target_link_libraries (${CEGUI_TARGET_NAME} log)
+    endif()
 endif ()
 
 source_group("Source Files\\widget" FILES ${WIDGET_SOURCE_FILES})
@@ -67,7 +71,7 @@
 source_group("Header Files\\widget" FILES ${WIDGET_HEADER_FILES})
 source_group("Header Files\\falagard" FILES ${FALAGARD_HEADER_FILES})
 
-if (NOT WIN32 AND NOT ANDROID)
+if (NOT WIN32)
     cegui_add_dependency(${CEGUI_TARGET_NAME} ICONV)
 endif()
 
@@ -92,11 +96,17 @@
 
 if (WIN32 AND NOT MINGW)
     cegui_target_link_libraries(${CEGUI_TARGET_NAME} winmm debug DbgHelp)
+elseif (ANDROID AND NOT APPLE)
+    if(CEGUI_BUILD_STATIC_CONFIGURATION)
+        target_link_libraries(${CEGUI_TARGET_NAME}_Static ${CMAKE_DL_LIBS})
+    else()
+        target_link_libraries(${CEGUI_TARGET_NAME} ${CMAKE_DL_LIBS})
+    endif()
 elseif (UNIX AND NOT APPLE)
     # This is intentionally not using 'cegui_target_link_libraries'
     target_link_libraries(${CEGUI_TARGET_NAME} ${CMAKE_DL_LIBS})
 elseif (MINGW)
-    cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CMAKE_DL_LIBS})
+   cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CMAKE_DL_LIBS})
 endif()
 
 if (APPLE AND CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES)

Please note that I made these changes to build only static CEGUI libraries for Android (with Ogre renderer component). Better would be to add option like 'CEGUI_BUILD_STATIC_ONLY' or something similar. In the end:

Code: Select all

[ 77%] Built target CEGUIBase-0_Static
[ 81%] Built target CEGUIOgreRenderer-0_Static
[ 83%] Built target CEGUIFreeImageImageCodec_Static
[ 97%] Built target CEGUICoreWindowRendererSet_Static
[100%] Built target CEGUICommonDialogs-0_Static

It builds without errors. But does it work? I haven't tested it yet - that's a different story (need to build Android application and link these static libs). Thanks again @YaronCT for pointing me in the right direction.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby YaronCT » Thu Jul 21, 2016 12:42

@calmengineer: Any reason y u didn't build iconv simply using autotools and the instructions I gave u? It has worked for me..

Disabling build of shared libs is definitely an option that should b added, you're right.

If you'd like to submit any of the changes you've made, contributions r always welcome!

I'm glad you've eventually managed to build everything. If u have any problems when running it, or with building and using any of the dependencies, or any other questions, feel free to ask.

calmengineer
Just popping in
Just popping in
Posts: 3
Joined: Mon Jul 18, 2016 14:22

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby calmengineer » Thu Jul 21, 2016 14:00

YaronCT wrote:@calmengineer: Any reason y u didn't build iconv simply using autotools and the instructions I gave u? It has worked for me..

Well I thought that using ndk-build would be easier. ndk-build was also mentioned on number of sites when I was searching for info on "libiconv android build" :) I was curious and tried the method that you mentioned - copied new config.sub and config.guess to both build-aux and libcharset/build-aux + updated lib/Makefile.in.

Code: Select all

export ANDROID_SYSROOT=/opt/android-ndk/platforms/android-9/arch-arm
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT"
export CFLAGS="--sysroot=$ANDROID_SYSROOT"
export CXXFLAGS="--sysroot=$ANDROID_SYSROOT"
export PATH=$PATH:/opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
./configure --host=arm-linux-androideabi --build=x86_64-linux --with-sysroot=$ANDROID_SYSROOT
make
Bam! It worked. Thanks. The output size differs though - but that's probably because APP_OPTIM := debug was set in Application.mk.

YaronCT wrote:If you'd like to submit any of the changes you've made, contributions r always welcome!

Let me just mention that most of the changes that I've made now were to bruteforce static only build. I would need to change it further...
Btw, Is libiconv really necessary? Is there a way to avoid this dependency?

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby YaronCT » Thu Jul 21, 2016 14:47

@calmengineer:

Btw, Is libiconv really necessary? Is there a way to avoid this dependency?


It's used for some string transcoding. You're welcome to inherit "CEGUI::StringTranscoder" and provide other implementations other than Iconv 1, e.g. using ICU, Java or implementing it yourself..

Perhaps u don't even need it - just try a dummy "CEGUI::StringTranscoder" implementation (e.g. make all methods throw an exception) and c if it works for u.. I don't know where it's used anyway.

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: How to build CEGUI (v0-8 branch) against OGRE 1.10 for Android?

Postby YaronCT » Fri Jul 22, 2016 00:02

@clamengineer:

Next, I installed previously built Ogre 1.10 to /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/user - I've noticed that CMake with Android Toolchain automatically searches this paths for headers and libraries (also this is the default CMAKE_INSTALL_PREFIX when configuring project with Android Toolchain - at least on my system). I also installed ogre dependencies there (OIS, zzip, freetype, FreeImage). This allowed cmake to find Ogre along other dependencies.


Even though it works, installing your own stuff to the compiler directory is definitely not the way that should work.. To control where CMake looks for packages, u adjust CMake variables (u usually specify them on the cmake invocation), mainly "CMAKE_PREFIX_PATH" or, for finer control, "CMAKE_INCLUDE_PATH" and "CMAKE_LIBRARY_PATH". However, when the cmake variable "CMAKE_FIND_ROOT_PATH" is non-empty (which is usually the case when cross-compiling) it specifies one or more directories to be prepended to all other search directories. This effectively “re-roots” the entire search under given locations. In our case that variable is set in the toolchain file - look for it there and adjust it as needed. See cmake doc for "find_path" and "find_library" for more info.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests