FindDirect3D.cmake 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #
  2. # Copyright (c) 2008-2015 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # For MSVC compiler, find Microsoft Direct3D installation in Windows SDK or in June 2010 DirectX SDK or later
  23. # 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
  24. # (use 'echo |$MINGW_PREFIX-gcc -v -E -' and '$MINGW_PREFIX-gcc -print-search-dirs', respectively, to double check)
  25. #
  26. # DIRECT3D_FOUND
  27. # DIRECT3D_INCLUDE_DIRS
  28. # DIRECT3D_LIBRARIES
  29. # DIRECT3D_DLL
  30. #
  31. if (NOT WIN32 OR URHO3D_OPENGL OR DIRECT3D_FOUND)
  32. return ()
  33. endif ()
  34. # Prefer to use MS Windows SDK, so search for it first
  35. if (MINGW)
  36. # Assume that 'libd3dcompiler.a' is a symlink pointing to 'libd3dcompiler_46.a' (See this discussion http://urho3d.prophpbb.com/topic504.html)
  37. # 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
  38. set (DLL_NAMES d3dcompiler_46.dll)
  39. else ()
  40. set (DLL_NAMES d3dcompiler_47.dll d3dcompiler_46.dll)
  41. endif ()
  42. if (CMAKE_CL_64)
  43. set (PATH_SUFFIX x64)
  44. else ()
  45. set (PATH_SUFFIX x86)
  46. endif ()
  47. # Only need to search the DLL as a proxy for the presence of the MS Windows SDK
  48. # Note: do not use default paths such as the PATH variable, to potentially avoid using a wrong architecture DLL
  49. find_file (DIRECT3D_DLL NAMES ${DLL_NAMES} PATHS
  50. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v10.0;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}"
  51. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}"
  52. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]/Redist/D3D/${PATH_SUFFIX}"
  53. NO_DEFAULT_PATH)
  54. if (DIRECT3D_DLL OR MINGW) # MinGW compiler toolchain is assumed to come with its own necessary headers and libraries for Direct3D
  55. if (NOT URHO3D_D3D11)
  56. set (DIRECT3D_LIBRARIES d3d9 d3dcompiler)
  57. else ()
  58. set (DIRECT3D_LIBRARIES d3d11 d3dcompiler dxgi dxguid)
  59. endif ()
  60. unset (DIRECT3D_INCLUDE_DIRS)
  61. set (DIRECT3D_FOUND 1)
  62. elseif (MSVC_VERSION LESS 1700 OR NOT URHO3D_D3D11)
  63. # To avoid incompatibility between DirectX SDK and Windows SDK defines and the resulting warning spam,
  64. # only search for the DirectX SDK when using Visual Studion lower than VS2012 or when using D3D9
  65. set (DIRECTX_INC_SEARCH_PATH
  66. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include"
  67. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Include"
  68. "$ENV{DIRECTX_ROOT}/Include"
  69. "$ENV{DXSDK_DIR}/Include")
  70. find_path (DIRECT3D_INCLUDE_DIRS NAMES d3dcompiler.h PATHS ${DIRECTX_INC_SEARCH_PATH})
  71. if (CMAKE_CL_64)
  72. set (DIRECTX_LIB_SEARCH_PATH
  73. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x64"
  74. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x64"
  75. "$ENV{DIRECTX_ROOT}/Lib/x64"
  76. "$ENV{DXSDK_DIR}/Lib/x64")
  77. else ()
  78. set (DIRECTX_LIB_SEARCH_PATH
  79. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib"
  80. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86"
  81. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib"
  82. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x86"
  83. "$ENV{DIRECTX_ROOT}/Lib"
  84. "$ENV{DIRECTX_ROOT}/Lib/x86"
  85. "$ENV{DXSDK_DIR}/Lib"
  86. "$ENV{DXSDK_DIR}/Lib/x86")
  87. endif ()
  88. if (NOT URHO3D_D3D11)
  89. find_library (DIRECT3D_LIB_D3D9 NAMES d3d9 PATHS ${DIRECTX_LIB_SEARCH_PATH})
  90. find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
  91. if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D9 AND DIRECT3D_LIB_D3DCOMPILER)
  92. set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D9} ${DIRECT3D_LIB_D3DCOMPILER})
  93. set (DIRECT3D_FOUND 1)
  94. endif ()
  95. else ()
  96. find_library (DIRECT3D_LIB_D3D11 NAMES d3d11 PATHS ${DIRECTX_LIB_SEARCH_PATH})
  97. find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
  98. find_library (DIRECT3D_LIB_DXGI NAMES dxgi PATHS ${DIRECTX_LIB_SEARCH_PATH})
  99. find_library (DIRECT3D_LIB_DXGUID NAMES dxguid PATHS ${DIRECTX_LIB_SEARCH_PATH})
  100. if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D11 AND DIRECT3D_LIB_D3DCOMPILER AND DIRECT3D_LIB_DXGI AND DIRECT3D_LIB_DXGUID)
  101. set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D11} ${DIRECT3D_LIB_D3DCOMPILER} ${DIRECT3D_LIB_DXGI} ${DIRECT3D_LIB_DXGUID})
  102. set (DIRECT3D_FOUND 1)
  103. endif ()
  104. endif ()
  105. endif ()
  106. if (DIRECT3D_FOUND)
  107. include (FindPackageMessage)
  108. FIND_PACKAGE_MESSAGE (Direct3D "Found Direct3D: ${DIRECT3D_LIBRARIES} ${DIRECT3D_INCLUDE_DIRS}" "[${DIRECT3D_LIBRARIES}][${DIRECT3D_INCLUDE_DIRS}]")
  109. elseif (Direct3D_FIND_REQUIRED)
  110. message (FATAL_ERROR "Could not find Direct3D in Windows SDK and DirectX SDK")
  111. endif ()
  112. mark_as_advanced (DIRECT3D_INCLUDE_DIRS DIRECT3D_LIBRARIES DIRECT3D_DLL)