FindDirect3D.cmake 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 DirectX installation (need June 2010 SDK or later, or a Windows SDK)
  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 |gcc -v -E -' and 'gcc -print-search-dirs', respectively, to double check)
  25. #
  26. # DIRECT3D_FOUND
  27. # DIRECT3D_INCLUDE_DIRS
  28. # DIRECT3D_LIBRARIES
  29. #
  30. if (NOT WIN32 OR DIRECT3D_FOUND)
  31. return ()
  32. endif ()
  33. # When using Direct3D11, do not search for the SDK from Visual Studio 2012 onward
  34. # to avoid incompatibility between DirectX SDK and Windows SDK defines and the
  35. # resulting warning spam
  36. if (MSVC AND (MSVC_VERSION LESS 1700 OR NOT URHO3D_D3D11))
  37. set (DIRECTX_INC_SEARCH_PATH
  38. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include"
  39. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Include"
  40. "$ENV{DIRECTX_ROOT}/Include"
  41. "$ENV{DXSDK_DIR}/Include")
  42. find_path (DIRECT3D_INCLUDE_DIRS NAMES d3dcompiler.h PATHS ${DIRECTX_INC_SEARCH_PATH})
  43. if (CMAKE_CL_64)
  44. set (DIRECTX_LIB_SEARCH_PATH
  45. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x64"
  46. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x64"
  47. "$ENV{DIRECTX_ROOT}/Lib/x64"
  48. "$ENV{DXSDK_DIR}/Lib/x64")
  49. else ()
  50. set (DIRECTX_LIB_SEARCH_PATH
  51. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib"
  52. "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86"
  53. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib"
  54. "C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x86"
  55. "$ENV{DIRECTX_ROOT}/Lib"
  56. "$ENV{DIRECTX_ROOT}/Lib/x86"
  57. "$ENV{DXSDK_DIR}/Lib"
  58. "$ENV{DXSDK_DIR}/Lib/x86")
  59. endif ()
  60. if (NOT URHO3D_D3D11)
  61. find_library (DIRECT3D_LIB_D3D9 NAMES d3d9 PATHS ${DIRECTX_LIB_SEARCH_PATH})
  62. find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
  63. if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D9 AND DIRECT3D_LIB_D3DCOMPILER)
  64. set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D9} ${DIRECT3D_LIB_D3DCOMPILER})
  65. set (DIRECT3D_FOUND 1)
  66. endif ()
  67. else ()
  68. find_library (DIRECT3D_LIB_D3D11 NAMES d3d11 PATHS ${DIRECTX_LIB_SEARCH_PATH})
  69. find_library (DIRECT3D_LIB_D3DCOMPILER NAMES d3dcompiler PATHS ${DIRECTX_LIB_SEARCH_PATH})
  70. find_library (DIRECT3D_LIB_DXGI NAMES dxgi PATHS ${DIRECTX_LIB_SEARCH_PATH})
  71. find_library (DIRECT3D_LIB_DXGUID NAMES dxguid PATHS ${DIRECTX_LIB_SEARCH_PATH})
  72. if (DIRECT3D_INCLUDE_DIRS AND DIRECT3D_LIB_D3D11 AND DIRECT3D_LIB_D3DCOMPILER AND DIRECT3D_LIB_DXGI AND DIRECT3D_LIB_DXGUID)
  73. set (DIRECT3D_LIBRARIES ${DIRECT3D_LIB_D3D11} ${DIRECT3D_LIB_D3DCOMPILER} ${DIRECT3D_LIB_DXGI} ${DIRECT3D_LIB_DXGUID})
  74. set (DIRECT3D_FOUND 1)
  75. endif ()
  76. endif ()
  77. endif ()
  78. if (DIRECT3D_FOUND)
  79. include (FindPackageMessage)
  80. FIND_PACKAGE_MESSAGE (Direct3D "Found DirectX SDK: ${DIRECT3D_LIBRARIES} ${DIRECT3D_INCLUDE_DIRS}" "[${DIRECT3D_LIBRARIES}][${DIRECT3D_INCLUDE_DIRS}]")
  81. else ()
  82. if (NOT URHO3D_D3D11)
  83. set (DIRECT3D_LIBRARIES d3d9 d3dcompiler)
  84. else ()
  85. set (DIRECT3D_LIBRARIES d3d11 d3dcompiler dxgi dxguid)
  86. endif ()
  87. if (MSVC)
  88. if (MSVC_VERSION LESS 1700 OR NOT URHO3D_D3D11)
  89. message (STATUS "DirectX SDK not found. This is not fatal if a recent Windows SDK is installed")
  90. else ()
  91. message (STATUS "DirectX SDK search skipped for MSVC 2012 and greater when using Direct3D 11")
  92. endif ()
  93. else ()
  94. message (STATUS "DirectX SDK search skipped for MinGW. It is assumed that MinGW itself comes with the necessary headers & libraries")
  95. endif ()
  96. endif ()
  97. mark_as_advanced (DIRECT3D_INCLUDE_DIRS DIRECT3D_LIBRARIES)