sdl2-config.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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...3.5)
  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. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  60. INTERFACE_SDL_VERSION "SDL2"
  61. )
  62. endif()
  63. set(SDL2_SDL2_FOUND TRUE)
  64. else()
  65. set(SDL2_SDL2_FOUND FALSE)
  66. endif()
  67. unset(_sdl2_library)
  68. unset(_sdl2_dll_library)
  69. set(_sdl2main_library "${SDL2_LIBDIR}/SDL2main.lib")
  70. if(EXISTS "${_sdl2main_library}")
  71. if(NOT TARGET SDL2::SDL2main)
  72. add_library(SDL2::SDL2main STATIC IMPORTED)
  73. set_target_properties(SDL2::SDL2main
  74. PROPERTIES
  75. IMPORTED_LOCATION "${_sdl2main_library}"
  76. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  77. INTERFACE_SDL_VERSION "SDL2"
  78. )
  79. endif()
  80. set(SDL2_SDL2main_FOUND TRUE)
  81. else()
  82. set(SDL2_SDL2_FOUND FALSE)
  83. endif()
  84. unset(_sdl2main_library)
  85. set(_sdl2test_library "${SDL2_LIBDIR}/SDL2test.lib")
  86. if(EXISTS "${_sdl2test_library}")
  87. if(NOT TARGET SDL2::SDL2test)
  88. add_library(SDL2::SDL2test STATIC IMPORTED)
  89. set_target_properties(SDL2::SDL2test
  90. PROPERTIES
  91. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  92. IMPORTED_LOCATION "${_sdl2test_library}"
  93. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  94. INTERFACE_SDL_VERSION "SDL2"
  95. )
  96. endif()
  97. set(SDL2_SDL2test_FOUND TRUE)
  98. else()
  99. set(SDL2_SDL2_FOUND FALSE)
  100. endif()
  101. unset(_sdl2test_library)
  102. check_required_components(SDL2)