sdl2-config.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. set(_sdl2_known_comps SDL2 SDL2main SDL2test)
  5. if(NOT SDL2_FIND_COMPONENTS)
  6. set(SDL2_FIND_COMPONENTS ${_sdl2_known_comps})
  7. endif()
  8. # Fail early when an unknown component is requested
  9. list(REMOVE_DUPLICATES SDL2_FIND_COMPONENTS)
  10. list(REMOVE_ITEM SDL2_FIND_COMPONENTS ${_sdl2_known_comps})
  11. if(SDL2_FIND_COMPONENTS)
  12. set(missing_required_comps)
  13. foreach(missingcomp ${SDL2_FIND_COMPONENTS})
  14. if(SDL2_FIND_REQUIRED_${missingcomp})
  15. list(APPEND missing_required_comps ${missingcomp})
  16. endif()
  17. endforeach()
  18. if(missing_required_comps)
  19. if(NOT SDL2_FIND_QUIETLY)
  20. message(WARNING "SDL2: following component(s) are not available: ${missing_required_comps}")
  21. endif()
  22. set(SDL2_FOUND FALSE)
  23. return()
  24. endif()
  25. endif()
  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. set(SDL2_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../include")
  36. set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}")
  37. set(SDL2_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/../lib/${_sdl_arch_subdir}/SDL2.lib")
  38. set(SDL2_DLL_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/../lib/${_sdl_arch_subdir}/SDL2.dll")
  39. set(SDL2main_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/../lib/${_sdl_arch_subdir}/SDL2main.lib")
  40. set(SDL2test_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/../lib/${_sdl_arch_subdir}/SDL2test.lib")
  41. # All targets are created, even when some might not be requested though COMPONENTS.
  42. # This is done for compatibility with CMake generated SDL2-target.cmake files.
  43. if(NOT TARGET SDL2::SDL2)
  44. add_library(SDL2::SDL2 SHARED IMPORTED)
  45. set_target_properties(SDL2::SDL2
  46. PROPERTIES
  47. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  48. IMPORTED_IMPLIB "${SDL2_LIBRARY}"
  49. IMPORTED_LOCATION "${SDL2_DLL_LIBRARY}"
  50. COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED"
  51. INTERFACE_SDL2_SHARED "ON"
  52. )
  53. endif()
  54. if(NOT TARGET SDL2::SDL2main)
  55. add_library(SDL2::SDL2main STATIC IMPORTED)
  56. set_target_properties(SDL2::SDL2main
  57. PROPERTIES
  58. IMPORTED_LOCATION "${SDL2main_LIBRARY}"
  59. )
  60. endif()
  61. if(NOT TARGET SDL2::SDL2test)
  62. add_library(SDL2::SDL2test STATIC IMPORTED)
  63. set_target_properties(SDL2::SDL2test
  64. PROPERTIES
  65. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  66. IMPORTED_LOCATION "${SDL2test_LIBRARY}"
  67. )
  68. endif()