🛠️🐜 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.

119 lines
5.3 KiB

  1. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")
  2. include("${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")
  3. endif()
  4. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2mainTargets.cmake")
  5. include("${CMAKE_CURRENT_LIST_DIR}/SDL2mainTargets.cmake")
  6. endif()
  7. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2staticTargets.cmake")
  8. include("${CMAKE_CURRENT_LIST_DIR}/SDL2staticTargets.cmake")
  9. endif()
  10. # on static-only builds create an alias
  11. if(NOT TARGET SDL2::SDL2 AND TARGET SDL2::SDL2-static)
  12. if(CMAKE_VERSION VERSION_LESS "3.18")
  13. # Aliasing local targets is not supported on CMake < 3.18, so make it global.
  14. set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE)
  15. endif()
  16. add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
  17. endif()
  18. # provide ${SDL2_LIBRARIES}, ${SDL2_INCLUDE_DIRS} etc, like sdl2-config.cmake does,
  19. # for compatibility between SDL2 built with autotools and SDL2 built with CMake
  20. # the following seems to work on Windows for both MSVC and MINGW+MSYS and with both SDL2Config/Target.cmake
  21. # from vcpkg and from building myself with cmake from latest git
  22. # AND on Linux when building SDL2 (tested current git) with CMake
  23. # the headers are easy - but note that this adds both .../include/ and .../include/SDL2/
  24. # while the SDL2_INCLUDE_DIRS of sdl2-config.cmake only add ...include/SDL2/
  25. # But at least if building worked with sdl2-config.cmake it will also work with this.
  26. get_target_property(SDL2_INCLUDE_DIRS SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
  27. # get the paths to the files to link against (.lib or .dll.a on Windows, .so or .a on Unix, ...) for both SDL2 and SDL2main
  28. # for the "normal"/release build they could be in lots of different properties..
  29. set(relprops IMPORTED_IMPLIB_RELEASE IMPORTED_IMPLIB_NOCONFIG IMPORTED_IMPLIB IMPORTED_IMPLIB_MINSIZEREL IMPORTED_IMPLIB_RELWITHDEBINFO
  30. IMPORTED_LOCATION_RELEASE IMPORTED_LOCATION_NOCONFIG IMPORTED_LOCATION IMPORTED_LOCATION_MINSIZEREL IMPORTED_LOCATION_RELWITHDEBINFO)
  31. # fewer possibilities for debug builds
  32. set(dbgprops IMPORTED_IMPLIB_DEBUG IMPORTED_LOCATION_DEBUG)
  33. foreach(prop ${relprops})
  34. get_target_property(sdl2implib SDL2::SDL2 ${prop})
  35. if(sdl2implib)
  36. #message("set sdl2implib from ${prop}")
  37. break()
  38. endif()
  39. endforeach()
  40. foreach(prop ${relprops})
  41. get_target_property(sdl2mainimplib SDL2::SDL2main ${prop})
  42. if(sdl2mainimplib)
  43. #message("set sdl2mainimplib from ${prop}")
  44. break()
  45. endif()
  46. endforeach()
  47. foreach(prop ${dbgprops})
  48. get_target_property(sdl2implibdbg SDL2::SDL2 ${prop})
  49. if(sdl2implibdbg)
  50. #message("set sdl2implibdbg from ${prop}")
  51. break()
  52. endif()
  53. endforeach()
  54. foreach(prop ${dbgprops})
  55. get_target_property(sdl2mainimplibdbg SDL2::SDL2main ${prop})
  56. if(sdl2mainimplibdbg)
  57. #message("set sdl2mainimplibdbg from ${prop}")
  58. break()
  59. endif()
  60. endforeach()
  61. if( sdl2implib AND sdl2mainimplib AND sdl2implibdbg AND sdl2mainimplibdbg )
  62. # we have both release and debug builds of SDL2 and SDL2main, so use this ugly
  63. # generator expression in SDL2_LIBRARIES to support both in MSVC, depending on build type configured there
  64. set(SDL2_LIBRARIES $<IF:$<CONFIG:Debug>,${sdl2mainimplibdbg},${sdl2mainimplib}> $<IF:$<CONFIG:Debug>,${sdl2implibdbg},${sdl2implib}>)
  65. else()
  66. if( (NOT sdl2implib) AND sdl2implibdbg ) # if we only have a debug version of the lib
  67. set(sdl2implib ${sdl2implibdbg})
  68. endif()
  69. if( (NOT sdl2mainimplib) AND sdl2mainimplibdbg ) # if we only have a debug version of the lib
  70. set(sdl2mainimplib ${sdl2mainimplibdbg})
  71. endif()
  72. if( sdl2implib AND sdl2mainimplib )
  73. set(SDL2_LIBRARIES ${sdl2mainimplib} ${sdl2implib})
  74. elseif(WIN32 OR APPLE) # I think these platforms have a non-dummy SDLmain?
  75. message(FATAL_ERROR, "SDL2::SDL2 and/or SDL2::SDL2main don't seem to contain any kind of IMPORTED_IMPLIB* or IMPORTED_LOCATION*")
  76. elseif(sdl2implib) # on other platforms just libSDL2 will hopefully do?
  77. set(SDL2_LIBRARIES ${sdl2implib})
  78. message(STATUS, "No SDL2main lib not found, I hope you don't need it..")
  79. else()
  80. message(FATAL_ERROR, "SDL2::SDL2 doesn't seem to contain any kind of lib to link against in IMPORTED_IMPLIB* or IMPORTED_LOCATION*")
  81. endif()
  82. # TODO: should something like INTERFACE_LINK_LIBRARIES be appended? or wherever -mwindows and things like that
  83. # might be defined (if they were defined by the CMake build at all; autotools has @SDL_RLD_FLAGS@ @SDL_LIBS@)?
  84. # LINK_DEPENDS? LINK_FLAGS?
  85. endif()
  86. get_filename_component(SDL2_LIBDIR ${sdl2implib} PATH)
  87. # NOTE: SDL2_LIBRARIES now looks like "c:/path/to/SDL2main.lib;c:/path/to/SDL2.lib"
  88. # which is different to what it looks like when coming from sdl2-config.cmake
  89. # (there it's more like "-L${SDL2_LIBDIR} -lSDL2main -lSDL2" - and also -lmingw32 and -mwindows)
  90. # This seems to work with both MSVC and MinGW though, while the other only worked with MinGW
  91. # On Linux it looks like "/tmp/sdl2inst/lib/libSDL2main.a;/tmp/sdl2inst/lib/libSDL2-2.0.so.0.14.1" which also seems to work
  92. # the exec prefix is one level up from lib/ - TODO: really, always? at least on Linux there's /usr/lib/x86_64-bla-blub/libSDL2-asdf.so.0 ..
  93. get_filename_component(SDL2_EXEC_PREFIX ${SDL2_LIBDIR} PATH)
  94. set(SDL2_PREFIX ${SDL2_EXEC_PREFIX}) # TODO: could this be somewhere else? parent dir of include or sth?
  95. unset(sdl2implib)
  96. unset(sdl2mainimplib)
  97. unset(sdl2implibdbg)
  98. unset(sdl2mainimplibdbg)
  99. unset(relprops)
  100. unset(dbgprops)