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

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