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

222 lines
8.0 KiB

  1. # sdl2 cmake project-config input for ./configure script
  2. include(FeatureSummary)
  3. set_package_properties(SDL2 PROPERTIES
  4. URL "https://www.libsdl.org/"
  5. DESCRIPTION "low level access to audio, keyboard, mouse, joystick, and graphics hardware"
  6. )
  7. # Copied from `configure_package_config_file`
  8. macro(set_and_check _var _file)
  9. set(${_var} "${_file}")
  10. if(NOT EXISTS "${_file}")
  11. message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  12. endif()
  13. endmacro()
  14. get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR} REALPATH)
  15. get_filename_component(prefix "${CMAKE_CURRENT_LIST_DIR}/@cmake_prefix_relpath@" ABSOLUTE)
  16. set(exec_prefix "@exec_prefix@")
  17. set(bindir "@bindir@")
  18. set(libdir "@libdir@")
  19. set(includedir "@includedir@")
  20. set_and_check(SDL2_PREFIX "${prefix}")
  21. set_and_check(SDL2_EXEC_PREFIX "${exec_prefix}")
  22. set_and_check(SDL2_BINDIR "${bindir}")
  23. set_and_check(SDL2_INCLUDE_DIR "${includedir}/SDL2")
  24. set_and_check(SDL2_LIBDIR "${libdir}")
  25. set(SDL2_INCLUDE_DIRS "${includedir};${SDL2_INCLUDE_DIR}")
  26. set(SDL2_LIBRARIES SDL2::SDL2)
  27. set(SDL2_STATIC_LIBRARIES SDL2::SDL2-static)
  28. set(SDL2MAIN_LIBRARY)
  29. set(SDL2TEST_LIBRARY SDL2::SDL2test)
  30. unset(prefix)
  31. unset(exec_prefix)
  32. unset(bindir)
  33. unset(libdir)
  34. unset(includedir)
  35. set(_sdl2_libraries_in "@SDL_LIBS@")
  36. set(_sdl2_static_private_libs_in "@SDL_STATIC_LIBS@")
  37. # Convert _sdl2_libraries to list and keep only libraries + library directories
  38. string(REGEX MATCHALL "-[lm]([-a-zA-Z0-9._]+)" _sdl2_libraries "${_sdl2_libraries_in}")
  39. string(REGEX REPLACE "^-l" "" _sdl2_libraries "${_sdl2_libraries}")
  40. string(REGEX REPLACE ";-l" ";" _sdl2_libraries "${_sdl2_libraries}")
  41. string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl2_libdirs "${_sdl2_libraries_in}")
  42. string(REGEX REPLACE "^-L" "" _sdl2_libdirs "${_sdl2_libdirs}")
  43. string(REGEX REPLACE ";-L" ";" _sdl2_libdirs "${_sdl2_libdirs}")
  44. list(APPEND _sdl2_libdirs "${SDL2_LIBDIR}")
  45. # Convert _sdl2_static_private_libs to list and keep only libraries + library directories
  46. string(REGEX MATCHALL "(-[lm]([-a-zA-Z0-9._]+))|(-Wl,[^ ]*framework[^ ]*)|(-pthread)" _sdl2_static_private_libs "${_sdl2_static_private_libs_in}")
  47. string(REGEX REPLACE "^-l" "" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
  48. string(REGEX REPLACE ";-l" ";" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
  49. string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl2_static_private_libdirs "${_sdl2_static_private_libs_in}")
  50. string(REGEX REPLACE "^-L" "" _sdl2_static_private_libdirs "${_sdl2_static_private_libdirs}")
  51. string(REGEX REPLACE ";-L" ";" _sdl2_static_private_libdirs "${_sdl2_static_private_libdirs}")
  52. # Set SDL2_NO_MWINDOWS to a true-ish value to not add the -mwindows link option
  53. if(SDL2_NO_MWINDOWS)
  54. list(REMOVE_ITEM _sdl2_libraries "-mwindows")
  55. endif()
  56. if(_sdl2_libraries MATCHES ".*SDL2main.*")
  57. list(INSERT SDL2_LIBRARIES 0 SDL2::SDL2main)
  58. list(INSERT SDL2_STATIC_LIBRARIES 0 SDL2::SDL2main)
  59. endif()
  60. set(_sdl2main_library ${SDL2_LIBDIR}/libSDL2main.a)
  61. if(EXISTS "${_sdl2main_library}")
  62. set(SDL2MAIN_LIBRARY SDL2::SDL2main)
  63. if(NOT TARGET SDL2::SDL2main)
  64. add_library(SDL2::SDL2main STATIC IMPORTED)
  65. set_target_properties(SDL2::SDL2main
  66. PROPERTIES
  67. IMPORTED_LOCATION "${_sdl2main_library}"
  68. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  69. INTERFACE_SDL_VERSION "SDL2"
  70. )
  71. if(WIN32)
  72. # INTERFACE_LINK_OPTIONS needs CMake 3.13
  73. cmake_minimum_required(VERSION 3.13)
  74. # Mark WinMain/WinMain@16 as undefined, such that it will be withheld by the linker.
  75. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  76. set_target_properties(SDL2::SDL2main
  77. PROPERTIES
  78. INTERFACE_LINK_OPTIONS "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=_WinMain@16>"
  79. )
  80. else()
  81. set_target_properties(SDL2::SDL2main
  82. PROPERTIES
  83. INTERFACE_LINK_OPTIONS "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=WinMain>"
  84. )
  85. endif()
  86. endif()
  87. endif()
  88. set(SDL2_SDL2main_FOUND TRUE)
  89. else()
  90. set(SDL2_SDL2main_FOUND FALSE)
  91. endif()
  92. unset(_sdl2main_library)
  93. # Remove SDL2 since this is the "central" library
  94. # Remove SDL2main since this will be provided by SDL2::SDL2main (if available)
  95. # Remove mingw32 and cygwin since these are not needed when using `-Wl,--undefined,WinMain`
  96. set(_sdl2_link_libraries ${_sdl2_libraries})
  97. list(REMOVE_ITEM _sdl2_link_libraries SDL2 SDL2main mingw32 cygwin)
  98. if(WIN32)
  99. set(_sdl2_implib "${SDL2_LIBDIR}/libSDL2.dll.a")
  100. set(_sdl2_dll "${SDL2_BINDIR}/SDL2.dll")
  101. if(EXISTS "${_sdl2_implib}" AND EXISTS "${_sdl2_dll}")
  102. if(NOT TARGET SDL2::SDL2)
  103. add_library(SDL2::SDL2 SHARED IMPORTED)
  104. set_target_properties(SDL2::SDL2 PROPERTIES
  105. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  106. INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries}"
  107. INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
  108. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  109. IMPORTED_IMPLIB "${_sdl2_implib}"
  110. IMPORTED_LOCATION "${_sdl2_dll}"
  111. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  112. INTERFACE_SDL_VERSION "SDL2"
  113. )
  114. endif()
  115. set(SDL2_SDL2_FOUND TRUE)
  116. else()
  117. set(SDL2_SDL2_FOUND FALSE)
  118. endif()
  119. unset(_sdl2_implib)
  120. unset(_sdl2_dll)
  121. else()
  122. set(_sdl2_shared "${SDL2_LIBDIR}/libSDL2${CMAKE_SHARED_LIBRARY_SUFFIX}")
  123. if(EXISTS "${_sdl2_shared}")
  124. if(NOT TARGET SDL2::SDL2)
  125. add_library(SDL2::SDL2 SHARED IMPORTED)
  126. set_target_properties(SDL2::SDL2 PROPERTIES
  127. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  128. INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries}"
  129. INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
  130. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  131. IMPORTED_LOCATION "${_sdl2_shared}"
  132. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  133. INTERFACE_SDL_VERSION "SDL2"
  134. )
  135. endif()
  136. set(SDL2_SDL2_FOUND TRUE)
  137. else()
  138. set(SDL2_SDL2_FOUND FALSE)
  139. endif()
  140. unset(_sdl2_shared)
  141. endif()
  142. set(_sdl2_static "${SDL2_LIBDIR}/libSDL2.a")
  143. if(EXISTS "${_sdl2_static}")
  144. if(NOT TARGET SDL2::SDL2-static)
  145. add_library(SDL2::SDL2-static STATIC IMPORTED)
  146. set_target_properties(SDL2::SDL2-static
  147. PROPERTIES
  148. IMPORTED_LOCATION "${_sdl2_static}"
  149. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  150. INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries};${_sdl2_static_private_libs}"
  151. INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs};${_sdl2_static_private_libdirs}"
  152. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  153. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  154. INTERFACE_SDL_VERSION "SDL2"
  155. )
  156. endif()
  157. set(SDL2_SDL2-static_FOUND TRUE)
  158. else()
  159. set(SDL2_SDL2-static_FOUND FALSE)
  160. endif()
  161. unset(_sdl2_static)
  162. unset(_sdl2_link_libraries)
  163. set(_sdl2test_library "${SDL2_LIBDIR}/libSDL2_test.a")
  164. if(EXISTS "${_sdl2test_library}")
  165. if(NOT TARGET SDL2::SDL2test)
  166. add_library(SDL2::SDL2test STATIC IMPORTED)
  167. set_target_properties(SDL2::SDL2test
  168. PROPERTIES
  169. IMPORTED_LOCATION "${_sdl2test_library}"
  170. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
  171. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  172. COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
  173. INTERFACE_SDL_VERSION "SDL2"
  174. )
  175. endif()
  176. set(SDL2_SDL2test_FOUND TRUE)
  177. else()
  178. set(SDL2_SDL2test_FOUND FALSE)
  179. endif()
  180. unset(_sdl2test_library)
  181. # Copied from `configure_package_config_file`
  182. macro(check_required_components _NAME)
  183. foreach(comp ${${_NAME}_FIND_COMPONENTS})
  184. if(NOT ${_NAME}_${comp}_FOUND)
  185. if(${_NAME}_FIND_REQUIRED_${comp})
  186. set(${_NAME}_FOUND FALSE)
  187. endif()
  188. endif()
  189. endforeach()
  190. endmacro()
  191. check_required_components(SDL2)
  192. # Create SDL2::SDL2 alias for static-only builds
  193. if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
  194. if(CMAKE_VERSION VERSION_LESS "3.18")
  195. # FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
  196. add_library(SDL2::SDL2 INTERFACE IMPORTED)
  197. set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES "SDL2::SDL2-static")
  198. else()
  199. add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
  200. endif()
  201. endif()