Browse Source

Refactor installation structure for Windows platform.
Attempt to reenable the try_compile logic to verify if the found Urho3D
library is ABI-compatible with the chosen compiler toolchain.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
f471dd66dd

+ 2 - 1
.appveyor.yml

@@ -32,6 +32,7 @@ environment:
     secure: cc1q9CXo5BwIYqtgigHpkCGG90zEVM45xx/YzXTOjVp512oQNUzTJq0AmxEYXP78
   build_tree: native-Build
   config: Release
+  PreferredToolArchitecture: x64
   matrix:
     - URHO3D_LIB_TYPE: STATIC
     - URHO3D_LIB_TYPE: SHARED
@@ -55,7 +56,7 @@ build_script:
   - rake cmake vs2015 %OPTS% URHO3D_LIB_TYPE=%URHO3D_LIB_TYPE% URHO3D_D3D11=1 URHO3D_LUAJIT=1 URHO3D_LUAJIT_AMALG=1 URHO3D_EXTRAS=1 URHO3D_TESTING=1 && rake make
 # Could not run test target yet as AppVeyor does not currently allow its service to interact with desktop
 # - rake make target=RUN_TESTS
-  - if "%PACKAGE_UPLOAD%" == "1" (echo "Packaging the build artifact..." && rake ci_appveyor_package_upload) else (echo "Configuring downstream project using Urho3D library in its build tree..." && rake scaffolding dir=UsingBuildTree && cd UsingBuildTree && rake cmake vs2015 %OPTS% URHO3D_HOME=..\..\native-Build URHO3D_D3D11=1 && rake make && echo "Installing Urho3D SDK to default system-wide location..." && cd .. && rake make target=install >nul && echo "Configuring downstream project using Urho3D SDK..." && rake scaffolding dir=UsingSDK && cd UsingSDK && rake cmake vs2015 %OPTS% URHO3D_D3D11=1 && rake make)
+  - if "%PACKAGE_UPLOAD%" == "1" (echo "Packaging the build artifact..." && rake ci_appveyor_package_upload) else (echo Configuring downstream project using Urho3D library in its build tree... && rake scaffolding dir=UsingBuildTree >nul && cd UsingBuildTree && rake cmake vs2015 %OPTS% URHO3D_HOME=..\..\native-Build URHO3D_D3D11=1 && rake make && echo Installing Urho3D SDK to default system-wide location... && cd .. && rake make target=install >nul && echo Configuring downstream project using Urho3D SDK... && rake scaffolding dir=UsingSDK >null && cd UsingSDK && rake cmake vs2015 %OPTS% URHO3D_D3D11=1 && rake make)
 test: off
 artifacts:
   - path: native-Build\*.zip

+ 25 - 14
CMake/Modules/FindUrho3D.cmake

@@ -46,15 +46,15 @@ set (PATH_SUFFIX Urho3D)
 if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND TARGET Urho3D)
     # A special case where library location is already known to be in the build tree of Urho3D project
     set (URHO3D_HOME ${CMAKE_BINARY_DIR})
-    set (URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include ${URHO3D_HOME}/include/${PATH_SUFFIX}/ThirdParty)
+    set (URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include ${URHO3D_HOME}/include/Urho3D/ThirdParty)
     if (URHO3D_PHYSICS)
         # Bullet library depends on its own include dir to be added in the header search path
         # This is more practical than patching its header files in many places to make them work with relative path
-        list (APPEND URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include/${PATH_SUFFIX}/ThirdParty/Bullet)
+        list (APPEND URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include/Urho3D/ThirdParty/Bullet)
     endif ()
     if (URHO3D_LUA)
         # ditto for Lua/LuaJIT
-        list (APPEND URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include/${PATH_SUFFIX}/ThirdParty/Lua${JIT})
+        list (APPEND URHO3D_INCLUDE_DIRS ${URHO3D_HOME}/include/Urho3D/ThirdParty/Lua${JIT})
     endif ()
     set (URHO3D_LIBRARIES Urho3D)
     set (COMPILE_RESULT TRUE)
@@ -65,7 +65,7 @@ else ()
         file (TO_CMAKE_PATH "$ENV{URHO3D_HOME}" URHO3D_HOME)
     endif ()
     # If either of the URHO3D_LIB_TYPE or URHO3D_HOME build options changes then invalidate all the caches
-    if ((URHO3D_LIB_TYPE AND NOT URHO3D_LIB_TYPE STREQUAL URHO3D_FOUND_LIB_TYPE) OR NOT URHO3D_BASE_INCLUDE_DIR MATCHES "^${URHO3D_HOME}/include/${PATH_SUFFIX}$")
+    if ((URHO3D_LIB_TYPE AND NOT URHO3D_LIB_TYPE STREQUAL URHO3D_FOUND_LIB_TYPE) OR NOT URHO3D_BASE_INCLUDE_DIR MATCHES "^${URHO3D_HOME}/include/Urho3D$")
         unset (URHO3D_BASE_INCLUDE_DIR CACHE)
         unset (URHO3D_LIBRARIES CACHE)
         if (WIN32)
@@ -98,6 +98,14 @@ else ()
         if (EMSCRIPTEN)
             string (REPLACE .so .bc CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")   # Stringify for string replacement
         endif ()
+        # The PATH_SUFFIX does not work for CMake on Windows host system, it actually needs a prefix instead
+        if (CMAKE_HOST_WIN32)
+            set (CMAKE_SYSTEM_PREFIX_PATH_SAVED ${CMAKE_SYSTEM_PREFIX_PATH})
+	    string (REPLACE ";" "\\Urho3D;" CMAKE_SYSTEM_PREFIX_PATH "${CMAKE_SYSTEM_PREFIX_PATH_SAVED};")    # Stringify for string replacement
+	    if (NOT URHO3D_64BIT)
+	        list (REVERSE CMAKE_SYSTEM_PREFIX_PATH)
+	    endif ()
+        endif ()
     endif ()
     # URHO3D_HOME variable should be an absolute path, so use a non-rooted search even when we are cross-compiling
     if (URHO3D_HOME)
@@ -115,8 +123,8 @@ else ()
     if (NOT URHO3D_64BIT)
         # For 32-bit, force to search in 'lib' path even when the host system defaulted to use 'lib64'
         set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
-    elseif (WIN32)
-        # For 64-bit, force to search in 'lib64' path even when the Windows platform is not defaulted to use it
+    elseif (MINGW AND CMAKE_CROSSCOMPILING)
+        # For 64-bit MinGW on Linux host system, force to search in 'lib64' path even when the Windows platform is not defaulted to use it
         set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
     endif ()
     find_path (URHO3D_BASE_INCLUDE_DIR Urho3D.h PATH_SUFFIXES ${PATH_SUFFIX} ${SEARCH_OPT} DOC "Urho3D include directory")
@@ -177,13 +185,12 @@ else ()
             set (URHO3D_LIB_TYPE SHARED)
         endif ()
     endif ()
-    # TODO: Ensure the module has found the library with the right ABI for the chosen compiler and URHO3D_64BIT build option
-    #if (NOT IOS AND NOT MSVC)
-    #    try_compile (COMPILE_RESULT ${CMAKE_BINARY_DIR}/generated/FindUrho3D ${CMAKE_CURRENT_LIST_DIR}/CheckUrho3DLibrary.cpp
-    #        CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING=${URHO3D_INCLUDE_DIRS}
-    #        LINK_LIBRARIES ${URHO3D_LIBRARIES})
-    #endif ()
-    set (COMPILE_RESULT TRUE)
+    # Ensure the module has found the library with the right ABI for the chosen compiler and URHO3D_64BIT build option
+    if (URHO3D_LIBRARIES AND NOT IOS)
+        try_compile (COMPILE_RESULT ${CMAKE_BINARY_DIR}/generated/FindUrho3D ${CMAKE_CURRENT_LIST_DIR}/CheckUrho3DLibrary.cpp
+            CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING=${URHO3D_INCLUDE_DIRS}
+            LINK_LIBRARIES ${URHO3D_LIBRARIES})
+    endif ()
     # For shared library type, also initialize the URHO3D_DLL variable for later use
     if (WIN32)
         if (URHO3D_LIB_TYPE STREQUAL SHARED AND URHO3D_HOME)
@@ -197,9 +204,13 @@ else ()
             endif ()
         endif ()
     endif ()
+    # Restore CMake global settings
     if (CMAKE_FIND_LIBRARY_SUFFIXES_SAVED)
         set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAVED})
     endif ()
+    if (CMAKE_SYSTEM_PREFIX_PATH_SAVED)
+        set (CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_SYSTEM_PREFIX_PATH_SAVED})
+    endif ()
 endif ()
 
 if (URHO3D_INCLUDE_DIRS AND URHO3D_LIBRARIES AND URHO3D_LIB_TYPE AND COMPILE_RESULT)
@@ -222,7 +233,7 @@ elseif (Urho3D_FIND_REQUIRED)
         set (NOT_FOUND_MESSAGE "Ensure the specified location contains the Urho3D library of the requested library type. ${NOT_FOUND_MESSAGE}")
     endif ()
     message (FATAL_ERROR
-        "Could NOT find Urho3D library in Urho3D SDK installation or build tree. "
+        "Could NOT find compatible Urho3D library in Urho3D SDK installation or build tree. "
         "Use URHO3D_HOME environment variable or build option to specify the location of the non-default SDK installation or build tree. ${NOT_FOUND_MESSAGE}")
 endif ()
 

+ 1 - 1
CMake/Modules/Urho3D-CMake-common.cmake

@@ -1259,7 +1259,7 @@ macro (setup_main_executable)
         endif ()
         # Add SDL native init function, SDL_Main() entry point must be defined by one of the source files in ${SOURCE_FILES}
         find_Urho3D_file (ANDROID_MAIN_C_PATH SDL_android_main.c
-            HINTS ${URHO3D_HOME}/include/${PATH_SUFFIX}/ThirdParty/SDL/android ${CMAKE_SOURCE_DIR}/Source/ThirdParty/SDL/src/main/android
+            HINTS ${URHO3D_HOME}/include/Urho3D/ThirdParty/SDL/android ${CMAKE_SOURCE_DIR}/Source/ThirdParty/SDL/src/main/android
             DOC "Path to SDL_android_main.c" MSG_MODE FATAL_ERROR)
         list (APPEND SOURCE_FILES ${ANDROID_MAIN_C_PATH})
         # Setup shared library output path

+ 6 - 3
CMakeLists.txt

@@ -46,12 +46,15 @@ set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
 include (Urho3D-CMake-common)
 
 # Setup SDK install destinations
+set (PATH_SUFFIX Urho3D)
 if (WIN32)
     set (SCRIPT_EXT .bat)
+    if (CMAKE_HOST_WIN32)
+        set (PATH_SUFFIX .)
+    endif ()
 else ()
     set (SCRIPT_EXT .sh)
 endif ()
-set (PATH_SUFFIX Urho3D)
 if (ANDROID)
     # For Android platform, install to a path similar to ANDROID_LIBRARY_OUTPUT_PATH variable, e.g. libs/armeabi-v7a
     set (LIB_SUFFIX s/${ANDROID_NDK_ABI_NAME})
@@ -60,11 +63,11 @@ elseif (URHO3D_64BIT)
         set (HAS_LIB64 TRUE)
     endif ()
     # Install to 'lib64' when one of these conditions is true
-    if (WIN32 OR URHO3D_USE_LIB64_RPM OR (HAS_LIB64 AND NOT URHO3D_USE_LIB_DEB))
+    if ((MINGW AND CMAKE_CROSSCOMPILING) OR URHO3D_USE_LIB64_RPM OR (HAS_LIB64 AND NOT URHO3D_USE_LIB_DEB))
         set (LIB_SUFFIX 64)
     endif ()
 endif ()
-set (DEST_INCLUDE_DIR include/${PATH_SUFFIX})
+set (DEST_INCLUDE_DIR include/Urho3D)    # The include directory path contains the 'Urho3D' suffix regardless of PATH_SUFFIX variable
 set (DEST_SHARE_DIR share/${PATH_SUFFIX})
 set (DEST_RUNTIME_DIR bin)
 set (DEST_BUNDLE_DIR ${DEST_SHARE_DIR}/Applications)

+ 2 - 2
Source/Samples/Sample.inl

@@ -62,9 +62,9 @@ void Sample::Setup()
 
     // Construct a search path to find the resource prefix with two entries:
     // The first entry is an empty path which will be substituted with program/bin directory -- this entry is for binary when it is still in build tree
-    // The second entry is a relative path from the installed program/bin directory to the asset directory -- this entry is for binary when it is in the Urho3D SDK installation location
+    // The second and third entries are possible relative paths from the installed program/bin directory to the asset directory -- these entries are for binary when it is in the Urho3D SDK installation location
     if (!engineParameters_.Contains("ResourcePrefixPaths"))
-        engineParameters_["ResourcePrefixPaths"] = ";../share/Urho3D/Resources";
+        engineParameters_["ResourcePrefixPaths"] = ";../share/Resources;../share/Urho3D/Resources";
 }
 
 void Sample::Start()

+ 2 - 2
Source/Tools/Urho3DPlayer/Urho3DPlayer.cpp

@@ -122,9 +122,9 @@ void Urho3DPlayer::Setup()
 
     // Construct a search path to find the resource prefix with two entries:
     // The first entry is an empty path which will be substituted with program/bin directory -- this entry is for binary when it is still in build tree
-    // The second entry is a relative path from the installed program/bin directory to the asset directory -- this entry is for binary when it is in the Urho3D SDK installation location
+    // The second and third entries are possible relative paths from the installed program/bin directory to the asset directory -- these entries are for binary when it is in the Urho3D SDK installation location
     if (!engineParameters_.Contains("ResourcePrefixPaths"))
-        engineParameters_["ResourcePrefixPaths"] = ";../share/Urho3D/Resources";
+        engineParameters_["ResourcePrefixPaths"] = ";../share/Resources;../share/Urho3D/Resources";
 }
 
 void Urho3DPlayer::Start()

+ 3 - 3
Source/Urho3D/CMakeLists.txt

@@ -423,15 +423,15 @@ if (GLOBAL_INCLUDE_DIRS)
     string (REPLACE ";" "\" ${DASH}I\"" GLOBAL_INCLUDE_DIRS "${DASH}I\"${GLOBAL_INCLUDE_DIRS}\"")
     string (REPLACE "${SYSROOT}" "" GLOBAL_INCLUDE_DIRS ${GLOBAL_INCLUDE_DIRS})
 endif ()
-set (ENGINE_INCLUDE_DIRS "${DASH}I\"\${includedir}\" ${DASH}I\"\${includedir}/${PATH_SUFFIX}/ThirdParty\"")
+set (ENGINE_INCLUDE_DIRS "${DASH}I\"\${includedir}\" ${DASH}I\"\${includedir}/Urho3D/ThirdParty\"")
 if (URHO3D_PHYSICS)
     # Bullet library depends on its own include dir to be added in the header search path
     # This is more practical than patching its header files in many places to make them work with relative path
-    set (ENGINE_INCLUDE_DIRS "${ENGINE_INCLUDE_DIRS} ${DASH}I\"\${includedir}/${PATH_SUFFIX}/ThirdParty/Bullet\"")
+    set (ENGINE_INCLUDE_DIRS "${ENGINE_INCLUDE_DIRS} ${DASH}I\"\${includedir}/Urho3D/ThirdParty/Bullet\"")
 endif ()
 if (URHO3D_LUA)
     # ditto for Lua/LuaJIT
-    set (ENGINE_INCLUDE_DIRS "${ENGINE_INCLUDE_DIRS} ${DASH}I\"\${includedir}/${PATH_SUFFIX}/ThirdParty/Lua${JIT}\"")
+    set (ENGINE_INCLUDE_DIRS "${ENGINE_INCLUDE_DIRS} ${DASH}I\"\${includedir}/Urho3D/ThirdParty/Lua${JIT}\"")
 endif ()
 # todo: Reevaluate the command below when the CMake minimum required version is set to 2.8.12 (and remove only when the deprected add_compiler_export_flags() is not used anymore)
 string (REGEX REPLACE " -fvisibility[^ ]+" "" CLEANED_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})   # Remove visibility compiler options that are only used for building the library