Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
3.6KB

  1. # Helper script to add the SDL2 CMake target and version variable as introduced in SDL 2.0.12.
  2. # Also fixes a wrong include path provided by the SDL2 config script.
  3. # Proper CMake target support was added in SDL 2.0.12, create one
  4. # Need to search again to find the full path of libSDL2
  5. if(NOT TARGET SDL2::SDL2)
  6. # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
  7. # This may require "libdir" being set (from above)
  8. string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS " -lSDL2 ")
  9. string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
  10. string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC " -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lpulse-simple -lpulse -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt ")
  11. string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
  12. find_library(SDL2_LIBRARY SDL2)
  13. if(NOT SDL2_LIBRARY)
  14. message(FATAL_ERROR "Could not determine the location of the SDL2 library.")
  15. endif()
  16. add_library(SDL2::SDL2 SHARED IMPORTED)
  17. set_target_properties(SDL2::SDL2 PROPERTIES
  18. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  19. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  20. IMPORTED_LOCATION "${SDL2_LIBRARY}"
  21. INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
  22. find_library(SDL2MAIN_LIBRARY SDL2main)
  23. if(NOT SDL2MAIN_LIBRARY)
  24. message(FATAL_ERROR "Could not determine the location of the SDL2main library.")
  25. endif()
  26. add_library(SDL2::SDL2main STATIC IMPORTED)
  27. set_target_properties(SDL2::SDL2main PROPERTIES
  28. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  29. IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}")
  30. # Retrieve the version from the SDL2_version.h header
  31. if(SDL2_INCLUDE_DIRS AND EXISTS "${SDL2_INCLUDE_DIRS}/SDL_version.h")
  32. file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
  33. file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
  34. file(STRINGS "${SDL2_INCLUDE_DIRS}/SDL_version.h" SDL_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
  35. string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}")
  36. string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}")
  37. string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}")
  38. set(SDL2_VERSION ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH})
  39. unset(SDL_VERSION_MAJOR_LINE)
  40. unset(SDL_VERSION_MINOR_LINE)
  41. unset(SDL_VERSION_PATCH_LINE)
  42. unset(SDL_VERSION_MAJOR)
  43. unset(SDL_VERSION_MINOR)
  44. unset(SDL_VERSION_PATCH)
  45. endif()
  46. endif()
  47. # Temporary fix to deal with wrong include dir set by SDL2's CMake configuration.
  48. get_target_property(_SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
  49. if(_SDL2_INCLUDE_DIR MATCHES "(.+)/SDL2\$")
  50. message(STATUS "SDL2 include dir contains \"SDL2\" subdir (SDL bug #4004) - fixing to \"${CMAKE_MATCH_1}\".")
  51. set_target_properties(SDL2::SDL2 PROPERTIES
  52. INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_MATCH_1}"
  53. )
  54. endif()
  55. if(SDL2_VERSION AND SDL2_VERSION VERSION_LESS "2.0.5")
  56. message(FATAL_ERROR "SDL2 libraries were found, but have version ${SDL2_VERSION}. At least version 2.0.5 is required.")
  57. endif()