Browse Source

Refactor build scripts to auto detect ANDROID and RASPI build options.

Yao Wei Tjong 姚伟忠 11 years ago
parent
commit
e0e3b11757
5 changed files with 29 additions and 24 deletions
  1. 1 1
      Docs/GettingStarted.dox
  2. 1 3
      Readme.txt
  3. 24 17
      Source/CMake/Modules/Urho3D-CMake-common.cmake
  4. 1 1
      cmake_android.bat
  5. 2 2
      cmake_gcc.sh

+ 1 - 1
Docs/GettingStarted.dox

@@ -197,7 +197,7 @@ Steps to configure:
 -# In the Urho3D project root directory, invoke "cmake-gui Source".
 -# Set the build directory name.
 -# Configure and update the build options as many times as necessary until there are no more new options in red. For the first configuration, choose the generator you like to use. Click the Group check box to group the build options.
-    - In the Ungrouped Entries: only check one of these options (ANDROID, IOS, RASPI) when you target the platform, leave them unchecked for dekstop/native build.
+    - In the Ungrouped Entries: check IOS option when targeting it on Xcode.
     - In the URHO3D group: check any of the options you desire. Some of the options when checked may cause new options to be made available in the subsequent configuration loop.
 -# Generate when all the configurations are done.
 

+ 1 - 3
Readme.txt

@@ -547,9 +547,7 @@ Steps to configure:
    are no more new options in red. For the first configuration, choose the
    generator you like to use. Click the Group check box to group the build
    options.
-    - In the Ungrouped Entries: only check one of these options (ANDROID, IOS,
-      RASPI) when you target the platform, leave them unchecked for
-      dekstop/native build.
+    - In the Ungrouped Entries: check IOS option when targeting it on Xcode.
     - In the URHO3D group: check any of the options you desire. Some of the
       options when checked may cause new options to be made available in the
       subsequent configuration loop.

+ 24 - 17
Source/CMake/Modules/Urho3D-CMake-common.cmake

@@ -20,11 +20,23 @@
 # THE SOFTWARE.
 #
 
+# Set the build type if not explicitly set, for single-configuration generator only
+if (CMAKE_GENERATOR STREQUAL Xcode)
+    set (XCODE TRUE)
+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
 include (CMakeDependentOption)
-option (ANDROID "Setup build for Android platform")
-option (RASPI "Setup build for Raspberry Pi platform")
-option (IOS "Setup build for iOS platform")
+cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
 if (NOT MSVC)
     # On non-MSVC compiler, default to build 64-bit when the host system has a 64-bit build environment
     execute_process (COMMAND echo COMMAND ${CMAKE_C_COMPILER} -E -dM - OUTPUT_VARIABLE PREDEFINED_MACROS ERROR_QUIET)
@@ -35,6 +47,15 @@ if (NOT MSVC)
     if (matched)
         set (URHO3D_DEFAULT_64BIT TRUE)
     endif ()
+    # The 'ANDROID' CMake variable is already set by android.toolchain.cmake when it is being used for cross-compiling Android
+    # The other arm platform that Urho3D supports that is not Android is Raspberry Pi at the moment
+    if (NOT ANDROID)
+        string (REGEX MATCH "#define +__arm__ +1" matched "${PREDEFINED_MACROS}")
+        if (matched)
+            # Set the CMake variable here instead of in raspberrypi.toolchain.cmake because Raspberry Pi can be built natively too
+            set (RASPI TRUE)
+        endif ()
+    endif ()
 endif ()
 option (URHO3D_64BIT "Enable 64-bit build" ${URHO3D_DEFAULT_64BIT})
 option (URHO3D_ANGELSCRIPT "Enable AngelScript scripting support" TRUE)
@@ -103,20 +124,6 @@ else ()
     endif ()
 endif ()
 
-# Set the build type if not explicitly set, for single-configuration generator only
-if (CMAKE_GENERATOR STREQUAL Xcode)
-    set (XCODE TRUE)
-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 ()
-
 # Enable testing
 if (URHO3D_TESTING)
     enable_testing ()

+ 1 - 1
cmake_android.bat

@@ -50,5 +50,5 @@ if "%use_mklink%" == "1" (
 ) 
 echo on
 @set "OPT="
-cmake -E chdir %build% cmake %OPT% -G "Unix Makefiles" -DANDROID=1 -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 -DLIBRARY_OUTPUT_PATH_ROOT=.  %* %source%
 @popd

+ 2 - 2
cmake_gcc.sh

@@ -46,8 +46,8 @@ GENERATOR="Unix Makefiles"
 
 # Create project with the respective CMake generators
 OPT=
-[ $ANDROID_NDK ] && msg "Android build" && cmake -E make_directory android-Build && cmake -E chdir android-Build cmake $OPT -G $GENERATOR -DANDROID=1 -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. $@ $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 -DRASPI=1 -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAINS/raspberrypi.toolchain.cmake $@ $SOURCE && post_cmake raspi-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 -DLIBRARY_OUTPUT_PATH_ROOT=. $@ $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
 [ $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
 unset IFS