2022-06-04 01:57:21 +08:00
|
|
|
# sdl2 cmake project-config input for ./configure script
|
2015-06-30 13:24:00 +08:00
|
|
|
|
2022-06-04 01:57:21 +08:00
|
|
|
include(FeatureSummary)
|
|
|
|
set_package_properties(SDL2 PROPERTIES
|
|
|
|
URL "https://www.libsdl.org/"
|
|
|
|
DESCRIPTION "low level access to audio, keyboard, mouse, joystick, and graphics hardware"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Copied from `configure_package_config_file`
|
|
|
|
macro(set_and_check _var _file)
|
|
|
|
set(${_var} "${_file}")
|
|
|
|
if(NOT EXISTS "${_file}")
|
|
|
|
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2023-01-15 06:49:06 +08:00
|
|
|
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR} REALPATH)
|
2022-07-25 08:01:59 +08:00
|
|
|
get_filename_component(prefix "${CMAKE_CURRENT_LIST_DIR}/@cmake_prefix_relpath@" ABSOLUTE)
|
2022-08-10 04:05:03 +08:00
|
|
|
|
2015-06-30 13:24:00 +08:00
|
|
|
set(exec_prefix "@exec_prefix@")
|
2022-06-04 01:57:21 +08:00
|
|
|
set(bindir "@bindir@")
|
2015-12-29 12:29:11 +08:00
|
|
|
set(libdir "@libdir@")
|
2021-04-21 12:27:41 +08:00
|
|
|
set(includedir "@includedir@")
|
2022-06-04 01:57:21 +08:00
|
|
|
|
|
|
|
set_and_check(SDL2_PREFIX "${prefix}")
|
|
|
|
set_and_check(SDL2_EXEC_PREFIX "${exec_prefix}")
|
|
|
|
set_and_check(SDL2_BINDIR "${bindir}")
|
|
|
|
set_and_check(SDL2_INCLUDE_DIR "${includedir}/SDL2")
|
|
|
|
set_and_check(SDL2_LIBDIR "${libdir}")
|
|
|
|
set(SDL2_INCLUDE_DIRS "${includedir};${SDL2_INCLUDE_DIR}")
|
|
|
|
|
|
|
|
set(SDL2_LIBRARIES SDL2::SDL2)
|
|
|
|
set(SDL2_STATIC_LIBRARIES SDL2::SDL2-static)
|
|
|
|
set(SDL2MAIN_LIBRARY)
|
|
|
|
set(SDL2TEST_LIBRARY SDL2::SDL2test)
|
|
|
|
|
|
|
|
unset(prefix)
|
|
|
|
unset(exec_prefix)
|
|
|
|
unset(bindir)
|
|
|
|
unset(libdir)
|
|
|
|
unset(includedir)
|
|
|
|
|
2022-08-21 10:03:32 +08:00
|
|
|
set(_sdl2_libraries_in "@SDL_LIBS@")
|
|
|
|
set(_sdl2_static_private_libs_in "@SDL_STATIC_LIBS@")
|
2022-06-04 01:57:21 +08:00
|
|
|
|
2022-08-21 10:03:32 +08:00
|
|
|
# Convert _sdl2_libraries to list and keep only libraries + library directories
|
|
|
|
string(REGEX MATCHALL "-[lm]([-a-zA-Z0-9._]+)" _sdl2_libraries "${_sdl2_libraries_in}")
|
2022-06-04 01:57:21 +08:00
|
|
|
string(REGEX REPLACE "^-l" "" _sdl2_libraries "${_sdl2_libraries}")
|
|
|
|
string(REGEX REPLACE ";-l" ";" _sdl2_libraries "${_sdl2_libraries}")
|
2022-08-21 10:03:32 +08:00
|
|
|
string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl2_libdirs "${_sdl2_libraries_in}")
|
|
|
|
string(REGEX REPLACE "^-L" "" _sdl2_libdirs "${_sdl2_libdirs}")
|
|
|
|
string(REGEX REPLACE ";-L" ";" _sdl2_libdirs "${_sdl2_libdirs}")
|
|
|
|
list(APPEND _sdl2_libdirs "${SDL2_LIBDIR}")
|
2022-06-04 01:57:21 +08:00
|
|
|
|
2022-08-21 10:03:32 +08:00
|
|
|
# Convert _sdl2_static_private_libs to list and keep only libraries + library directories
|
|
|
|
string(REGEX MATCHALL "(-[lm]([-a-zA-Z0-9._]+))|(-Wl,[^ ]*framework[^ ]*)|(-pthread)" _sdl2_static_private_libs "${_sdl2_static_private_libs_in}")
|
2022-06-04 01:57:21 +08:00
|
|
|
string(REGEX REPLACE "^-l" "" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
|
|
|
|
string(REGEX REPLACE ";-l" ";" _sdl2_static_private_libs "${_sdl2_static_private_libs}")
|
2022-08-21 10:03:32 +08:00
|
|
|
string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl2_static_private_libdirs "${_sdl2_static_private_libs_in}")
|
|
|
|
string(REGEX REPLACE "^-L" "" _sdl2_static_private_libdirs "${_sdl2_static_private_libdirs}")
|
|
|
|
string(REGEX REPLACE ";-L" ";" _sdl2_static_private_libdirs "${_sdl2_static_private_libdirs}")
|
2022-06-04 01:57:21 +08:00
|
|
|
|
2023-04-19 00:46:35 +08:00
|
|
|
# Set SDL2_NO_MWINDOWS to a true-ish value to not add the -mwindows link option
|
|
|
|
if(SDL2_NO_MWINDOWS)
|
|
|
|
list(REMOVE_ITEM _sdl2_libraries "-mwindows")
|
|
|
|
endif()
|
|
|
|
|
2022-06-04 01:57:21 +08:00
|
|
|
if(_sdl2_libraries MATCHES ".*SDL2main.*")
|
|
|
|
list(INSERT SDL2_LIBRARIES 0 SDL2::SDL2main)
|
|
|
|
list(INSERT SDL2_STATIC_LIBRARIES 0 SDL2::SDL2main)
|
2022-08-24 10:14:52 +08:00
|
|
|
endif()
|
|
|
|
|
2023-02-02 02:05:44 +08:00
|
|
|
set(_sdl2main_library ${SDL2_LIBDIR}/libSDL2main.a)
|
2022-08-24 10:14:52 +08:00
|
|
|
if(EXISTS "${_sdl2main_library}")
|
|
|
|
set(SDL2MAIN_LIBRARY SDL2::SDL2main)
|
|
|
|
if(NOT TARGET SDL2::SDL2main)
|
|
|
|
add_library(SDL2::SDL2main STATIC IMPORTED)
|
|
|
|
set_target_properties(SDL2::SDL2main
|
|
|
|
PROPERTIES
|
|
|
|
IMPORTED_LOCATION "${_sdl2main_library}"
|
2023-03-01 11:33:43 +08:00
|
|
|
COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
|
|
|
|
INTERFACE_SDL_VERSION "SDL2"
|
2022-08-24 10:14:52 +08:00
|
|
|
)
|
|
|
|
if(WIN32)
|
|
|
|
# INTERFACE_LINK_OPTIONS needs CMake 3.13
|
|
|
|
cmake_minimum_required(VERSION 3.13)
|
|
|
|
# Mark WinMain/WinMain@16 as undefined, such that it will be withheld by the linker.
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
|
|
|
set_target_properties(SDL2::SDL2main
|
|
|
|
PROPERTIES
|
2022-09-27 09:15:04 +08:00
|
|
|
INTERFACE_LINK_OPTIONS "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=_WinMain@16>"
|
2022-08-24 10:14:52 +08:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
set_target_properties(SDL2::SDL2main
|
|
|
|
PROPERTIES
|
2022-09-27 09:15:04 +08:00
|
|
|
INTERFACE_LINK_OPTIONS "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=WinMain>"
|
2022-08-24 10:14:52 +08:00
|
|
|
)
|
2022-06-04 01:57:21 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
2021-04-21 12:34:46 +08:00
|
|
|
endif()
|
2022-08-24 10:14:52 +08:00
|
|
|
set(SDL2_SDL2main_FOUND TRUE)
|
|
|
|
else()
|
|
|
|
set(SDL2_SDL2main_FOUND FALSE)
|
2022-06-04 01:57:21 +08:00
|
|
|
endif()
|
2022-08-24 10:14:52 +08:00
|
|
|
unset(_sdl2main_library)
|
2021-04-21 12:34:46 +08:00
|
|
|
|
2022-06-04 01:57:21 +08:00
|
|
|
# Remove SDL2 since this is the "central" library
|
|
|
|
# Remove SDL2main since this will be provided by SDL2::SDL2main (if available)
|
|
|
|
# Remove mingw32 and cygwin since these are not needed when using `-Wl,--undefined,WinMain`
|
|
|
|
set(_sdl2_link_libraries ${_sdl2_libraries})
|
|
|
|
list(REMOVE_ITEM _sdl2_link_libraries SDL2 SDL2main mingw32 cygwin)
|
2021-04-21 12:34:46 +08:00
|
|
|
|
2022-06-04 01:57:21 +08:00
|
|
|
if(WIN32)
|
2023-02-02 02:05:44 +08:00
|
|
|
set(_sdl2_implib "${SDL2_LIBDIR}/libSDL2.dll.a")
|
|
|
|
set(_sdl2_dll "${SDL2_BINDIR}/SDL2.dll")
|
2022-06-04 01:57:21 +08:00
|
|
|
if(EXISTS "${_sdl2_implib}" AND EXISTS "${_sdl2_dll}")
|
|
|
|
if(NOT TARGET SDL2::SDL2)
|
|
|
|
add_library(SDL2::SDL2 SHARED IMPORTED)
|
|
|
|
set_target_properties(SDL2::SDL2 PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
|
|
|
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries}"
|
2022-08-21 10:03:32 +08:00
|
|
|
INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
|
2022-06-04 01:57:21 +08:00
|
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
|
|
IMPORTED_IMPLIB "${_sdl2_implib}"
|
|
|
|
IMPORTED_LOCATION "${_sdl2_dll}"
|
2023-03-01 11:33:43 +08:00
|
|
|
COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
|
|
|
|
INTERFACE_SDL_VERSION "SDL2"
|
2022-06-04 01:57:21 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set(SDL2_SDL2_FOUND TRUE)
|
|
|
|
else()
|
|
|
|
set(SDL2_SDL2_FOUND FALSE)
|
|
|
|
endif()
|
|
|
|
unset(_sdl2_implib)
|
|
|
|
unset(_sdl2_dll)
|
|
|
|
else()
|
2023-02-02 02:05:44 +08:00
|
|
|
set(_sdl2_shared "${SDL2_LIBDIR}/libSDL2${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
2022-06-04 01:57:21 +08:00
|
|
|
if(EXISTS "${_sdl2_shared}")
|
|
|
|
if(NOT TARGET SDL2::SDL2)
|
|
|
|
add_library(SDL2::SDL2 SHARED IMPORTED)
|
|
|
|
set_target_properties(SDL2::SDL2 PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
|
|
|
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries}"
|
2022-08-21 10:03:32 +08:00
|
|
|
INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
|
2022-06-04 01:57:21 +08:00
|
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
|
|
IMPORTED_LOCATION "${_sdl2_shared}"
|
2023-03-01 11:33:43 +08:00
|
|
|
COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
|
|
|
|
INTERFACE_SDL_VERSION "SDL2"
|
2022-06-04 01:57:21 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set(SDL2_SDL2_FOUND TRUE)
|
|
|
|
else()
|
|
|
|
set(SDL2_SDL2_FOUND FALSE)
|
|
|
|
endif()
|
|
|
|
unset(_sdl2_shared)
|
|
|
|
endif()
|
|
|
|
|
2023-02-02 02:05:44 +08:00
|
|
|
set(_sdl2_static "${SDL2_LIBDIR}/libSDL2.a")
|
2022-06-04 01:57:21 +08:00
|
|
|
if(EXISTS "${_sdl2_static}")
|
|
|
|
if(NOT TARGET SDL2::SDL2-static)
|
|
|
|
add_library(SDL2::SDL2-static STATIC IMPORTED)
|
|
|
|
set_target_properties(SDL2::SDL2-static
|
|
|
|
PROPERTIES
|
|
|
|
IMPORTED_LOCATION "${_sdl2_static}"
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
|
|
|
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries};${_sdl2_static_private_libs}"
|
2022-08-21 10:03:32 +08:00
|
|
|
INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs};${_sdl2_static_private_libdirs}"
|
2022-06-04 01:57:21 +08:00
|
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
2023-03-01 11:33:43 +08:00
|
|
|
COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
|
|
|
|
INTERFACE_SDL_VERSION "SDL2"
|
2022-06-04 01:57:21 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set(SDL2_SDL2-static_FOUND TRUE)
|
|
|
|
else()
|
|
|
|
set(SDL2_SDL2-static_FOUND FALSE)
|
|
|
|
endif()
|
|
|
|
unset(_sdl2_static)
|
|
|
|
|
|
|
|
unset(_sdl2_link_libraries)
|
|
|
|
|
2023-02-02 02:05:44 +08:00
|
|
|
set(_sdl2test_library "${SDL2_LIBDIR}/libSDL2_test.a")
|
2022-06-04 01:57:21 +08:00
|
|
|
if(EXISTS "${_sdl2test_library}")
|
|
|
|
if(NOT TARGET SDL2::SDL2test)
|
|
|
|
add_library(SDL2::SDL2test STATIC IMPORTED)
|
|
|
|
set_target_properties(SDL2::SDL2test
|
|
|
|
PROPERTIES
|
2022-09-06 03:53:50 +08:00
|
|
|
IMPORTED_LOCATION "${_sdl2test_library}"
|
2022-06-04 01:57:21 +08:00
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
|
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
2023-03-01 11:33:43 +08:00
|
|
|
COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
|
|
|
|
INTERFACE_SDL_VERSION "SDL2"
|
2022-06-04 01:57:21 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set(SDL2_SDL2test_FOUND TRUE)
|
|
|
|
else()
|
|
|
|
set(SDL2_SDL2test_FOUND FALSE)
|
|
|
|
endif()
|
|
|
|
unset(_sdl2test_library)
|
2020-02-22 04:52:35 +08:00
|
|
|
|
2022-06-04 01:57:21 +08:00
|
|
|
# Copied from `configure_package_config_file`
|
|
|
|
macro(check_required_components _NAME)
|
|
|
|
foreach(comp ${${_NAME}_FIND_COMPONENTS})
|
|
|
|
if(NOT ${_NAME}_${comp}_FOUND)
|
|
|
|
if(${_NAME}_FIND_REQUIRED_${comp})
|
|
|
|
set(${_NAME}_FOUND FALSE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
2020-02-22 04:52:35 +08:00
|
|
|
|
2022-06-04 01:57:21 +08:00
|
|
|
check_required_components(SDL2)
|
2022-06-15 10:29:14 +08:00
|
|
|
|
|
|
|
# Create SDL2::SDL2 alias for static-only builds
|
|
|
|
if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS "3.18")
|
|
|
|
# FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
|
|
|
|
add_library(SDL2::SDL2 INTERFACE IMPORTED)
|
|
|
|
set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_LINK_LIBRARIES "SDL2::SDL2-static")
|
|
|
|
else()
|
|
|
|
add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
|
|
|
|
endif()
|
|
|
|
endif()
|