Browse Source

Fix URHO3D_PACKAGING build option on Windows platform with SHARED lib.
[ci scan]

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
7a80b37c22

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

@@ -100,7 +100,7 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
         set (URHO3D_DEFAULT_LUA_RAW TRUE)
     endif ()
     cmake_dependent_option (URHO3D_LUA_RAW_SCRIPT_LOADER "Prefer loading raw script files from the file system before falling back on Urho3D resource cache. Useful for debugging (e.g. breakpoints), but less performant (Lua/LuaJIT only)" ${URHO3D_DEFAULT_LUA_RAW} "URHO3D_LUA OR URHO3D_LUAJIT" FALSE)
- 
+
     option (URHO3D_SAMPLES "Build sample applications")
     cmake_dependent_option (URHO3D_TOOLS "Build tools (native and RPI only)" TRUE "NOT IOS AND NOT ANDROID AND NOT EMSCRIPTEN" FALSE)
     cmake_dependent_option (URHO3D_EXTRAS "Build extras (native and RPI only)" FALSE "NOT IOS AND NOT ANDROID AND NOT EMSCRIPTEN" FALSE)
@@ -528,6 +528,14 @@ macro (set_output_directories OUTPUT_PATH)
     endforeach ()
 endmacro ()
 
+# Macro for setting runtime output directories for tools
+macro (set_tool_output_directories)
+    set_output_directories (${CMAKE_BINARY_DIR}/bin/tool RUNTIME PDB)
+    if (DEST_RUNTIME_DIR STREQUAL bin)
+        set (DEST_RUNTIME_DIR bin/tool)
+    endif ()
+endmacro ()
+
 # Set common binary output directory for all platforms
 set_output_directories (${CMAKE_BINARY_DIR}/bin RUNTIME PDB)
 

+ 2 - 5
Source/Extras/CMakeLists.txt

@@ -27,11 +27,8 @@ project (Urho3D-Extras)
 find_package (Urho3D REQUIRED)
 include_directories (${URHO3D_INCLUDE_DIRS})
 
-# All tools must be natively built and output to bin/tool subdir to differentiate them from platform-specific binaries in the bin directory
-set_output_directories (${CMAKE_BINARY_DIR}/bin/tool RUNTIME PDB)
-if (DEST_RUNTIME_DIR STREQUAL bin)
-    set (DEST_RUNTIME_DIR bin/tool)
-endif ()
+# All tools must be natively built and output to bin/tool subdir to differentiate them from target platfrom binaries in the bin directory
+set_tool_output_directories ()
 
 # Urho3D extras
 add_subdirectory (OgreBatchConverter)

+ 2 - 5
Source/ThirdParty/LuaJIT/src/host/CMakeLists.txt

@@ -86,11 +86,8 @@ set (SOURCE_FILES ${C_FILES} ${GEN_ARCH_H})
 # Define dependency libs
 set (INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ..)
 
-# All tools must be natively built and output to bin/tool subdir to differentiate them from platform-specific binaries in the bin directory
-set_output_directories (${CMAKE_BINARY_DIR}/bin/tool RUNTIME PDB)
-if (DEST_RUNTIME_DIR STREQUAL bin)
-    set (DEST_RUNTIME_DIR bin/tool)
-endif ()
+# All tools must be natively built and output to bin/tool subdir to differentiate them from target platfrom binaries in the bin directory
+set_tool_output_directories ()
 
 # Setup target
 setup_executable (NODEPS)

+ 2 - 5
Source/ThirdParty/LuaJIT/src/host/minilua/CMakeLists.txt

@@ -31,11 +31,8 @@ if (NOT MSVC)
     set (LIBS m)
 endif ()
 
-# All tools must be natively built and output to bin/tool subdir to differentiate them from platform-specific binaries in the bin directory
-set_output_directories (${CMAKE_BINARY_DIR}/bin/tool RUNTIME PDB)
-if (DEST_RUNTIME_DIR STREQUAL bin)
-    set (DEST_RUNTIME_DIR bin/tool)
-endif ()
+# All tools must be natively built and output to bin/tool subdir to differentiate them from target platfrom binaries in the bin directory
+set_tool_output_directories ()
 
 # Setup target
 setup_executable (NODEPS)

+ 2 - 5
Source/ThirdParty/toluapp/src/bin/CMakeLists.txt

@@ -65,11 +65,8 @@ if (NOT MSVC)
 endif ()
 set (INCLUDE_DIRS ../../include ../../../../ThirdParty/Lua${JIT}/src)
 
-# All tools must be natively built and output to bin/tool subdir to differentiate them from platform-specific binaries in the bin directory
-set_output_directories (${CMAKE_BINARY_DIR}/bin/tool RUNTIME PDB)
-if (DEST_RUNTIME_DIR STREQUAL bin)
-    set (DEST_RUNTIME_DIR bin/tool)
-endif ()
+# All tools must be natively built and output to bin/tool subdir to differentiate them from target platfrom binaries in the bin directory
+set_tool_output_directories ()
 
 # Setup target
 if (APPLE)

+ 3 - 6
Source/Tools/CMakeLists.txt

@@ -27,7 +27,7 @@ project (Urho3D-Tools)
 find_package (Urho3D REQUIRED)
 include_directories (${URHO3D_INCLUDE_DIRS})
 
-# Urho3DPlayer target is rather special, although it is here, it is not a tool because it builds into platform-specific binary
+# Urho3DPlayer target is rather special, although it is here, it is not a tool because it is built into target platform binary as opposed to host platform
 if (NOT EMSCRIPTEN)
     add_subdirectory (Urho3DPlayer)
 endif ()
@@ -46,11 +46,8 @@ if ((CMAKE_CROSSCOMPILING OR IOS) AND URHO3D_PACKAGING)
     install (PROGRAMS ${CMAKE_BINARY_DIR}/bin/tool/PackageTool DESTINATION ${DEST_RUNTIME_DIR}/tool)
 endif ()
 
-# All tools must be natively built and output to bin/tool subdir to differentiate them from platform-specific binaries in the bin directory
-set_output_directories (${CMAKE_BINARY_DIR}/bin/tool RUNTIME PDB)
-if (DEST_RUNTIME_DIR STREQUAL bin)
-    set (DEST_RUNTIME_DIR bin/tool)
-endif ()
+# All tools must be natively built and output to bin/tool subdir to differentiate them from target platfrom binaries in the bin directory
+set_tool_output_directories ()
 
 if (URHO3D_TOOLS)
     # Urho3D tools

+ 10 - 9
Source/Urho3D/CMakeLists.txt

@@ -25,8 +25,18 @@ set (TARGET_NAME Urho3D)
 
 add_definitions (-DURHO3D_IS_BUILDING)
 
+# Windows platform has its own naming convention for library
+set (LIB_NAME ${TARGET_NAME})
 if (WIN32)
     set (CMAKE_DEBUG_POSTFIX _d)
+    if (CMAKE_BUILD_TYPE STREQUAL Debug)
+        set (LIB_NAME ${LIB_NAME}_d)
+    endif ()
+    if (URHO3D_LIB_TYPE STREQUAL SHARED)
+        set (LIB_NAME ${LIB_NAME}.dll)
+        # When building shared library, a copy of the library must be available in the tool directory for the tools to work correctly as there is no RPATH for Windows platform
+        create_symlink (${CMAKE_BINARY_DIR}/bin/${LIB_NAME} ${CMAKE_BINARY_DIR}/bin/tool/${LIB_NAME})
+    endif ()
 endif ()
 
 # Define generated source files
@@ -317,15 +327,6 @@ if (ABSOLUTE_PATH_LIBS)
     string (REPLACE ";" "\" \"" URHO3D_ABS_PATH_LIBS "\"${ABSOLUTE_PATH_LIBS}\"")   # Note: need to always "stringify" a variable in list context for replace to work correctly, besides the list could be empty
     string (REPLACE "${SYSROOT}" "\${pc_sysrootdir}" URHO3D_ABS_PATH_LIBS "${URHO3D_ABS_PATH_LIBS}")
 endif ()
-set (LIB_NAME ${TARGET_NAME})
-if (MINGW)
-    if (CMAKE_BUILD_TYPE STREQUAL Debug)
-        set (LIB_NAME ${LIB_NAME}_d)
-    endif ()
-    if (URHO3D_LIB_TYPE STREQUAL SHARED)
-        set (LIB_NAME ${LIB_NAME}.dll)
-    endif ()
-endif ()
 if (MSVC)
     # todo: Add a post build command to adjust the LIB_NAME when in Debug configuration (CMake/VS generator is multi-config)
     set (DASH /)