Browse Source

For Travis CI - skip APK test run when packaging.
General build script cleanup:
- Constrain build option values in cmake-gui.
- Constrain build configuration for both multi-configuration and single-configuration generators.
- Mark cached variables as advanced or internal as appropriate.

Yao Wei Tjong 姚伟忠 11 years ago
parent
commit
60eeb45222

+ 1 - 1
.bash_helpers.sh

@@ -34,7 +34,7 @@ post_cmake() {
         if [ $HAS_XMLSTARLET ]; then
         if [ $HAS_XMLSTARLET ]; then
             # Common fixes for all builds
             # Common fixes for all builds
             #
             #
-            # Remove build type from project name
+            # Remove build configuration from project name
             # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
             # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
             #
             #
             xmlstarlet ed -P -L \
             xmlstarlet ed -P -L \

+ 13 - 12
Docs/GettingStarted.dox

@@ -63,27 +63,27 @@ CMake caches some internal variables to speed up the subsequent invocation of th
 
 
 \section Building_Android Android build process
 \section Building_Android Android build process
 
 
-First, if you are building under Windows platform without MKLINK support then copy Bin/Data and Bin/CoreData directories to the Source/Android/assets directory (you can use the provided batch file CopyData.bat). This step is not necessary for Windows with MKLINK support and non-Windows platforms because the build script uses symbolic links for platforms that support it.
+First, if you are building under Windows host without MKLINK support then copy Bin/Data and Bin/CoreData directories to the Source/Android/assets directory (you can use the provided batch file CopyData.bat). This step is not necessary for Windows with MKLINK support and non-Windows host because the build script uses symbolic links for host development environments that support it.
 
 
 Set the ANDROID_NDK environment variable to point to your Android NDK. On Windows, ensure that make.exe from the Android NDK is included in the path and is executable from the command line.
 Set the ANDROID_NDK environment variable to point to your Android NDK. On Windows, ensure that make.exe from the Android NDK is included in the path and is executable from the command line.
 
 
-On Windows, execute cmake_android.bat. If MKLINK support is available, provide build option "-DURHO3D_MKLINK=1" to generate out-of-source build. Then go to the build directory Source/Android (or android-Build if out-of-source build) and execute the following commands. On OS X or Linux, execute cmake_gcc.sh (the ANDROID_NDK environment variable distinguishes from a normal desktop build) then go to the android-Build directory (always an out-of-source build) and execute the following commands.
+On Windows, execute cmake_android.bat. If your user account has privilege to use MKLINK then you have the option to provide the build option "-DURHO3D_MKLINK=1" when invoking the cmake_android.bat to generate out-of-source build tree. Then go to the build tree directory which could be either 'Source/Android' or 'android-Build' (when using MKLINK) and execute the below commands to start the build.
 
 
-- android update project -p . -t 1 (only needed on the first time,
-                                    replace '-t 1' with desired target-id)
-- make -j8 (replace '-j8' with the number of logical CPU cores of the
-            host/build system)
+- android update project -p . -t 1 (replace id to match the desired target API)
+- make -j8 (replace the number to match your host's number of logical CPU cores)
 - ant debug
 - ant debug
 
 
-After the commands finish successfully, the APK should have been generated to the build's "bin" subdirectory, from where it can be installed on a device or an emulator. The command "ant installd" can be used for this.
+On OS X or Linux, execute cmake_gcc.sh (the presence of ANDROID_NDK environment variable instructs the shell script to also generate project file for Android build besides normal desktop build). Then go to the build tree (which is currently defaulted to 'android-Build' directory) and execute the same commands as above.
+
+After the commands finish successfully, the APK should have been generated in the build tree's "bin" subdirectory, from where it can be installed on a device or an emulator. The command "ant installd" can be used for this. After the debug APK has been installed, you can use "rake android" command to automate the test running of the APK on the attached Android device.
 
 
 For a release build, use the "ant release" command instead of "ant debug" and follow the Android SDK instructions on how to sign your APK properly.
 For a release build, use the "ant release" command instead of "ant debug" and follow the Android SDK instructions on how to sign your APK properly.
 
 
 By default the Android package for Urho3D is com.googlecode.urho3d. For a real application you must replace this with your own package name. The Urho3D activity subclasses the SDLActivity from org.libsdl.app package, whose name (or the JNI code from SDL library) does not have to be changed.
 By default the Android package for Urho3D is com.googlecode.urho3d. For a real application you must replace this with your own package name. The Urho3D activity subclasses the SDLActivity from org.libsdl.app package, whose name (or the JNI code from SDL library) does not have to be changed.
 
 
-Note that the native code is built by default for armeabi-v7a ABI. To make your program compatible also with old Android devices, build also an armeabi version by executing the CMake batch file again with the build option "-DANDROID_ABI=armeabi" added, then execute make again in the build directory. Similarly, the native code can be built using 64-bit ABI by changing the value of this build option. See \ref Build_Options "Build options" for all the possible values.
+Note that the native code is built by default for armeabi-v7a ABI. To make your program compatible also with old Android devices, build also an armeabi version by executing the CMake batch file or shell script again with the build option "-DANDROID_ABI=armeabi" added, then execute make again in the build directory. Similarly, the native code can be built using 64-bit ABI by changing the value of this build option. See \ref Build_Options "Build options" for all the possible values.
 
 
-You can also build and deploy using Eclipse IDE with ADT plugin. To do that, after setting the ANDROID_NDK environment variable then run cmake_eclipse.sh. Import "Existing Android Code into Workspace" from the CMake generated Eclipse's project found in the android-Build directory. Switch Eclipse IDE to use Java Perspective. Update project properties to choose the desired Android API target and that's it. Just choose "Run" to let ADT automatically build and deploy the application to Android (virtual) device.
+You can also build and deploy using Eclipse IDE with ADT plugin. To do that, after setting the ANDROID_NDK environment variable then run cmake_eclipse.sh instead of cmake_gcc.sh. Import "Existing Android Code into Workspace" from the CMake generated Eclipse project file in the build tree. Switch Eclipse IDE to use Java Perspective. Update project properties to choose the desired Android API target. Choose "Run" to let ADT automatically build and deploy the application to Android (virtual) device.
 
 
 \section Building_Ios iOS build process
 \section Building_Ios iOS build process
 
 
@@ -172,11 +172,12 @@ A number of build options can be defined explicitly when invoking the above cmak
 |URHO3D_STATIC_RUNTIME|0|Use static C/C++ runtime libraries and eliminate the need for runtime DLLs installation (VS only)|
 |URHO3D_STATIC_RUNTIME|0|Use static C/C++ runtime libraries and eliminate the need for runtime DLLs installation (VS only)|
 |URHO3D_LIB_TYPE      |*|Specify Urho3D library type, possible values are STATIC (\*default) and SHARED|
 |URHO3D_LIB_TYPE      |*|Specify Urho3D library type, possible values are STATIC (\*default) and SHARED|
 |URHO3D_SCP_TO_TARGET |-|Use scp to transfer executables to target system (non-Android cross-compiling build only), SSH digital key must be setup first for this to work, typical value has a pattern of usr@tgt:remote-loc|
 |URHO3D_SCP_TO_TARGET |-|Use scp to transfer executables to target system (non-Android cross-compiling build only), SSH digital key must be setup first for this to work, typical value has a pattern of usr@tgt:remote-loc|
-|URHO3D_NDK_GDB       |0|Enable ndk-gdb for debugging (Android build only)|
-|CMAKE_BUILD_TYPE     |*|Specify CMake build configuration to be generated (Makefile generator only), possible values are Release (\*default), Debug, and RelWithDebInfo|
+|CMAKE_BUILD_TYPE     |*|Specify CMake build configuration (single-configuration generator only), possible values are Release (\*default), RelWithDebInfo, and Debug|
 |CMAKE_OSX_DEPLOYMENT_TARGET|-|Specify Mac OS X deployment target (OSX build only); default to current running OS X if not specified|
 |CMAKE_OSX_DEPLOYMENT_TARGET|-|Specify Mac OS X deployment target (OSX build only); default to current running OS X if not specified|
 |IPHONEOS_DEPLOYMENT_TARGET|-|Specify iPhone OS deployment target (iOS build only); default to latest installed iOS SDK if not specified|
 |IPHONEOS_DEPLOYMENT_TARGET|-|Specify iPhone OS deployment target (iOS build only); default to latest installed iOS SDK if not specified|
-|ANDROID_ABI          |*|Specify target ABI (Android build only), possible values are armeabi, armeabi-v7a (\*default), armeabi-v7a with NEON, armeabi-v7a with VFPV3, armeabi-v6 with VFP, arm64-v8a, x86, and x86_64|
+|ANDROID_ABI          |*|Specify target ABI (Android build only), possible values are arm64-v8a, armeabi, armeabi-v6 with VFP, armeabi-v7a (\*default), armeabi-v7a with NEON, armeabi-v7a with VFPV3, mips, mips64, x86, and x86_64|
+|ANDROID_NATIVE_API_LEVEL|*|Specify target API level (Android build only), possible values depends on installed NDK version, default to API level 12 on 32-bit ABIs, default to API level 21 on 64-bit ABIs|
+|ANDROID_NDK_GDB      |0|Enable ndk-gdb support (Android Debug build only)|
 
 
 Note that build option values specified via command line are cached by CMake. The cached values will be used by CMake in the subsequent invocation. That is, the same build options are not required to be specified again and again. Once a non-default build option value is being cached, it can only be reverted back to its default value by explicitly setting it via command line. That is, simply by NOT passing the corresponding build option would not work. One way to revert all the build options to their default values is by clearing the CMake cache by calling cmake_clean.bat or cmake_clean.sh.
 Note that build option values specified via command line are cached by CMake. The cached values will be used by CMake in the subsequent invocation. That is, the same build options are not required to be specified again and again. Once a non-default build option value is being cached, it can only be reverted back to its default value by explicitly setting it via command line. That is, simply by NOT passing the corresponding build option would not work. One way to revert all the build options to their default values is by clearing the CMake cache by calling cmake_clean.bat or cmake_clean.sh.
 
 

+ 3 - 2
Rakefile

@@ -89,6 +89,7 @@ task :ci do
   $build_options = "-DURHO3D_64BIT=#{ENV['URHO3D_64BIT']}" if ENV['URHO3D_64BIT']
   $build_options = "-DURHO3D_64BIT=#{ENV['URHO3D_64BIT']}" if ENV['URHO3D_64BIT']
   $build_options = "#{$build_options} -DURHO3D_OPENGL=#{ENV['URHO3D_OPENGL']}" if ENV['URHO3D_OPENGL']
   $build_options = "#{$build_options} -DURHO3D_OPENGL=#{ENV['URHO3D_OPENGL']}" if ENV['URHO3D_OPENGL']
   $build_options = "#{$build_options} -DANDROID_ABI=#{ENV['ABI']}" if ENV['ABI']
   $build_options = "#{$build_options} -DANDROID_ABI=#{ENV['ABI']}" if ENV['ABI']
+  $build_options = "#{$build_options} -DANDROID_NATIVE_API_LEVEL=#{ENV['API']}" if ENV['API']
   if ENV['XCODE']
   if ENV['XCODE']
     # xctool or xcodebuild
     # xctool or xcodebuild
     xcode_ci
     xcode_ci
@@ -310,7 +311,7 @@ def makefile_ci
   end
   end
   system "./cmake_gcc.sh -DURHO3D_LIB_TYPE=$URHO3D_LIB_TYPE #{$build_options} -DURHO3D_LUA#{jit}=1 #{amalg} -DURHO3D_SAMPLES=1 -DURHO3D_TOOLS=1 -DURHO3D_EXTRAS=1 -DURHO3D_TESTING=#{$testing} -DCMAKE_BUILD_TYPE=#{$configuration}" or abort 'Failed to configure Urho3D library build'
   system "./cmake_gcc.sh -DURHO3D_LIB_TYPE=$URHO3D_LIB_TYPE #{$build_options} -DURHO3D_LUA#{jit}=1 #{amalg} -DURHO3D_SAMPLES=1 -DURHO3D_TOOLS=1 -DURHO3D_EXTRAS=1 -DURHO3D_TESTING=#{$testing} -DCMAKE_BUILD_TYPE=#{$configuration}" or abort 'Failed to configure Urho3D library build'
   if ENV['ANDROID']
   if ENV['ANDROID']
-    if ENV['AVD']
+    if ENV['AVD'] && !ENV['PACKAGE_UPLOAD']   # Skip APK test run when packaging
       android_prepare_device ENV['API'], ENV['ABI'], ENV['AVD'] or abort 'Failed to prepare Android (virtual) device for test run'
       android_prepare_device ENV['API'], ENV['ABI'], ENV['AVD'] or abort 'Failed to prepare Android (virtual) device for test run'
     end
     end
     # LuaJIT on Android build requires tolua++ and buildvm-android tools to be built natively first
     # LuaJIT on Android build requires tolua++ and buildvm-android tools to be built natively first
@@ -345,7 +346,7 @@ def makefile_ci
   scaffolding "#{platform_prefix}Build/generated/externallib"
   scaffolding "#{platform_prefix}Build/generated/externallib"
   system "URHO3D_HOME=`pwd`; export URHO3D_HOME && cd #{platform_prefix}Build/generated/externallib && echo '\nUsing Urho3D as external library in external project' && ./cmake_gcc.sh #{$build_options} -DURHO3D_LUA#{jit}=1 -DURHO3D_TESTING=#{$testing} -DCMAKE_BUILD_TYPE=#{$configuration} && cd #{platform_prefix}Build && make -j$NUMJOBS #{test}" or abort 'Failed to configure/build/test temporary project using Urho3D as external library' 
   system "URHO3D_HOME=`pwd`; export URHO3D_HOME && cd #{platform_prefix}Build/generated/externallib && echo '\nUsing Urho3D as external library in external project' && ./cmake_gcc.sh #{$build_options} -DURHO3D_LUA#{jit}=1 -DURHO3D_TESTING=#{$testing} -DCMAKE_BUILD_TYPE=#{$configuration} && cd #{platform_prefix}Build && make -j$NUMJOBS #{test}" or abort 'Failed to configure/build/test temporary project using Urho3D as external library' 
   # Make, deploy, and test run Android APK in an Android (virtual) device
   # Make, deploy, and test run Android APK in an Android (virtual) device
-  if ENV['AVD']
+  if ENV['AVD'] && !ENV['PACKAGE_UPLOAD']
     system "cd #{platform_prefix}Build && android update project -p . -t $( android list target |grep android-$API |cut -d ' ' -f2 ) && ant debug" or abort 'Failed to make Urho3D Samples APK'
     system "cd #{platform_prefix}Build && android update project -p . -t $( android list target |grep android-$API |cut -d ' ' -f2 ) && ant debug" or abort 'Failed to make Urho3D Samples APK'
     if android_wait_for_device ENV['CI'] ? 1 : 10 # minutes
     if android_wait_for_device ENV['CI'] ? 1 : 10 # minutes
       system "cd #{platform_prefix}Build && ant -Dadb.device.arg='-s #{$specific_device}' installd" or abort 'Failed to deploy Urho3D Samples APK'
       system "cd #{platform_prefix}Build && ant -Dadb.device.arg='-s #{$specific_device}' installd" or abort 'Failed to deploy Urho3D Samples APK'

+ 49 - 38
Readme.txt

@@ -247,54 +247,61 @@ to first clean the CMake cache by invoking cmake_clean.bat or cmake_clean.sh.
 Android build process
 Android build process
 ---------------------
 ---------------------
 
 
-First, if you are building under Windows platform without MKLINK support then
-copy Bin/Data and Bin/CoreData directories to the Source/Android/assets
-directory (you can use the provided batch file CopyData.bat). This step is not
-necessary for Windows with MKLINK support and non-Windows platforms because the
-build script uses symbolic links for platforms that support it.
+First, if you are building under Windows host without MKLINK support then copy
+Bin/Data and Bin/CoreData directories to the Source/Android/assets directory
+(you can use the provided batch file CopyData.bat). This step is not necessary
+for Windows with MKLINK support and non-Windows host because the build script
+uses symbolic links for host development environments that support it.
 
 
-Set the ANDROID_NDK environment variable to point to your Android NDK. On 
+Set the ANDROID_NDK environment variable to point to your Android NDK. On
 Windows, ensure that make.exe from the Android NDK is included in the path and
 Windows, ensure that make.exe from the Android NDK is included in the path and
 is executable from the command line.
 is executable from the command line.
 
 
-On Windows, execute cmake_android.bat. If MKLINK support is available, provide
-build option "-DURHO3D_MKLINK=1" to generate out-of-source build. Then go to the
-build directory Source/Android (or android-Build if out-of-source build) and
-execute the following commands. On OS X or Linux, execute cmake_gcc.sh (the
-ANDROID_NDK environment variable distinguishes from a normal desktop build) then
-go to the android-Build directory (always an out-of-source build) and execute
-the following commands.
-
-- android update project -p . -t 1 (only needed on the first time,
-                                    replace '-t 1' with desired target-id)
-- make -j8 (replace '-j8' with the number of logical CPU cores of the 
-            host/build system)
+On Windows, execute cmake_android.bat. If your user account has privilege to use
+MKLINK then you have the option to provide the build option "-DURHO3D_MKLINK=1"
+when invoking the cmake_android.bat to generate out-of-source build tree. Then
+go to the build tree directory which could be either 'Source/Android' or
+'android-Build' (when using MKLINK) and execute the below commands to start the
+build.
+
+- android update project -p . -t 1 (replace id to match the desired target API)
+- make -j8 (replace the number to match your host's number of logical CPU cores)
 - ant debug
 - ant debug
 
 
-After the commands finish successfully, the APK should have been generated to
-the build's "bin" subdirectory, from where it can be installed on a device or an
-emulator. The command "ant installd" can be used for this.
+On OS X or Linux, execute cmake_gcc.sh (the presence of ANDROID_NDK environment
+variable instructs the shell script to also generate project file for Android
+build besides normal desktop build). Then go to the build tree (which is
+currently defaulted to 'android-Build' directory) and execute the same commands
+as above.
+
+After the commands finish successfully, the APK should have been generated in
+the build tree's "bin" subdirectory, from where it can be installed on a device
+or an emulator. The command "ant installd" can be used for this. After the debug
+APK has been installed, you can use "rake android" command to automate the test
+running of the APK on the attached Android device.
 
 
 For a release build, use the "ant release" command instead of "ant debug" and
 For a release build, use the "ant release" command instead of "ant debug" and
 follow the Android SDK instructions on how to sign your APK properly.
 follow the Android SDK instructions on how to sign your APK properly.
 
 
 By default the Android package for Urho3D is com.googlecode.urho3d. For a real
 By default the Android package for Urho3D is com.googlecode.urho3d. For a real
 application you must replace this with your own package name. The Urho3D
 application you must replace this with your own package name. The Urho3D
-activity subclasses the SDLActivity from org.libsdl.app package, whose name
-(or the JNI code from SDL library) does not have to be changed.
+activity subclasses the SDLActivity from org.libsdl.app package, whose name (or
+the JNI code from SDL library) does not have to be changed.
 
 
 Note that the native code is built by default for armeabi-v7a ABI. To make your
 Note that the native code is built by default for armeabi-v7a ABI. To make your
 program compatible also with old Android devices, build also an armeabi version
 program compatible also with old Android devices, build also an armeabi version
-by executing the CMake batch file again with the parameter -DANDROID_ABI=armeabi
-added, then execute make again in the build directory. See "Build options" for
-all the possible values.
+by executing the CMake batch file or shell script again with the build option
+"-DANDROID_ABI=armeabi" added, then execute make again in the build directory.
+Similarly, the native code can be built using 64-bit ABI by changing the value
+of this build option. See \ref Build_Options "Build options" for all the
+possible values.
 
 
 You can also build and deploy using Eclipse IDE with ADT plugin. To do that,
 You can also build and deploy using Eclipse IDE with ADT plugin. To do that,
-after setting the ANDROID_NDK environment variable then run cmake_eclipse.sh.
-Import "Existing Android Code into Workspace" from the CMake generated Eclipse's
-project found in the android-Build directory. Switch Eclipse IDE to use Java
-Perspective. Update project properties to choose the desired Android API target
-and that's it. Just choose "Run" to let ADT automatically build and deploy the
+after setting the ANDROID_NDK environment variable then run cmake_eclipse.sh
+instead of cmake_gcc.sh. Import "Existing Android Code into Workspace" from the
+CMake generated Eclipse project file in the build tree. Switch Eclipse IDE to
+use Java Perspective. Update project properties to choose the desired Android
+API target. Choose "Run" to let ADT automatically build and deploy the
 application to Android (virtual) device.
 application to Android (virtual) device.
 
 
 
 
@@ -489,18 +496,22 @@ cmake_xxxx batch files or shell scripts.
 |                     | | Android cross-compiling build only), SSH digital key |
 |                     | | Android cross-compiling build only), SSH digital key |
 |                     | | must be setup first for this to work, typical value  |
 |                     | | must be setup first for this to work, typical value  |
 |                     | | has a pattern of usr@tgt:remote-loc                  |
 |                     | | has a pattern of usr@tgt:remote-loc                  |
-|URHO3D_NDK_GDB       |0|Enable ndk-gdb for debugging (Android build only)     |
-|CMAKE_BUILD_TYPE     |*|Specify CMake build configuration to be generated     |
-|                     | | (Makefile generator only), possible values are       |
-|                     | | Release (*default), Debug, and RelWithDebInfo        |
+|CMAKE_BUILD_TYPE     |*|Specify CMake build configuration (single-            |
+|                     | | configuration generator only), possible values are   |
+|                     | | Release (*default), RelWithDebInfo, and Debug        |
 |CMAKE_OSX_           |-|Specify Mac OS X deployment target (OSX build only);  |
 |CMAKE_OSX_           |-|Specify Mac OS X deployment target (OSX build only);  |
 | DEPLOYMENT_TARGET   | | default to current running OS X if not specified     |
 | DEPLOYMENT_TARGET   | | default to current running OS X if not specified     |
 |IPHONEOS_            |-|Specify iPhone OS deployment target (iOS build only); |
 |IPHONEOS_            |-|Specify iPhone OS deployment target (iOS build only); |
 | DEPLOYMENT_TARGET   | | default to latest installed iOS SDK if not specified |
 | DEPLOYMENT_TARGET   | | default to latest installed iOS SDK if not specified |
 |ANDROID_ABI          |*|Specify target ABI (Android build only), possible     |
 |ANDROID_ABI          |*|Specify target ABI (Android build only), possible     |
-|                     | | values are armeabi, armeabi-v7a (*default),          |
-|                     | | armeabi-v7a with NEON, armeabi-v7a with VFPV3,       |
-|                     | | armeabi-v6 with VFP, arm64-v8a, x86, and x86_64      |
+|                     | | values are arm64-v8a, armeabi, armeabi-v6 with VFP,  |
+|                     | | armeabi-v7a (*default), armeabi-v7a with NEON,       |
+|                     | | armeabi-v7a with VFPV3, mips, mips64, x86, and x86_64|
+|ANDROID_NATIVE_API   |*|Specify target API level (Android build only),        |
+| _LEVEL              | | possible values depends on installed NDK version,    |
+|                     | | default to API level 12 on 32-bit ABIs,              |
+|                     | | default to API level 21 on 64-bit ABIs               |
+|ANDROID_NDK_GDB      |0|Enable ndk-gdb support (Android Debug build only)     |
 |---------------------|-|------------------------------------------------------|
 |---------------------|-|------------------------------------------------------|
 
 
 Note that build option values specified via command line are cached by CMake.
 Note that build option values specified via command line are cached by CMake.

+ 33 - 19
Source/CMake/Modules/Urho3D-CMake-common.cmake

@@ -20,19 +20,25 @@
 # THE SOFTWARE.
 # THE SOFTWARE.
 #
 #
 
 
-# Set the build type if not explicitly set, for single-configuration generator only
+# Limit the supported build configurations
+set (URHO3D_BUILD_CONFIGURATIONS Release RelWithDebInfo Debug)
+set (DOC_STRING "Choose the build configuration, possible options are: ${URHO3D_BUILD_CONFIGURATIONS}")
+if (CMAKE_CONFIGURATION_TYPES)
+    # For multi-configurations generator, such as VS and Xcode
+    set (CMAKE_CONFIGURATION_TYPES ${URHO3D_BUILD_CONFIGURATIONS} CACHE STRING "${DOC_STRING}" FORCE)
+else ()
+    # For single-configuration generator, such as Unix Makefile generator
+    if (CMAKE_BUILD_TYPE STREQUAL "")
+        # If not specified then default to Release
+        set (CMAKE_BUILD_TYPE Release)
+    endif ()
+    set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "${DOC_STRING}" FORCE)
+endif ()
+
+# Define other useful variables not defined by CMake
 if (CMAKE_GENERATOR STREQUAL Xcode)
 if (CMAKE_GENERATOR STREQUAL Xcode)
     set (XCODE TRUE)
     set (XCODE TRUE)
 endif ()
 endif ()
-if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
-    set (CMAKE_BUILD_TYPE Release)
-endif ()
-if (CMAKE_HOST_WIN32)
-    execute_process (COMMAND uname -o RESULT_VARIABLE UNAME_EXIT_CODE OUTPUT_VARIABLE UNAME_OPERATING_SYSTEM ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
-    if (UNAME_EXIT_CODE EQUAL 0 AND UNAME_OPERATING_SYSTEM STREQUAL Msys)
-        set (MSYS 1)
-    endif ()
-endif ()
 
 
 # Define all supported build options
 # Define all supported build options
 include (CMakeDependentOption)
 include (CMakeDependentOption)
@@ -53,7 +59,7 @@ if (NOT MSVC)
         string (REGEX MATCH "#define +__arm__ +1" matched "${PREDEFINED_MACROS}")
         string (REGEX MATCH "#define +__arm__ +1" matched "${PREDEFINED_MACROS}")
         if (matched)
         if (matched)
             # Set the CMake variable here instead of in raspberrypi.toolchain.cmake because Raspberry Pi can be built natively too
             # Set the CMake variable here instead of in raspberrypi.toolchain.cmake because Raspberry Pi can be built natively too
-            set (RASPI TRUE CACHE STRING "Setup build for Raspberry Pi platform")
+            set (RASPI TRUE CACHE INTERNAL "Setup build for Raspberry Pi platform")
         endif ()
         endif ()
     endif ()
     endif ()
 endif ()
 endif ()
@@ -115,17 +121,22 @@ else ()
     unset (URHO3D_SCP_TO_TARGET CACHE)
     unset (URHO3D_SCP_TO_TARGET CACHE)
 endif ()
 endif ()
 if (ANDROID)
 if (ANDROID)
-    set (ANDROID TRUE CACHE STRING "Setup build for Android platform")  # Cache the CMake variable
-    set (ANDROID_ABI armeabi-v7a CACHE STRING "Specify ABI for native code (Android build only), possible values are armeabi, armeabi-v7a (default), armeabi-v7a with NEON, armeabi-v7a with VFPV3, armeabi-v6 with VFP, arm64-v8a, x86, and x86_64")
-    cmake_dependent_option (URHO3D_NDK_GDB "Enable ndk-gdb for debugging (Android build only)" FALSE "CMAKE_BUILD_TYPE STREQUAL Debug" FALSE)
+    set (ANDROID TRUE CACHE INTERNAL "Setup build for Android platform")
+    cmake_dependent_option (ANDROID_NDK_GDB "Enable ndk-gdb for debugging (Android build only)" FALSE "CMAKE_BUILD_TYPE STREQUAL Debug" FALSE)
 else ()
 else ()
-    unset (ANDROID_ABI CACHE)
-    unset (URHO3D_NDK_GDB CACHE)
+    unset (ANDROID_NDK_GDB CACHE)
     if (ANDROID_ABI)
     if (ANDROID_ABI)
         # Just reference it to suppress "unused variable" CMake warning on non-Android project
         # Just reference it to suppress "unused variable" CMake warning on non-Android project
         # Due to the design of cmake_gcc.sh currently, the script can be used to configure/generate Android project and other non-Android projects in one go
         # Due to the design of cmake_gcc.sh currently, the script can be used to configure/generate Android project and other non-Android projects in one go
     endif ()
     endif ()
 endif ()
 endif ()
+# Constrain the build option values in cmake-gui, if applicable
+if (CMAKE_VERSION VERSION_GREATER 2.8 OR CMAKE_VERSION VERSION_EQUAL 2.8)
+    set_property (CACHE URHO3D_LIB_TYPE PROPERTY STRINGS STATIC SHARED)
+    if (NOT CMAKE_CONFIGURATION_TYPES)
+        set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${URHO3D_BUILD_CONFIGURATIONS})
+    endif ()
+endif()
 
 
 # Enable testing
 # Enable testing
 if (URHO3D_TESTING)
 if (URHO3D_TESTING)
@@ -327,7 +338,7 @@ else ()
             # Additional compiler flags for Windows ports of GCC
             # Additional compiler flags for Windows ports of GCC
             set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
             set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
-            # Reduce GCC optimization level from -O3 to -O2 for stability in RELEASE build type
+            # Reduce GCC optimization level from -O3 to -O2 for stability in RELEASE build configuration
             set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
             set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
         endif ()
         endif ()
@@ -379,7 +390,7 @@ endif ()
 set_output_directories (${PROJECT_ROOT_DIR}/${PLATFORM_PREFIX}Bin RUNTIME PDB)
 set_output_directories (${PROJECT_ROOT_DIR}/${PLATFORM_PREFIX}Bin RUNTIME PDB)
 
 
 # Enable Android ndk-gdb
 # Enable Android ndk-gdb
-if (URHO3D_NDK_GDB)
+if (ANDROID_NDK_GDB)
     set (NDK_GDB_SOLIB_PATH ${PROJECT_BINARY_DIR}/obj/local/${ANDROID_NDK_ABI_NAME}/)
     set (NDK_GDB_SOLIB_PATH ${PROJECT_BINARY_DIR}/obj/local/${ANDROID_NDK_ABI_NAME}/)
     file (MAKE_DIRECTORY ${NDK_GDB_SOLIB_PATH})
     file (MAKE_DIRECTORY ${NDK_GDB_SOLIB_PATH})
     set (NDK_GDB_JNI ${PROJECT_BINARY_DIR}/jni)
     set (NDK_GDB_JNI ${PROJECT_BINARY_DIR}/jni)
@@ -394,6 +405,8 @@ if (URHO3D_NDK_GDB)
     set (NDK_GDB_SETUP "# This is a generated file. DO NOT EDIT!\n\nset solib-search-path ${NDK_GDB_SOLIB_PATH}\ndirectory ${INCLUDE_DIRECTORIES}\n")
     set (NDK_GDB_SETUP "# This is a generated file. DO NOT EDIT!\n\nset solib-search-path ${NDK_GDB_SOLIB_PATH}\ndirectory ${INCLUDE_DIRECTORIES}\n")
     file (WRITE ${ANDROID_LIBRARY_OUTPUT_PATH}/gdb.setup ${NDK_GDB_SETUP})
     file (WRITE ${ANDROID_LIBRARY_OUTPUT_PATH}/gdb.setup ${NDK_GDB_SETUP})
     file (COPY ${ANDROID_NDK}/prebuilt/android-${ANDROID_ARCH_NAME}/gdbserver/gdbserver DESTINATION ${ANDROID_LIBRARY_OUTPUT_PATH})
     file (COPY ${ANDROID_NDK}/prebuilt/android-${ANDROID_ARCH_NAME}/gdbserver/gdbserver DESTINATION ${ANDROID_LIBRARY_OUTPUT_PATH})
+elseif (ANDROID)
+    file (REMOVE ${ANDROID_LIBRARY_OUTPUT_PATH}/gdbserver)
 endif ()
 endif ()
 
 
 # Override builtin macro and function to suit our need, always generate header file regardless of target type...
 # Override builtin macro and function to suit our need, always generate header file regardless of target type...
@@ -608,6 +621,7 @@ macro (add_android_native_init)
         # Search using Urho3D SDK installation location which could be rooted
         # Search using Urho3D SDK installation location which could be rooted
         find_file (ANDROID_MAIN_C_PATH SDL_android_main.c PATH_SUFFIXES ${PATH_SUFFIX} DOC "Path to SDL_android_main.c")
         find_file (ANDROID_MAIN_C_PATH SDL_android_main.c PATH_SUFFIXES ${PATH_SUFFIX} DOC "Path to SDL_android_main.c")
     endif ()
     endif ()
+    mark_as_advanced (ANDROID_MAIN_C_PATH)  # Hide it from cmake-gui in non-advanced mode
     if (ANDROID_MAIN_C_PATH)
     if (ANDROID_MAIN_C_PATH)
         list (APPEND SOURCE_FILES ${ANDROID_MAIN_C_PATH})
         list (APPEND SOURCE_FILES ${ANDROID_MAIN_C_PATH})
     else ()
     else ()
@@ -645,7 +659,7 @@ macro (setup_main_executable)
                     COMMENT "Copying ${NAME} to library output directory")
                     COMMENT "Copying ${NAME} to library output directory")
             endif ()
             endif ()
         endforeach ()
         endforeach ()
-        if (URHO3D_NDK_GDB)
+        if (ANDROID_NDK_GDB)
             # Copy the library while it still has debug symbols for ndk-gdb
             # Copy the library while it still has debug symbols for ndk-gdb
             add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
             add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
                 COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${NDK_GDB_SOLIB_PATH}
                 COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${NDK_GDB_SOLIB_PATH}

+ 15 - 7
Source/CMake/Toolchains/android.toolchain.cmake

@@ -853,9 +853,14 @@ else()
   unset( __realApiLevel )
   unset( __realApiLevel )
  endif()
  endif()
  set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
  set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
- if( CMAKE_VERSION VERSION_GREATER "2.8" )
-  list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
-  set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
+ # Urho3D: Sort in numerical order instead of alphabetical order
+ if( CMAKE_VERSION VERSION_GREATER 2.8 OR CMAKE_VERSION VERSION_EQUAL 2.8 )  # Feature avaiable starting from CMake 2.8
+  string(REGEX REPLACE ";([1-9]);" ";0\\1;" PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS ";${ANDROID_SUPPORTED_NATIVE_API_LEVELS};")
+  string(REGEX REPLACE ";([1-9]);" ";0\\1;" PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS "${PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS}")
+  list( SORT PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS )
+  string(REGEX REPLACE ";0([1-9]);" ";\\1;" PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS "${PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS}")
+  string(REGEX REPLACE ";0([1-9]);" ";\\1;" PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS "${PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS}")
+  set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${PADDED_ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
  endif()
  endif()
 endif()
 endif()
 unset( __levelIdx )
 unset( __levelIdx )
@@ -863,9 +868,10 @@ unset( __levelIdx )
 
 
 # remember target ABI
 # remember target ABI
 set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
 set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
-if( CMAKE_VERSION VERSION_GREATER "2.8" )
- list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} )
- set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} )
+# Urho3D: fix to present the full list of supported ABIs initially
+if( CMAKE_VERSION VERSION_GREATER 2.8 OR CMAKE_VERSION VERSION_EQUAL 2.8 )
+ list( SORT ANDROID_SUPPORTED_ABIS )
+ set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS} )
 endif()
 endif()
 
 
 
 
@@ -1527,7 +1533,8 @@ if( ANDROID_EXPLICIT_CRT_LINK )
 endif()
 endif()
 
 
 # setup output directories
 # setup output directories
-set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
+# Urho3D: Prefer binary dir over source dir, which is anyway equal to source dir when not using out-of-source build tree
+set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
 set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
 set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
 
 
 if(NOT _CMAKE_IN_TRY_COMPILE)
 if(NOT _CMAKE_IN_TRY_COMPILE)
@@ -1538,6 +1545,7 @@ if(NOT _CMAKE_IN_TRY_COMPILE)
  endif()
  endif()
  # Urho3D: All libraries are first generated in CMake default binary directory and only the main target library is later copied to below output path by Urho3D own build script
  # Urho3D: All libraries are first generated in CMake default binary directory and only the main target library is later copied to below output path by Urho3D own build script
  set( ANDROID_LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" FORCE )
  set( ANDROID_LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" FORCE )
+ mark_as_advanced (ANDROID_LIBRARY_OUTPUT_PATH)
 endif()
 endif()
 
 
 # Urho3D: Copy shared STL library to final Android library output path pointed by ANDROID_LIBRARY_OUTPUT_PATH variable as CMake's LIBRARY_OUTPUT_PATH still points to its default
 # Urho3D: Copy shared STL library to final Android library output path pointed by ANDROID_LIBRARY_OUTPUT_PATH variable as CMake's LIBRARY_OUTPUT_PATH still points to its default

+ 1 - 1
Source/Engine/CMakeLists.txt

@@ -268,7 +268,7 @@ if (URHO3D_LIB_TYPE STREQUAL SHARED)
 endif ()
 endif ()
 
 
 # Define post build steps
 # Define post build steps
-if (URHO3D_NDK_GDB)
+if (ANDROID_NDK_GDB)
     # Copy the library while it still has debug symbols for ndk-gdb
     # Copy the library while it still has debug symbols for ndk-gdb
     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${NDK_GDB_SOLIB_PATH}
     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${NDK_GDB_SOLIB_PATH}
         COMMENT "Copying Urho3D library with debug symbols to ${NDK_GDB_SOLIB_PATH} directory")
         COMMENT "Copying Urho3D library with debug symbols to ${NDK_GDB_SOLIB_PATH} directory")

+ 1 - 1
cmake_android.bat

@@ -50,5 +50,5 @@ if "%use_mklink%" == "1" (
 ) 
 ) 
 echo on
 echo on
 @set "OPT="
 @set "OPT="
-cmake -E chdir %build% cmake %OPT% -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=%source%\CMake\Toolchains\android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=.  %* %source%
+cmake -E chdir %build% cmake %OPT% -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=%source%\CMake\Toolchains\android.toolchain.cmake %* %source%
 @popd
 @popd

+ 1 - 1
cmake_gcc.sh

@@ -46,7 +46,7 @@ GENERATOR="Unix Makefiles"
 
 
 # Create project with the respective CMake generators
 # Create project with the respective CMake generators
 OPT=
 OPT=
-[ $ANDROID_NDK ] && msg "Android build" && cmake -E make_directory android-Build && cmake -E chdir android-Build cmake $OPT -G $GENERATOR -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. $@ $SOURCE && post_cmake android-Build
+[ $ANDROID_NDK ] && msg "Android build" && cmake -E make_directory android-Build && cmake -E chdir android-Build cmake $OPT -G $GENERATOR -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/android.toolchain.cmake $@ $SOURCE && post_cmake android-Build
 [ $RASPI_TOOL ] && msg "Raspberry Pi build" && cmake -E make_directory raspi-Build && cmake -E chdir raspi-Build cmake $OPT -G $GENERATOR -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/raspberrypi.toolchain.cmake $@ $SOURCE && post_cmake raspi-Build
 [ $RASPI_TOOL ] && msg "Raspberry Pi build" && cmake -E make_directory raspi-Build && cmake -E chdir raspi-Build cmake $OPT -G $GENERATOR -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/raspberrypi.toolchain.cmake $@ $SOURCE && post_cmake raspi-Build
 [ $MINGW_PREFIX ] && msg "MinGW build" && cmake -E make_directory mingw-Build && cmake -E chdir mingw-Build cmake $OPT -G $GENERATOR -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/mingw.toolchain.cmake $@ $SOURCE && post_cmake mingw-Build
 [ $MINGW_PREFIX ] && msg "MinGW build" && cmake -E make_directory mingw-Build && cmake -E chdir mingw-Build cmake $OPT -G $GENERATOR -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/mingw.toolchain.cmake $@ $SOURCE && post_cmake mingw-Build
 [ ! $SKIP_NATIVE ] && msg "Native build" && cmake -E make_directory Build && cmake -E chdir Build cmake $OPT -G $GENERATOR $PLATFORM $@ $SOURCE && post_cmake Build
 [ ! $SKIP_NATIVE ] && msg "Native build" && cmake -E make_directory Build && cmake -E chdir Build cmake $OPT -G $GENERATOR $PLATFORM $@ $SOURCE && post_cmake Build