Browse Source

Improve the reliablity to find SDL_android_main.c when using SDK.
Replace usage of URHO3D_INSTALL_PREFIX environment variable with the more standard CMake's own CMAKE_PREFIX_PATH environment variable to define prefix path of non-standard SDK installation location.

Yao Wei Tjong 姚伟忠 11 years ago
parent
commit
08f08e460b

+ 3 - 3
Docs/GettingStarted.dox

@@ -401,20 +401,20 @@ The setup_main_executable() macro then uses SOURCE_FILES and TARGET_NAME variabl
 
 \section UsingLibraryFromSDK From Urho3D SDK installation
 
-This section assumes that you have already installed Urho3D SDK into your system. If you have installed the SDK in a non-default location then you need to use "URHO3D_INSTALL_PREFIX" environment variable to specify the prefix path of the non-default installation location.
+This section assumes that you have already installed Urho3D SDK into your system. If you have installed the SDK in a non-default location then you need to use "CMAKE_PREFIX_PATH" environment variable to specify the prefix path of the non-default installation location.
 
 In your own project Source/ directory, create a new CMakeLists.txt file similar to the first approach but change the CMake module search path setup to read as follows on Windows platform:
 
 \code
 # Set CMake modules search path
-set (CMAKE_MODULE_PATH $ENV{URHO3D_INSTALL_PREFIX}/share/CMake/Modules ${CMAKE_INSTALL_PREFIX}/share/CMake/Modules CACHE PATH "Path to Urho3D-specific CMake modules")
+set (CMAKE_MODULE_PATH $ENV{CMAKE_PREFIX_PATH}/share/CMake/Modules CACHE PATH "Path to Urho3D-specific CMake modules")
 \endcode
 
 On non-Windows platform:
 
 \code
 # Set CMake modules search path
-set (CMAKE_MODULE_PATH $ENV{URHO3D_INSTALL_PREFIX}/share/Urho3D/CMake/Modules ${CMAKE_INSTALL_PREFIX}/share/Urho3D/CMake/Modules CACHE PATH "Path to Urho3D-specific CMake modules")
+set (CMAKE_MODULE_PATH $ENV{CMAKE_PREFIX_PATH}/share/Urho3D/CMake/Modules CACHE PATH "Path to Urho3D-specific CMake modules")
 \endcode
 
 \subsection UsingLibraryFromSDKWithPkgConfig Using pkg-config instead of CMake

+ 2 - 3
Rakefile

@@ -41,7 +41,7 @@ task :scaffolding do
   scaffolding(abs_path, project, target)
   abs_path = Pathname.new(abs_path).realpath
   puts "\nNew project created in #{abs_path}\n\n"
-  puts "To build the new project, you may need to first define and export either 'URHO3D_HOME' or 'URHO3D_INSTALL_PREFIX' environment variable"
+  puts "To build the new project, you may need to first define and export either 'URHO3D_HOME' or 'CMAKE_PREFIX_PATH' environment variable"
   puts "Please see http://urho3d.github.io/documentation/a00004.html for more detail. For example:\n\n"
   puts "$ URHO3D_HOME=#{Dir.pwd}; export URHO3D_HOME\n$ cd #{abs_path}\n$ ./cmake_gcc.sh -DURHO3D_64BIT=1 -DURHO3D_LUAJIT=1\n$ cd Build\n$ make\n\n"
 end
@@ -194,8 +194,7 @@ endif ()
 # Set CMake modules search path
 set (CMAKE_MODULE_PATH
     \\$ENV{URHO3D_HOME}/Source/CMake/Modules
-    \\$ENV{URHO3D_INSTALL_PREFIX}/share/Urho3D/CMake/Modules
-    \\${CMAKE_INSTALL_PREFIX}/share/Urho3D/CMake/Modules
+    \\$ENV{CMAKE_PREFIX_PATH}/share/Urho3D/CMake/Modules
     CACHE PATH \"Path to Urho3D-specific CMake modules\")
 
 # Include Urho3D CMake common module

+ 5 - 10
Source/CMake/Modules/FindUrho3D.cmake

@@ -103,14 +103,10 @@ if (URHO3D_HOME)
         endif ()
     endif ()
 else ()
-    # If Urho3D SDK is not being installed in the default system location, use the URHO3D_INSTALL_PREFIX environment variable to specify the prefix path to that location
+    # If Urho3D SDK is not being installed in the default system location, use the CMAKE_PREFIX_PATH environment variable to specify the prefix path to that location
     # Note that the prefix path should not contain the "/include" or "/lib"
-    # For example on Windows platform: URHO3D_INSTALL_PREFIX=C:/Users/john/Urho3D if the SDK is installed using CMAKE_INSTALL_PREFIX=C:/Users/john/Urho3D
-    # For example on Linux platform: URHO3D_INSTALL_PREFIX=/home/john/usr/local if the SDK is installed using DESTDIR=/home/john and CMAKE_INSTALL_PREFIX=/usr/local
-    if (NOT CMAKE_PREFIX_PATH AND DEFINED ENV{URHO3D_INSTALL_PREFIX})
-        file (TO_CMAKE_PATH "$ENV{URHO3D_INSTALL_PREFIX}" URHO3D_INSTALL_PREFIX)
-        set (CMAKE_PREFIX_PATH ${URHO3D_INSTALL_PREFIX} CACHE PATH "Prefix path to Urho3D SDK installation")
-    endif ()
+    # For example on Windows platform: CMAKE_PREFIX_PATH=C:/Users/john/Urho3D if the SDK is installed using CMAKE_INSTALL_PREFIX=C:/Users/john/Urho3D
+    # For example on Linux platform: CMAKE_PREFIX_PATH=/home/john/usr/local if the SDK is installed using DESTDIR=/home/john and CMAKE_INSTALL_PREFIX=/usr/local
     if (WIN32)
         set (URHO3D_INC_SEARCH_PATH include)
         set (URHO3D_LIB_SEARCH_PATH lib)
@@ -119,9 +115,8 @@ else ()
         if (IOS)
             set (CMAKE_LIBRARY_ARCHITECTURE ios)
         endif ()
-        set (URHO3D_INC_SEARCH_PATH /opt/include)
-        set (URHO3D_LIB_SEARCH_PATH /opt/lib)
     endif ()
+    # Additional search paths are added by CMake by default which should already include most common platform specific paths
     find_path (URHO3D_INCLUDE_DIRS Urho3D.h PATHS ${URHO3D_INC_SEARCH_PATH} PATH_SUFFIXES ${PATH_SUFFIX})
     find_library (URHO3D_LIBRARIES NAMES ${URHO3D_LIB_NAMES} PATHS ${URHO3D_LIB_SEARCH_PATH} PATH_SUFFIXES ${PATH_SUFFIX})
     if (WIN32)
@@ -165,7 +160,7 @@ else ()
     if (Urho3D_FIND_REQUIRED)
         message (FATAL_ERROR
             "Could not find Urho3D library in default SDK installation location or Urho3D project root tree. "
-            "For searching in a non-default Urho3D SDK installation, use 'URHO3D_INSTALL_PREFIX' environment variable to specify the prefix path of the installation location. "
+            "For searching in a non-default Urho3D SDK installation, use 'CMAKE_PREFIX_PATH' environment variable to specify the prefix path of the installation location. "
             "For searching in a build tree of Urho3D project, use 'URHO3D_HOME' environment variable to specify the Urho3D project root directory. The Urho3D library itself must already be built successfully.")
     endif ()
 endif ()

+ 8 - 12
Source/CMake/Modules/Urho3D-CMake-common.cmake

@@ -511,21 +511,17 @@ endmacro ()
 macro (add_android_native_init)
     # This source file could not be added when building SDL static library because it needs SDL_Main() which is not yet available at library building time
     # The SDL_Main() is defined by Android application that could be resided in other CMake projects outside of Urho3D CMake project which makes things a little bit complicated
-    if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
-        list (APPEND SOURCE_FILES ${PROJECT_ROOT_DIR}/Source/ThirdParty/SDL/src/main/android/SDL_android_main.c)
-    elseif (EXISTS ${URHO3D_HOME}/Source/ThirdParty/SDL/src/main/android/SDL_android_main.c)
-        # Use Urho3D source installation
-        list (APPEND SOURCE_FILES ${URHO3D_HOME}/Source/ThirdParty/SDL/src/main/android/SDL_android_main.c)
-    elseif (EXISTS ${CMAKE_PREFIX_PATH}/share/${PATH_SUFFIX}/templates/android/SDL_android_main.c)
-        # Use Urho3D SDK installation on non-default installation location (PATH_SUFFIX variable is set in FindUrho3D.cmake module)
-        list (APPEND SOURCE_FILES ${CMAKE_PREFIX_PATH}/share/${PATH_SUFFIX}/templates/android/SDL_android_main.c)
-    elseif (EXISTS ${CMAKE_INSTALL_PREFIX}/share/${PATH_SUFFIX}/templates/android/SDL_android_main.c)
-        # Use Urho3D SDK installation on system default installation location
-        list (APPEND SOURCE_FILES ${CMAKE_INSTALL_PREFIX}/share/${PATH_SUFFIX}/templates/android/SDL_android_main.c)
+    find_file (ANDROID_MAIN_C_PATH SDL_android_main.c PATHS ${URHO3D_HOME}/Source/ThirdParty/SDL/src/main/android DOC "Path to SDL_android_main.c" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+    if (NOT ANDROID_MAIN_C_PATH)
+        # Attempt another 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")
+    endif ()
+    if (ANDROID_MAIN_C_PATH)
+        list (APPEND SOURCE_FILES ${ANDROID_MAIN_C_PATH})
     else ()
         message (FATAL_ERROR
             "Could not find SDL_android_main.c source file in default SDK installation location or Urho3D project root tree. "
-            "For searching in a non-default Urho3D SDK installation, use 'URHO3D_INSTALL_PREFIX' environment variable to specify the prefix path of the installation location. "
+            "For searching in a non-default Urho3D SDK installation, use 'CMAKE_PREFIX_PATH' environment variable to specify the prefix path of the installation location. "
             "For searching in a source tree of Urho3D project, use 'URHO3D_HOME' environment variable to specify the Urho3D project root directory.")
     endif ()
 endmacro ()

+ 1 - 1
Source/ThirdParty/SDL/CMakeLists.txt

@@ -115,7 +115,7 @@ set (SOURCE_FILES ${C_FILES} ${SYS_C_FILES} ${H_FILES})
 # Install dependency for SDL_android_main.c, D3D9GraphicsImpl.h, OGLGraphicsImpl.h, InputEvents.h, File.h, and Cursor.h
 install (DIRECTORY include/ DESTINATION ${DEST_INCLUDE_DIR}/SDL ${DEST_PERMISSIONS} FILES_MATCHING PATTERN *.h)     # Note: the trailing slash is significant
 set (INSTALL_INCLUDE_DIRS ${INSTALL_INCLUDE_DIRS} SDL PARENT_SCOPE)
-install (FILES src/main/android/SDL_android_main.c DESTINATION ${DEST_SHARE_DIR}/templates/android)
+install (FILES src/main/android/SDL_android_main.c DESTINATION ${DEST_INCLUDE_DIR})
 
 # Define dependency libs
 set (INCLUDE_DIRS_ONLY include)