Browse Source

Fix try_run() logic on WIN32 platform with both Release and Debug libs.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
891bde9325
2 changed files with 23 additions and 18 deletions
  1. 22 17
      CMake/Modules/FindUrho3D.cmake
  2. 1 1
      Docs/GettingStarted.dox

+ 22 - 17
CMake/Modules/FindUrho3D.cmake

@@ -175,14 +175,8 @@ else ()
         if (WIN32)
             # For Windows platform, give a second chance to search for a debug version of the library
             find_library (URHO3D_LIBRARIES_DBG NAMES Urho3D_d ${URHO3D_LIB_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX} ${SEARCH_OPT})
-            # If both the non-debug and debug version of the libraries are found then use them both
             set (URHO3D_LIBRARIES_REL ${URHO3D_LIBRARIES})
-            # Otherwise, URHO3D_LIBRARIES variable should have the path to either one of the version
-            if (URHO3D_LIBRARIES)
-                if (URHO3D_LIBRARIES_DBG)
-                    list (APPEND URHO3D_LIBRARIES ${URHO3D_LIBRARIES_DBG})
-                endif ()
-            else ()
+            if (NOT URHO3D_LIBRARIES)
                 set (URHO3D_LIBRARIES ${URHO3D_LIBRARIES_DBG})
             endif ()
         endif ()
@@ -231,12 +225,20 @@ else ()
                 set (IOS_FLAGS -DCMAKE_MACOSX_BUNDLE=1 -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=0)
             elseif (ANDROID)
                 set (ANDROID_LIBRARIES "log\;android\;GLESv1_CM\;GLESv2")
-            elseif (MSVC AND URHO3D_DLL)
-                # This is a hack as it relies on internal implementation of try_run
-                foreach (DLL ${URHO3D_DLL})
-                    get_filename_component (NAME ${DLL} NAME)
-                    execute_process (COMMAND ${CMAKE_COMMAND} -E copy ${DLL} ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/Debug/${NAME})
-                endforeach ()
+            elseif (WIN32)
+                set (CMAKE_TRY_COMPILE_CONFIGURATION_SAVED ${CMAKE_TRY_COMPILE_CONFIGURATION})
+                if (URHO3D_LIBRARIES_REL)
+                    set (CMAKE_TRY_COMPILE_CONFIGURATION Release)
+                else ()
+                    set (CMAKE_TRY_COMPILE_CONFIGURATION Debug)
+                endif ()
+                if (MSVC AND URHO3D_DLL)
+                    # This is a hack as it relies on internal implementation of try_run
+                    foreach (DLL ${URHO3D_DLL})
+                        get_filename_component (NAME ${DLL} NAME)
+                        execute_process (COMMAND ${CMAKE_COMMAND} -E copy ${DLL} ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/${CMAKE_TRY_COMPILE_CONFIGURATION}/${NAME})
+                    endforeach ()
+                endif ()
             endif ()
             # Since in cross-compiling mode we cannot run the test target executable and auto-discover the build options used by the found library,
             # the next best thing is to evaluate the found export header indirectly (assuming the found library was built using the same export header)
@@ -268,13 +270,13 @@ else ()
                     unset (URHO3D_LIB_TYPE)
                 endif ()
                 unset (URHO3D_LIBRARIES CACHE)
-                if (WIN32)
-                    unset (URHO3D_LIBRARIES_DBG CACHE)
-                endif ()
-                unset (URHO3D_DLL)
             endif ()
         endif ()
     endforeach ()
+    # If both the non-debug and debug version of the libraries are found on Windows platform then use them both
+    if (URHO3D_LIBRARIES_REL AND URHO3D_LIBRARIES_DBG)
+        set (URHO3D_LIBRARIES ${URHO3D_LIBRARIES_REL} ${URHO3D_LIBRARIES_DBG})
+    endif ()
     # Ensure auto-discovered variables always prefail over user settings in all the subsequent cmake rerun (even without redoing try_run)
     foreach (VAR ${AUTO_DISCOVER_VARS})
         if (DEFINED ${VAR} AND DEFINED AUTO_DISCOVERED_${VAR})  # Cannot combine these two ifs due to variable expansion error when it is not defined
@@ -292,6 +294,9 @@ else ()
     if (CMAKE_SYSTEM_PREFIX_PATH_SAVED)
         set (CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_SYSTEM_PREFIX_PATH_SAVED})
     endif ()
+    if (CMAKE_TRY_COMPILE_CONFIGURATION_SAVED)
+        set (CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_TRY_COMPILE_CONFIGURATION_SAVED})
+    endif ()
 endif ()
 
 if (URHO3D_INCLUDE_DIRS AND URHO3D_LIBRARIES AND URHO3D_LIB_TYPE AND URHO3D_COMPILE_RESULT)

+ 1 - 1
Docs/GettingStarted.dox

@@ -501,7 +501,7 @@ First of all, structure your project similar to Urho3D project as below. Althoug
  └ *.bat or *.sh
 \endcode
 
-The physical project root directory is also the logical project source tree in CMake terminology where your project main CMakeLists.txt should reside. The 'bin' directory should contain the 'Data' and 'CoreData' resource subdirs for your own assets. You must copy (or symlink) the 'CMake' subdir from Urho3D project root directory (or from Urho3D SDK installation, which can be found in the 'share/Urho3D/CMake') to your project root directory. You may also want to copy (or symlink) the build scripts from Urho3D project root directory (or from Urho3D SDK installation, which can be found in the 'share/Urho3D/Scripts') to your project root directory, unless you just want to use cmake-gui for your own project configuration and generation. Alternatively, you can add the Urho3D project root directory into the PATH environment variable in your host system in order to make the build scripts available everywhere. The build scripts work together with the Urho3D CMake modules to configure and generate your initial project build tree. Both out-of-source build tree (recommended) and non out-of-source build tree are supported. Note that when you configure your project (either via one of the build script or via cmake-gui), you can also pass most of the \ref Build_Options supported by Urho3D project. In fact, you probably have to pass a compatible build options with the Urho3D library that you intend to use to avoid any conflict. Although this may change in the near future as we will enhance our modules to be smart enough to auto-discover the original build options used by the Urho3D library, but until then it is still your responsibility to supply the compatible build options.
+The physical project root directory is also the logical project source tree in CMake terminology where your project main CMakeLists.txt should reside. The 'bin' directory should contain the 'Data' and 'CoreData' resource subdirs for your own assets. You must copy (or symlink) the 'CMake' subdir from Urho3D project root directory (or from Urho3D SDK installation, which can be found in the 'share/Urho3D/CMake') to your project root directory. You may also want to copy (or symlink) the build scripts from Urho3D project root directory (or from Urho3D SDK installation, which can be found in the 'share/Urho3D/Scripts') to your project root directory, unless you just want to use cmake-gui for your own project configuration and generation. Alternatively, you can add the Urho3D project root directory into the PATH environment variable in your host system in order to make the build scripts available everywhere. The build scripts work together with the Urho3D CMake modules to configure and generate your initial project build tree. Both out-of-source build tree (recommended) and non out-of-source build tree are supported. Note that when you configure your project (either via one of the build script or via cmake-gui), you can only pass the \ref Build_Options that are applicable to downstream projects. Be mindful that conflicting build options would be ignored.
 
 In your own project root directory, create a main CMakeLists.txt file and add the following lines: (replace MyProjectName and MyExecutableName with the actual names you want)