sdl2-config.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. )
  51. endif()
  52. if(NOT TARGET SDL2::SDL2main)
  53. add_library(SDL2::SDL2main STATIC IMPORTED)
  54. set_target_properties(SDL2::SDL2main
  55. PROPERTIES
  56. IMPORTED_LOCATION "${SDL2main_LIBRARY}"
  57. )
  58. endif()
  59. if(NOT TARGET SDL2::SDL2test)
  60. add_library(SDL2::SDL2test STATIC IMPORTED)
  61. set_target_properties(SDL2::SDL2test
  62. PROPERTIES
  63. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  64. IMPORTED_LOCATION "${SDL2test_LIBRARY}"
  65. )
  66. endif()