sdl3-config.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # SDL CMake configuration file:
  2. # This file is meant to be placed in a cmake subfolder of SDL3-devel-3.x.y-VC
  3. cmake_minimum_required(VERSION 3.0)
  4. include(FeatureSummary)
  5. set_package_properties(SDL3 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(SDL3_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(SDL3_FOUND FALSE)
  33. return()
  34. endif()
  35. # For compatibility with autotools sdl3-config.cmake, provide SDL3_* variables.
  36. set_and_check(SDL3_PREFIX "${CMAKE_CURRENT_LIST_DIR}/..")
  37. set_and_check(SDL3_EXEC_PREFIX "${CMAKE_CURRENT_LIST_DIR}/..")
  38. set_and_check(SDL3_INCLUDE_DIR "${SDL3_PREFIX}/include")
  39. set(SDL3_INCLUDE_DIRS "${SDL3_INCLUDE_DIR}")
  40. set_and_check(SDL3_BINDIR "${SDL3_PREFIX}/lib/${_sdl_arch_subdir}")
  41. set_and_check(SDL3_LIBDIR "${SDL3_PREFIX}/lib/${_sdl_arch_subdir}")
  42. set(SDL3_LIBRARIES SDL3::SDL3main SDL3::SDL3)
  43. set(SDL3MAIN_LIBRARY SDL3::SDL3main)
  44. set(SDL3TEST_LIBRARY SDL3::SDL3test)
  45. # All targets are created, even when some might not be requested though COMPONENTS.
  46. # This is done for compatibility with CMake generated SDL3-target.cmake files.
  47. set(_sdl3_library "${SDL3_LIBDIR}/SDL3.lib")
  48. set(_sdl3_dll_library "${SDL3_BINDIR}/SDL3.dll")
  49. if(EXISTS "${_sdl3_library}" AND EXISTS "${_sdl3_dll_library}")
  50. if(NOT TARGET SDL3::SDL3)
  51. add_library(SDL3::SDL3 SHARED IMPORTED)
  52. set_target_properties(SDL3::SDL3
  53. PROPERTIES
  54. INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIRS}"
  55. IMPORTED_IMPLIB "${_sdl3_library}"
  56. IMPORTED_LOCATION "${_sdl3_dll_library}"
  57. COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
  58. INTERFACE_SDL3_SHARED "ON"
  59. )
  60. endif()
  61. set(SDL3_SDL3_FOUND TRUE)
  62. else()
  63. set(SDL3_SDL3_FOUND FALSE)
  64. endif()
  65. unset(_sdl3_library)
  66. unset(_sdl3_dll_library)
  67. set(_sdl3main_library "${SDL3_LIBDIR}/SDL3main.lib")
  68. if(EXISTS "${_sdl3main_library}")
  69. if(NOT TARGET SDL3::SDL3main)
  70. add_library(SDL3::SDL3main STATIC IMPORTED)
  71. set_target_properties(SDL3::SDL3main
  72. PROPERTIES
  73. IMPORTED_LOCATION "${_sdl3main_library}"
  74. )
  75. endif()
  76. set(SDL3_SDL3main_FOUND TRUE)
  77. else()
  78. set(SDL3_SDL3_FOUND FALSE)
  79. endif()
  80. unset(_sdl3main_library)
  81. set(_sdl3test_library "${SDL3_LIBDIR}/SDL3test.lib")
  82. if(EXISTS "${_sdl3test_library}")
  83. if(NOT TARGET SDL3::SDL3test)
  84. add_library(SDL3::SDL3test STATIC IMPORTED)
  85. set_target_properties(SDL3::SDL3test
  86. PROPERTIES
  87. INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIRS}"
  88. IMPORTED_LOCATION "${_sdl3test_library}"
  89. )
  90. endif()
  91. set(SDL3_SDL3test_FOUND TRUE)
  92. else()
  93. set(SDL3_SDL3_FOUND FALSE)
  94. endif()
  95. unset(_sdl3test_library)
  96. check_required_components(SDL3)