FindDirect3D9.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Filename: FindDirect3D9.cmake
  2. # Authors: CFSworks (26 Oct, 2018)
  3. #
  4. # Usage:
  5. # find_package(Direct3D9 [REQUIRED] [QUIET])
  6. #
  7. # This supports the following components:
  8. # d3dx9
  9. # dxerr
  10. # dxguid
  11. #
  12. # Once done this will define:
  13. # DIRECT3D9_FOUND - system has Direct3D 9.x
  14. # DIRECT3D9_INCLUDE_DIR - the include directory containing d3d9.h - note that
  15. # this will be empty if it's part of the Windows SDK.
  16. # DIRECT3D9_LIBRARY - the path to d3d9.lib
  17. # DIRECT3D9_LIBRARIES - the path to d3d9.lib and all extra component
  18. # libraries
  19. #
  20. include(CheckIncludeFile)
  21. if(Direct3D9_FIND_QUIETLY)
  22. if(DEFINED CMAKE_REQUIRED_QUIET)
  23. set(_OLD_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
  24. endif()
  25. # Suppress check_include_file messages
  26. set(CMAKE_REQUIRED_QUIET ON)
  27. endif()
  28. check_include_file("d3d9.h" SYSTEM_INCLUDE_D3D9_H)
  29. mark_as_advanced(SYSTEM_INCLUDE_D3D9_H)
  30. if(Direct3D9_FIND_QUIETLY)
  31. if(DEFINED _OLD_CMAKE_REQUIRED_QUIET)
  32. set(CMAKE_REQUIRED_QUIET ${_OLD_CMAKE_REQUIRED_QUIET})
  33. unset(_OLD_CMAKE_REQUIRED_QUIET)
  34. else()
  35. unset(CMAKE_REQUIRED_QUIET)
  36. endif()
  37. endif()
  38. if(SYSTEM_INCLUDE_D3D9_H
  39. AND NOT Direct3D9_FIND_REQUIRED_d3dx9
  40. AND NOT Direct3D9_FIND_REQUIRED_dxerr)
  41. # It's available as #include <d3d9.h> - easy enough. We'll use "." as a way
  42. # of saying "We found it, but please erase this variable later."
  43. set(DIRECT3D9_INCLUDE_DIR ".")
  44. # Since d3d9.h is on the search path, we can pretty much assume d3d9.lib is
  45. # as well.
  46. set(DIRECT3D9_LIBRARY "d3d9.lib")
  47. # And dxguid.lib, why not
  48. set(DIRECT3D9_dxguid_LIBRARY "dxguid.lib")
  49. else()
  50. # We could not find it easily - maybe it's installed separately as part of
  51. # the DirectX SDK?
  52. find_path(DIRECT3D9_INCLUDE_DIR
  53. NAMES d3d9.h
  54. PATHS "$ENV{DXSDK_DIR}/Include")
  55. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  56. set(dx_lib_path "$ENV{DXSDK_DIR}/Lib/x64/")
  57. else()
  58. set(dx_lib_path "$ENV{DXSDK_DIR}/Lib/x86/")
  59. endif()
  60. find_library(DIRECT3D9_LIBRARY d3d9 "${dx_lib_path}" NO_DEFAULT_PATH)
  61. find_library(DIRECT3D9_d3dx9_LIBRARY d3dx9 "${dx_lib_path}" NO_DEFAULT_PATH)
  62. find_library(DIRECT3D9_dxerr_LIBRARY dxerr "${dx_lib_path}" NO_DEFAULT_PATH)
  63. find_library(DIRECT3D9_dxguid_LIBRARY dxguid "${dx_lib_path}" NO_DEFAULT_PATH)
  64. unset(dx_lib_path)
  65. endif()
  66. mark_as_advanced(DIRECT3D9_INCLUDE_DIR DIRECT3D9_LIBRARY)
  67. set(DIRECT3D9_LIBRARIES "${DIRECT3D9_LIBRARY}")
  68. foreach(_component d3dx9 dxerr dxguid)
  69. if(DIRECT3D9_${_component}_LIBRARY)
  70. set(Direct3D9_${_component}_FOUND ON)
  71. list(FIND Direct3D9_FIND_COMPONENTS "${_component}" _index)
  72. if(${_index} GREATER -1)
  73. list(APPEND DIRECT3D9_LIBRARIES "${DIRECT3D9_${_component}_LIBRARY}")
  74. endif()
  75. unset(_index)
  76. endif()
  77. endforeach(_component)
  78. unset(_component)
  79. include(FindPackageHandleStandardArgs)
  80. find_package_handle_standard_args(Direct3D9 HANDLE_COMPONENTS
  81. REQUIRED_VARS DIRECT3D9_INCLUDE_DIR DIRECT3D9_LIBRARY DIRECT3D9_LIBRARIES)
  82. # See above - if we found the include as part of the system path, we don't want
  83. # to actually modify the include search path, but we need a non-empty string to
  84. # satisfy find_package_handle_standard_args()
  85. if(DIRECT3D9_INCLUDE_DIR STREQUAL ".")
  86. set(DIRECT3D9_INCLUDE_DIR "")
  87. endif()