mirror of
https://github.com/shadps4-emu/ext-SDL.git
synced 2024-12-11 04:24:21 +00:00
207 lines
7.7 KiB
CMake
207 lines
7.7 KiB
CMake
# sdl3 cmake project-config input for ./configure script
|
|
|
|
include(FeatureSummary)
|
|
set_package_properties(SDL3 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()
|
|
|
|
get_filename_component(prefix "${CMAKE_CURRENT_LIST_DIR}/@cmake_prefix_relpath@" ABSOLUTE)
|
|
|
|
set(exec_prefix "@exec_prefix@")
|
|
set(bindir "@bindir@")
|
|
set(libdir "@libdir@")
|
|
set(includedir "@includedir@")
|
|
|
|
set_and_check(SDL3_PREFIX "${prefix}")
|
|
set_and_check(SDL3_EXEC_PREFIX "${exec_prefix}")
|
|
set_and_check(SDL3_BINDIR "${bindir}")
|
|
set_and_check(SDL3_INCLUDE_DIR "${includedir}/SDL3")
|
|
set_and_check(SDL3_LIBDIR "${libdir}")
|
|
set(SDL3_INCLUDE_DIRS "${includedir};${SDL3_INCLUDE_DIR}")
|
|
|
|
set(SDL3_LIBRARIES SDL3::SDL3)
|
|
set(SDL3_STATIC_LIBRARIES SDL3::SDL3-static)
|
|
set(SDL3MAIN_LIBRARY)
|
|
set(SDL3TEST_LIBRARY SDL3::SDL3test)
|
|
|
|
unset(prefix)
|
|
unset(exec_prefix)
|
|
unset(bindir)
|
|
unset(libdir)
|
|
unset(includedir)
|
|
|
|
set(_sdl3_libraries_in "@SDL_LIBS@")
|
|
set(_sdl3_static_private_libs_in "@SDL_STATIC_LIBS@")
|
|
|
|
# Convert _sdl3_libraries to list and keep only libraries + library directories
|
|
string(REGEX MATCHALL "-[lm]([-a-zA-Z0-9._]+)" _sdl3_libraries "${_sdl3_libraries_in}")
|
|
string(REGEX REPLACE "^-l" "" _sdl3_libraries "${_sdl3_libraries}")
|
|
string(REGEX REPLACE ";-l" ";" _sdl3_libraries "${_sdl3_libraries}")
|
|
string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl3_libdirs "${_sdl3_libraries_in}")
|
|
string(REGEX REPLACE "^-L" "" _sdl3_libdirs "${_sdl3_libdirs}")
|
|
string(REGEX REPLACE ";-L" ";" _sdl3_libdirs "${_sdl3_libdirs}")
|
|
list(APPEND _sdl3_libdirs "${SDL3_LIBDIR}")
|
|
|
|
# Convert _sdl3_static_private_libs to list and keep only libraries + library directories
|
|
string(REGEX MATCHALL "(-[lm]([-a-zA-Z0-9._]+))|(-Wl,[^ ]*framework[^ ]*)|(-pthread)" _sdl3_static_private_libs "${_sdl3_static_private_libs_in}")
|
|
string(REGEX REPLACE "^-l" "" _sdl3_static_private_libs "${_sdl3_static_private_libs}")
|
|
string(REGEX REPLACE ";-l" ";" _sdl3_static_private_libs "${_sdl3_static_private_libs}")
|
|
string(REGEX MATCHALL "-L([-a-zA-Z0-9._/]+)" _sdl3_static_private_libdirs "${_sdl3_static_private_libs_in}")
|
|
string(REGEX REPLACE "^-L" "" _sdl3_static_private_libdirs "${_sdl3_static_private_libdirs}")
|
|
string(REGEX REPLACE ";-L" ";" _sdl3_static_private_libdirs "${_sdl3_static_private_libdirs}")
|
|
|
|
if(_sdl3_libraries MATCHES ".*SDL3main.*")
|
|
list(INSERT SDL3_LIBRARIES 0 SDL3::SDL3main)
|
|
list(INSERT SDL3_STATIC_LIBRARIES 0 SDL3::SDL3main)
|
|
endif()
|
|
|
|
set(_sdl3main_library ${SDL3_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL3main${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
if(EXISTS "${_sdl3main_library}")
|
|
set(SDL3MAIN_LIBRARY SDL3::SDL3main)
|
|
if(NOT TARGET SDL3::SDL3main)
|
|
add_library(SDL3::SDL3main STATIC IMPORTED)
|
|
set_target_properties(SDL3::SDL3main
|
|
PROPERTIES
|
|
IMPORTED_LOCATION "${_sdl3main_library}"
|
|
)
|
|
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(SDL3::SDL3main
|
|
PROPERTIES
|
|
INTERFACE_LINK_OPTIONS "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=_WinMain@16>"
|
|
)
|
|
else()
|
|
set_target_properties(SDL3::SDL3main
|
|
PROPERTIES
|
|
INTERFACE_LINK_OPTIONS "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=WinMain>"
|
|
)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
set(SDL3_SDL3main_FOUND TRUE)
|
|
else()
|
|
set(SDL3_SDL3main_FOUND FALSE)
|
|
endif()
|
|
unset(_sdl3main_library)
|
|
|
|
# Remove SDL3 since this is the "central" library
|
|
# Remove SDL3main since this will be provided by SDL3::SDL3main (if available)
|
|
# Remove mingw32 and cygwin since these are not needed when using `-Wl,--undefined,WinMain`
|
|
set(_sdl3_link_libraries ${_sdl3_libraries})
|
|
list(REMOVE_ITEM _sdl3_link_libraries SDL3 SDL3main mingw32 cygwin)
|
|
|
|
if(WIN32)
|
|
set(_sdl3_implib "${SDL3_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL3${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
|
set(_sdl3_dll "${SDL3_BINDIR}/SDL3${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
|
if(EXISTS "${_sdl3_implib}" AND EXISTS "${_sdl3_dll}")
|
|
if(NOT TARGET SDL3::SDL3)
|
|
add_library(SDL3::SDL3 SHARED IMPORTED)
|
|
set_target_properties(SDL3::SDL3 PROPERTIES
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}"
|
|
INTERFACE_LINK_LIBRARIES "${_sdl3_link_libraries}"
|
|
INTERFACE_LINK_DIRECTORIES "${_sdl3_libdirs}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
IMPORTED_IMPLIB "${_sdl3_implib}"
|
|
IMPORTED_LOCATION "${_sdl3_dll}"
|
|
)
|
|
endif()
|
|
set(SDL3_SDL3_FOUND TRUE)
|
|
else()
|
|
set(SDL3_SDL3_FOUND FALSE)
|
|
endif()
|
|
unset(_sdl3_implib)
|
|
unset(_sdl3_dll)
|
|
else()
|
|
set(_sdl3_shared "${SDL3_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}SDL3${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
|
if(EXISTS "${_sdl3_shared}")
|
|
if(NOT TARGET SDL3::SDL3)
|
|
add_library(SDL3::SDL3 SHARED IMPORTED)
|
|
set_target_properties(SDL3::SDL3 PROPERTIES
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}"
|
|
INTERFACE_LINK_LIBRARIES "${_sdl3_link_libraries}"
|
|
INTERFACE_LINK_DIRECTORIES "${_sdl3_libdirs}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
IMPORTED_LOCATION "${_sdl3_shared}"
|
|
)
|
|
endif()
|
|
set(SDL3_SDL3_FOUND TRUE)
|
|
else()
|
|
set(SDL3_SDL3_FOUND FALSE)
|
|
endif()
|
|
unset(_sdl3_shared)
|
|
endif()
|
|
|
|
set(_sdl3_static "${SDL3_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL3${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
|
if(EXISTS "${_sdl3_static}")
|
|
if(NOT TARGET SDL3::SDL3-static)
|
|
add_library(SDL3::SDL3-static STATIC IMPORTED)
|
|
set_target_properties(SDL3::SDL3-static
|
|
PROPERTIES
|
|
IMPORTED_LOCATION "${_sdl3_static}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}"
|
|
INTERFACE_LINK_LIBRARIES "${_sdl3_link_libraries};${_sdl3_static_private_libs}"
|
|
INTERFACE_LINK_DIRECTORIES "${_sdl3_libdirs};${_sdl3_static_private_libdirs}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
)
|
|
endif()
|
|
set(SDL3_SDL3-static_FOUND TRUE)
|
|
else()
|
|
set(SDL3_SDL3-static_FOUND FALSE)
|
|
endif()
|
|
unset(_sdl3_static)
|
|
|
|
unset(_sdl3_link_libraries)
|
|
|
|
set(_sdl3test_library "${SDL3_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}SDL3_test${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
|
if(EXISTS "${_sdl3test_library}")
|
|
if(NOT TARGET SDL3::SDL3test)
|
|
add_library(SDL3::SDL3test STATIC IMPORTED)
|
|
set_target_properties(SDL3::SDL3test
|
|
PROPERTIES
|
|
IMPORTED_LOCATION "${_sdl3test_library}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
)
|
|
endif()
|
|
set(SDL3_SDL3test_FOUND TRUE)
|
|
else()
|
|
set(SDL3_SDL3test_FOUND FALSE)
|
|
endif()
|
|
unset(_sdl3test_library)
|
|
|
|
# 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()
|
|
|
|
check_required_components(SDL3)
|
|
|
|
# Create SDL3::SDL3 alias for static-only builds
|
|
if(TARGET SDL3::SDL3-static AND NOT TARGET SDL3::SDL3)
|
|
if(CMAKE_VERSION VERSION_LESS "3.18")
|
|
# FIXME: Aliasing local targets is not supported on CMake < 3.18, so make it global.
|
|
add_library(SDL3::SDL3 INTERFACE IMPORTED)
|
|
set_target_properties(SDL3::SDL3 PROPERTIES INTERFACE_LINK_LIBRARIES "SDL3::SDL3-static")
|
|
else()
|
|
add_library(SDL3::SDL3 ALIAS SDL3::SDL3-static)
|
|
endif()
|
|
endif()
|