🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

81 lines
4.2 KiB

  1. # sdl2 cmake project-config input for ./configure scripts
  2. set(prefix "@prefix@")
  3. set(exec_prefix "@exec_prefix@")
  4. set(libdir "@libdir@")
  5. set(includedir "@includedir@")
  6. set(SDL2_PREFIX "${prefix}")
  7. set(SDL2_EXEC_PREFIX "${exec_prefix}")
  8. set(SDL2_LIBDIR "${libdir}")
  9. set(SDL2_INCLUDE_DIRS "${includedir}/SDL2")
  10. set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} @SDL_RLD_FLAGS@ @SDL_LIBS@")
  11. string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
  12. if(NOT TARGET SDL2::SDL2)
  13. # provide SDL2::SDL2, SDL2::SDL2main and SDL2::SDL2-static targets, like SDL2Config.cmake does, for compatibility
  14. # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
  15. # This may require "libdir" beeing set (from above)
  16. string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "@SDL_RLD_FLAGS@ @SDL_LIBS@ ")
  17. # also get rid of -lSDL2main, if you want to link against that use both SDL2::SDL2main and SDL2::SDL2 (in that order)
  18. # (SDL2Config.cmake has the same behavior)
  19. string(REPLACE "-lSDL2main" "" SDL2_EXTRA_LINK_FLAGS ${SDL2_EXTRA_LINK_FLAGS})
  20. string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
  21. string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "@SDL_STATIC_LIBS@ ")
  22. string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)
  23. if(WIN32 AND NOT MSVC)
  24. # MINGW needs very special handling, because the link order must be exactly -lmingw32 -lSDL2main -lSDL2
  25. # for it to work at all (and -mwindows somewhere); a normal SHARED IMPORTED or STATIC IMPORTED library always puts itself first
  26. # so handle this like a header-only lib and put everything in INTERFACE_LINK_LIBRARIES
  27. add_library(SDL2::SDL2 INTERFACE IMPORTED)
  28. set_target_properties(SDL2::SDL2 PROPERTIES
  29. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  30. INTERFACE_LINK_LIBRARIES "-L${SDL2_LIBDIR} -lSDL2")
  31. add_library(SDL2::SDL2main INTERFACE IMPORTED)
  32. set_target_properties(SDL2::SDL2main PROPERTIES
  33. INTERFACE_LINK_LIBRARIES "-L${SDL2_LIBDIR} -lmingw32 -lSDL2main -mwindows")
  34. else() # (not WIN32) or MSVC
  35. add_library(SDL2::SDL2 SHARED IMPORTED)
  36. set_target_properties(SDL2::SDL2 PROPERTIES
  37. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  38. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  39. IMPORTED_LOCATION "${SDL2_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}SDL2${CMAKE_SHARED_LIBRARY_SUFFIX}")
  40. if(MSVC)
  41. # This file is generated when building SDL2 with autotools and MinGW, and MinGW/dlltool
  42. # isn't able to generate .lib files that are usable by recent MSVC versions
  43. # (something about "module unsafe for SAFESEH"; SAFESEH is enabled by default in MSVC).
  44. # The .lib file for SDL2.dll *could* be generated with `gendef SDL2.dll` and then
  45. # `lib.exe /machine:x86 /def:SDL2.def /out:SDL2.lib` (or /machine:amd64)
  46. # but that requires lib.exe from a Visual Studio installation - and that still doesn't
  47. # give you a static SDL2main.lib with SAFESEH support that you'll need (unless you don't use SDL2main)
  48. # Note that when building SDL2 with CMake and MSVC, the result works with both MinGW and MSVC.
  49. message(FATAL_ERROR, "This build of libSDL2 only supports MinGW, not MSVC (Visual C++), because it lacks .lib files!")
  50. # MSVC needs SDL2.lib set as IMPORTED_IMPLIB to link against (comment out message() call above if you added SDL2.lib yourself)
  51. set_target_properties(SDL2::SDL2 PROPERTIES IMPORTED_IMPLIB "${SDL2_LIBDIR}/SDL2.lib")
  52. else()
  53. # this mustn't be set for MSVC, so do it here in an extra call here
  54. set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")
  55. endif()
  56. add_library(SDL2::SDL2main STATIC IMPORTED)
  57. set_target_properties(SDL2::SDL2main PROPERTIES
  58. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  59. IMPORTED_LOCATION "${SDL2_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2main${CMAKE_STATIC_LIBRARY_SUFFIX}")
  60. endif() # (not WIN32) or MSVC
  61. add_library(SDL2::SDL2-static STATIC IMPORTED)
  62. set_target_properties(SDL2::SDL2-static PROPERTIES
  63. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
  64. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  65. IMPORTED_LOCATION "${SDL2_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2${CMAKE_STATIC_LIBRARY_SUFFIX}"
  66. INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")
  67. endif() # NOT TARGET SDL2::SDL2