sdl3-config.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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::SDL3)
  43. set(SDL3TEST_LIBRARY SDL3::SDL3_test)
  44. # All targets are created, even when some might not be requested though COMPONENTS.
  45. # This is done for compatibility with CMake generated SDL3-target.cmake files.
  46. set(_sdl3_library "${SDL3_LIBDIR}/SDL3.lib")
  47. set(_sdl3_dll_library "${SDL3_BINDIR}/SDL3.dll")
  48. if(EXISTS "${_sdl3_library}" AND EXISTS "${_sdl3_dll_library}")
  49. if(NOT TARGET SDL3::SDL3)
  50. add_library(SDL3::SDL3 SHARED IMPORTED)
  51. set_target_properties(SDL3::SDL3
  52. PROPERTIES
  53. INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIRS}"
  54. IMPORTED_IMPLIB "${_sdl3_library}"
  55. IMPORTED_LOCATION "${_sdl3_dll_library}"
  56. COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
  57. INTERFACE_SDL3_SHARED "ON"
  58. )
  59. endif()
  60. set(SDL3_SDL3_FOUND TRUE)
  61. else()
  62. set(SDL3_SDL3_FOUND FALSE)
  63. endif()
  64. unset(_sdl3_library)
  65. unset(_sdl3_dll_library)
  66. set(_sdl3test_library "${SDL3_LIBDIR}/SDL3_test.lib")
  67. if(EXISTS "${_sdl3test_library}")
  68. if(NOT TARGET SDL3::SDL3_test)
  69. add_library(SDL3::SDL3_test STATIC IMPORTED)
  70. set_target_properties(SDL3::SDL3_test
  71. PROPERTIES
  72. INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIRS}"
  73. IMPORTED_LOCATION "${_sdl3test_library}"
  74. )
  75. endif()
  76. set(SDL3_SDL3_test_FOUND TRUE)
  77. else()
  78. set(SDL3_SDL3_FOUND FALSE)
  79. endif()
  80. unset(_sdl3test_library)
  81. check_required_components(SDL3)