Browse Source

Minor clean up to avoid redundant code. Also copy DLL to build tree.
Related to commit 58332565eafa1a948a7673a48e9fcebc27bb8eb6.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
a7c1dae794
2 changed files with 71 additions and 71 deletions
  1. 63 65
      CMake/Modules/FindDirect3D.cmake
  2. 8 6
      CMake/Modules/Urho3D-CMake-common.cmake

+ 63 - 65
CMake/Modules/FindDirect3D.cmake

@@ -22,7 +22,7 @@
 
 # For MSVC compiler, find Microsoft DirectX installation (need June 2010 SDK or later, or a Windows SDK)
 # For MinGW compiler, assume MinGW not only comes with the necessary headers & libraries but also has the headers & libraries directories in its default search path
-# (use 'echo |gcc -v -E -' and 'gcc -print-search-dirs', respectively, to double check)
+# (use 'echo |$MINGW_PREFIX-gcc -v -E -' and '$MINGW_PREFIX-gcc -print-search-dirs', respectively, to double check)
 #
 #  DIRECT3D_FOUND
 #  DIRECT3D_INCLUDE_DIRS
@@ -34,76 +34,74 @@ if (NOT WIN32 OR DIRECT3D_FOUND)
     return ()
 endif ()
 
-if (MSVC)
-    # Prefer to use MS Windows SDK, so search for it first
-    if (CMAKE_CL_64)
-        set (PATH_SUFFIX x64)
+# Prefer to use MS Windows SDK, so search for it first
+if (MINGW)
+    # Assume that 'libd3dcompiler.a' is a symlink pointing to 'libd3dcompiler_46.a' (See this discussion http://urho3d.prophpbb.com/topic504.html)
+    # Anyway, we could not do anything else in the build system automation with version lower than 46 and libd3dcompiler_46.a is the latest supported version
+    set (DLL_NAMES d3dcompiler_46.dll)
+else ()
+    set (DLL_NAMES d3dcompiler_47.dll d3dcompiler_46.dll)
+endif ()
+if (CMAKE_CL_64)
+    set (PATH_SUFFIX x64)
+else ()
+    set (PATH_SUFFIX x86)
+endif ()
+# Only need to search the DLL as a proxy for the presence of the MS Windows SDK
+find_file (DIRECT3D_DLL NAMES ${DLL_NAMES} PATHS
+    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}"
+    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}")
+if (DIRECT3D_DLL OR MINGW)  # MinGW compiler toolchain is assumed to come with its own necessary headers and libraries for Direct3D
+    if (NOT URHO3D_D3D11)
+        set (DIRECT3D_LIBRARIES d3d9 d3dcompiler)
     else ()
-        set (PATH_SUFFIX x86)
+        set (DIRECT3D_LIBRARIES d3d11 d3dcompiler dxgi dxguid)
     endif ()
-    # Only need to search the DLL as a proxy for the presence of the MS Windows SDK
-    find_file (DIRECT3D_DLL d3dcompiler_47.dll d3dcompiler_46.dll PATHS
-        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}"
-        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}")
-    if (DIRECT3D_DLL)
-        if (NOT URHO3D_D3D11)
-            set (DIRECT3D_LIBRARIES d3d9 d3dcompiler)
-        else ()
-            set (DIRECT3D_LIBRARIES d3d11 d3dcompiler dxgi dxguid)
-        endif ()
-        unset (DIRECT3D_INCLUDE_DIRS)
-        set (DIRECT3D_FOUND 1)
-    elseif (MSVC_VERSION LESS 1700 OR NOT URHO3D_D3D11)
-        # To avoid incompatibility between DirectX SDK and Windows SDK defines and the resulting warning spam,
-        # only search for the DirectX SDK when using Visual Studion lower than VS2012 or when using D3D9
-        set (DIRECTX_INC_SEARCH_PATH
-            "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include"
-            "C:/Program Files/Microsoft DirectX SDK (June 2010)/Include"
-            "$ENV{DIRECTX_ROOT}/Include"
-            "$ENV{DXSDK_DIR}/Include")
-        find_path (DIRECT3D_INCLUDE_DIRS NAMES d3dcompiler.h PATHS ${DIRECTX_INC_SEARCH_PATH})
+    unset (DIRECT3D_INCLUDE_DIRS)
+    set (DIRECT3D_FOUND 1)
+elseif (MSVC_VERSION LESS 1700 OR NOT URHO3D_D3D11)
+    # To avoid incompatibility between DirectX SDK and Windows SDK defines and the resulting warning spam,
+    # only search for the DirectX SDK when using Visual Studion lower than VS2012 or when using D3D9
+    set (DIRECTX_INC_SEARCH_PATH
+        "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include"
+        "C:/Program Files/Microsoft DirectX SDK (June 2010)/Include"
+        "$ENV{DIRECTX_ROOT}/Include"
+        "$ENV{DXSDK_DIR}/Include")
+    find_path (DIRECT3D_INCLUDE_DIRS NAMES d3dcompiler.h PATHS ${DIRECTX_INC_SEARCH_PATH})
 
-        if (CMAKE_CL_64)
-            set (DIRECTX_LIB_SEARCH_PATH
-                "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x64"
-                "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x64"
-                "$ENV{DIRECTX_ROOT}/Lib/x64"
-                "$ENV{DXSDK_DIR}/Lib/x64")
-        else ()
-            set (DIRECTX_LIB_SEARCH_PATH
-                "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib"
-                "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86"
-                "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib"
-                "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x86"
-                "$ENV{DIRECTX_ROOT}/Lib"
-                "$ENV{DIRECTX_ROOT}/Lib/x86"
-                "$ENV{DXSDK_DIR}/Lib"
-                "$ENV{DXSDK_DIR}/Lib/x86")
-        endif ()
-        if (NOT URHO3D_D3D11)
-            find_library (DIRECT3D_LIB_D3D9 NAMES d3d9 PATHS ${DIRECTX_LIB_SEARCH_PATH})
-            find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
-            if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D9 AND DIRECT3D_LIB_D3DCOMPILER)
-                set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D9} ${DIRECT3D_LIB_D3DCOMPILER})
-                set (DIRECT3D_FOUND 1)
-            endif ()
-        else ()
-            find_library (DIRECT3D_LIB_D3D11 NAMES d3d11 PATHS ${DIRECTX_LIB_SEARCH_PATH})
-            find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
-            find_library (DIRECT3D_LIB_DXGI NAMES dxgi PATHS ${DIRECTX_LIB_SEARCH_PATH})
-            find_library (DIRECT3D_LIB_DXGUID NAMES dxguid PATHS ${DIRECTX_LIB_SEARCH_PATH})
-            if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D11 AND DIRECT3D_LIB_D3DCOMPILER AND DIRECT3D_LIB_DXGI AND DIRECT3D_LIB_DXGUID)
-                set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D11} ${DIRECT3D_LIB_D3DCOMPILER} ${DIRECT3D_LIB_DXGI} ${DIRECT3D_LIB_DXGUID})
-                set (DIRECT3D_FOUND 1)
-            endif ()
-        endif ()
+    if (CMAKE_CL_64)
+        set (DIRECTX_LIB_SEARCH_PATH
+            "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x64"
+            "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x64"
+            "$ENV{DIRECTX_ROOT}/Lib/x64"
+            "$ENV{DXSDK_DIR}/Lib/x64")
+    else ()
+        set (DIRECTX_LIB_SEARCH_PATH
+            "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib"
+            "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86"
+            "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib"
+            "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x86"
+            "$ENV{DIRECTX_ROOT}/Lib"
+            "$ENV{DIRECTX_ROOT}/Lib/x86"
+            "$ENV{DXSDK_DIR}/Lib"
+            "$ENV{DXSDK_DIR}/Lib/x86")
     endif ()
-else ()
-    # MinGW compiler toolchain is assumed to come with its own necessary headers and libraries for Direct3D
     if (NOT URHO3D_D3D11)
-        set (DIRECT3D_LIBRARIES d3d9 d3dcompiler)
+        find_library (DIRECT3D_LIB_D3D9 NAMES d3d9 PATHS ${DIRECTX_LIB_SEARCH_PATH})
+        find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
+        if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D9 AND DIRECT3D_LIB_D3DCOMPILER)
+            set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D9} ${DIRECT3D_LIB_D3DCOMPILER})
+            set (DIRECT3D_FOUND 1)
+        endif ()
     else ()
-        set (DIRECT3D_LIBRARIES d3d11 d3dcompiler dxgi dxguid)
+        find_library (DIRECT3D_LIB_D3D11 NAMES d3d11 PATHS ${DIRECTX_LIB_SEARCH_PATH})
+        find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
+        find_library (DIRECT3D_LIB_DXGI NAMES dxgi PATHS ${DIRECTX_LIB_SEARCH_PATH})
+        find_library (DIRECT3D_LIB_DXGUID NAMES dxguid PATHS ${DIRECTX_LIB_SEARCH_PATH})
+        if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D11 AND DIRECT3D_LIB_D3DCOMPILER AND DIRECT3D_LIB_DXGI AND DIRECT3D_LIB_DXGUID)
+            set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D11} ${DIRECT3D_LIB_D3DCOMPILER} ${DIRECT3D_LIB_DXGI} ${DIRECT3D_LIB_DXGUID})
+            set (DIRECT3D_FOUND 1)
+        endif ()
     endif ()
 endif ()
 

+ 8 - 6
CMake/Modules/Urho3D-CMake-common.cmake

@@ -357,11 +357,8 @@ endif ()
 # be necessary for DirectInput & DirectSound headers, if those are not present in the compiler's own
 # default includes.
 if (WIN32)
-    if (MSVC)
-        set (D3D_REQUIRED REQUIRED)
-    endif ()
-    find_package (Direct3D ${D3D_REQUIRED})
-    if (DIRECT3D_FOUND AND DIRECT3D_INCLUDE_DIRS)
+    find_package (Direct3D REQUIRED)
+    if (DIRECT3D_INCLUDE_DIRS)
         include_directories (${DIRECT3D_INCLUDE_DIRS})
     endif ()
 endif ()
@@ -824,6 +821,10 @@ macro (setup_executable)
         add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND scp $<TARGET_FILE:${TARGET_NAME}> ${URHO3D_SCP_TO_TARGET} || exit 0
             COMMENT "Scp-ing ${TARGET_NAME} executable to target system")
     endif ()
+    if (DIRECT3D_DLL)
+        # Make a copy of the D3D DLL to the runtime directory in the build tree
+        add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DIRECT3D_DLL} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+    endif ()
     # Need to check if the destination variable is defined first because this macro could be called by external project that does not wish to install anything
     if (DEST_RUNTIME_DIR)
         if (EMSCRIPTEN)
@@ -841,7 +842,8 @@ macro (setup_executable)
             install (FILES ${FILES} DESTINATION ${DEST_BUNDLE_DIR} OPTIONAL)    # We get html.map or html.mem depend on the build configuration
         else ()
             install (TARGETS ${TARGET_NAME} RUNTIME DESTINATION ${DEST_RUNTIME_DIR} BUNDLE DESTINATION ${DEST_BUNDLE_DIR})
-            if (MSVC AND DIRECT3D_DLL AND NOT DIRECT3D_DLL_INSTALLED)
+            if (DIRECT3D_DLL AND NOT DIRECT3D_DLL_INSTALLED)
+                # Make a copy of the D3D DLL to the runtime directory in the installed location
                 install (FILES ${DIRECT3D_DLL} DESTINATION ${DEST_RUNTIME_DIR})
                 set (DIRECT3D_DLL_INSTALLED TRUE)
             endif ()