Pārlūkot izejas kodu

Change CMake library type preferences to agree with Urho3D.

This change helps external CMake project to choose the correct library type as the compiler flags setup by the Urho3D-CMake-Magic module. Both the external project and the cmake module are being governed by the same URHO3D_LIB_TYPE build option.
Yao Wei Tjong 姚伟忠 12 gadi atpakaļ
vecāks
revīzija
589e0d53bb

+ 1 - 1
Docs/GettingStarted.dox

@@ -306,7 +306,7 @@ Copy the "CMake" sub-directory from Urho3D project to your own project so that C
 
 Since your CMake build script include the Urho3D-Cmake-magic module, your project also now has the cross-platform build capability.
 
-When both Urho3D static and shared library are built and available in the Urho3D project build tree, the Urho3D shared library takes precedence over static library to be linked against your own project. You can modify the CMAKE_FIND_LIBRARY_SUFFIXES global variable to change this behaviour.
+When both Urho3D static and shared library are built and available in the Urho3D project build tree, the Urho3D static library takes precedence over shared library to be linked against your own project. Use the URHO3D_LIB_TYPE build option to explicitly specify which Urho3D library type to be linked against.
 
 
 \page Structure Overall structure

+ 11 - 0
Source/CMake/Modules/FindUrho3D.cmake

@@ -30,6 +30,17 @@
 
 set (URHO3D_FOUND 0)
 
+# Urho3D prefers static library type by default while CMake prefers shared one, so we need to change CMake preference to agree with Urho3D
+if (NOT URHO3D_LIB_TYPE STREQUAL SHARED)
+    list (REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
+endif ()
+
+# If the URHO3D_LIB_TYPE build option changes then invalidate the found library cache
+if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_EXPORTS_LIB_TYPE)
+    unset (URHO3D_LIBRARIES CACHE)
+    set (URHO3D_EXPORTS_LIB_TYPE ${URHO3D_LIB_TYPE} CACHE INTERNAL "Lib type when Urho3D export header was last generated")
+endif ()
+
 set (URHO3D_LIB_NAMES Urho3D)
 if (WIN32)
     set (URHO3D_LIB_NAMES ${URHO3D_LIB_NAMES} Urho3D_d)

+ 2 - 2
Source/Engine/CMakeLists.txt

@@ -136,10 +136,10 @@ if (APPLE AND URHO3D_LIB_TYPE STREQUAL SHARED)
 endif ()
 
 # Generate platform specific export header file automatically
-if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_EXPORTS_BUILD_TYPE OR ${CMAKE_CURRENT_SOURCE_DIR}/Urho3D.h.in IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.h)
+if (NOT URHO3D_LIB_TYPE STREQUAL URHO3D_EXPORTS_LIB_TYPE OR ${CMAKE_CURRENT_SOURCE_DIR}/Urho3D.h.in IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.h)
     set_target_properties (${TARGET_NAME} PROPERTIES DEFINE_SYMBOL URHO3D_EXPORTS)
     generate_export_header (${TARGET_NAME} BASE_NAME ${LIB_NAME} EXPORT_MACRO_NAME URHO3D_API EXPORT_FILE_NAME Urho3D.h)
-    set (URHO3D_EXPORTS_BUILD_TYPE ${URHO3D_LIB_TYPE} CACHE INTERNAL "Lib type when Urho3D export header was last generated")
+    set (URHO3D_EXPORTS_LIB_TYPE ${URHO3D_LIB_TYPE} CACHE INTERNAL "Lib type when Urho3D export header was last generated")
     
     # Append Urho3D license notice to the export header file
     file (READ ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.h EXPORT_DEFINE)