I’m not familiar with Cmake, how do we set the compiler flags for building Urho3D or Urho3D android projects? I’ve tried modifying CMakeLists.txt by adding set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -O3”) and add_definitions("-O3"), it does not seem to be working.
How to set compiler flags for building Urho3D (Android Build)


You can use
cmake_android.sh
or
cmake_android.bat
(main Urho3D folder). Or you can invoke command manually:
cmake -DCMAKE_TOOLCHAIN_FILE=Urho3D/CMake/Toolchains/Android.cmake -DANDROID=1 -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_ABI=armeabi
Make sure you have two environment variables pointing to android SDK and NDK:
ANDROID_NDK=/path/to/android-ndk-r13b
ANDROID_SDK=/path/to/android-sdk-linux
Now i do not remember for sure but
PATH
environment variable might need
/path/to/android-sdk-linux/platform-tools
.
More info in docs .

Thank you for your response. Just to clarify, How if I want to set the compiler’s level of optimisation(for exp, set to -O3)? could I just append -O3 at the end of the command?

You may use
-DCMAKE_BUILD_TYPE=Release
in case you want a release build. To set specific flags you should add
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
(and maybe
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
for C code) in appropriate place.

Thanks a lot for your help, it’s very helpful. What is the default CPU optimization level for Release mode for Urho3D Android build?

Release build configuration uses -O3.

ok, thanks! If this is the case i just need to use “-DCMAKE_BUILD_TYPE=Release”

Actually Release is the default.