sdl2-config.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # SDL2 CMake configuration file:
  2. # This file is meant to be placed in a cmake subfolder of SDL2-devel-2.x.y-VC
  3. cmake_minimum_required(VERSION 3.0)
  4. include(FeatureSummary)
  5. set_package_properties(SDL2 PROPERTIES
  6. URL "https://www.libsdl.org/"
  7. DESCRIPTION "low level access to audio, keyboard, mouse, joystick, and graphics hardware"
  8. )
  9. # Copied from `configure_package_config_file`
  10. macro(set_and_check _var _file)
  11. set(${_var} "${_file}")
  12. if(NOT EXISTS "${_file}")
  13. message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  14. endif()
  15. endmacro()
  16. # Copied from `configure_package_config_file`
  17. macro(check_required_components _NAME)
  18. foreach(comp ${${_NAME}_FIND_COMPONENTS})
  19. if(NOT ${_NAME}_${comp}_FOUND)
  20. if(${_NAME}_FIND_REQUIRED_${comp})
  21. set(${_NAME}_FOUND FALSE)
  22. endif()
  23. endif()
  24. endforeach()
  25. endmacro()
  26. set(SDL2_FOUND TRUE)
  27. if(CMAKE_SIZEOF_VOID_P STREQUAL "4")
  28. set(_sdl_arch_subdir "x86")
  29. elseif(CMAKE_SIZEOF_VOID_P STREQUAL "8")
  30. set(_sdl_arch_subdir "x64")
  31. else()
  32. set(SDL2_FOUND FALSE)
  33. return()
  34. endif()
  35. # For compatibility with autotools sdl2-config.cmake, provide SDL2_* variables.
  36. set_and_check(SDL2_PREFIX "${CMAKE_CURRENT_LIST_DIR}/..")
  37. set_and_check(SDL2_EXEC_PREFIX "${CMAKE_CURRENT_LIST_DIR}/..")
  38. set_and_check(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include")
  39. set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}")
  40. set_and_check(SDL2_BINDIR "${SDL2_PREFIX}/lib/${_sdl_arch_subdir}")
  41. set_and_check(SDL2_LIBDIR "${SDL2_PREFIX}/lib/${_sdl_arch_subdir}")
  42. set(SDL2_LIBRARIES SDL2::SDL2main SDL2::SDL2)
  43. set(SDL2MAIN_LIBRARY SDL2::SDL2main)
  44. set(SDL2TEST_LIBRARY SDL2::SDL2test)
  45. # All targets are created, even when some might not be requested though COMPONENTS.
  46. # This is done for compatibility with CMake generated SDL2-target.cmake files.
  47. set(_sdl2_library "${SDL2_LIBDIR}/SDL2.lib")
  48. set(_sdl2_dll_library "${SDL2_BINDIR}/SDL2.dll")
  49. if(EXISTS "${_sdl2_library}" AND EXISTS "${_sdl2_dll_library}")
  50. if(NOT TARGET SDL2::SDL2)
  51. add_library(SDL2::SDL2 SHARED IMPORTED)
  52. set_target_properties(SDL2::SDL2
  53. PROPERTIES
  54. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  55. IMPORTED_IMPLIB "${_sdl2_library}"
  56. IMPORTED_LOCATION "${_sdl2_dll_library}"
  57. COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED"
  58. INTERFACE_SDL2_SHARED "ON"
  59. )
  60. endif()
  61. set(SDL2_SDL2_FOUND TRUE)
  62. else()
  63. set(SDL2_SDL2_FOUND FALSE)
  64. endif()
  65. unset(_sdl2_library)
  66. unset(_sdl2_dll_library)
  67. set(_sdl2main_library "${SDL2_LIBDIR}/SDL2main.lib")
  68. if(EXISTS "${_sdl2main_library}")
  69. if(NOT TARGET SDL2::SDL2main)
  70. add_library(SDL2::SDL2main STATIC IMPORTED)
  71. set_target_properties(SDL2::SDL2main
  72. PROPERTIES
  73. IMPORTED_LOCATION "${_sdl2main_library}"
  74. )
  75. endif()
  76. set(SDL2_SDL2main_FOUND TRUE)
  77. else()
  78. set(SDL2_SDL2_FOUND FALSE)
  79. endif()
  80. unset(_sdl2main_library)
  81. set(_sdl2test_library "${SDL2_LIBDIR}/SDL2test.lib")
  82. if(EXISTS "${_sdl2test_library}")
  83. if(NOT TARGET SDL2::SDL2test)
  84. add_library(SDL2::SDL2test STATIC IMPORTED)
  85. set_target_properties(SDL2::SDL2test
  86. PROPERTIES
  87. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  88. IMPORTED_LOCATION "${_sdl2test_library}"
  89. )
  90. endif()
  91. set(SDL2_SDL2test_FOUND TRUE)
  92. else()
  93. set(SDL2_SDL2_FOUND FALSE)
  94. endif()
  95. unset(_sdl2test_library)
  96. check_required_components(SDL2)