cmake: move platform detection to cmake/sdl/paltform.cmake for re-use by SDL2-compat

This commit is contained in:
Anonymous Maarten 2022-11-29 17:48:45 +01:00
parent 69f0223474
commit 5df106603d
2 changed files with 57 additions and 50 deletions

View file

@ -74,6 +74,7 @@ find_package(PkgConfig)
list(APPEND CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
include(${SDL2_SOURCE_DIR}/cmake/sdlplatform.cmake)
include(${SDL2_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake)
# Enable large file support on 32-bit glibc, so that we can access files
@ -156,56 +157,7 @@ if(NOT LIBTYPE)
endif()
# Get the platform
if(WIN32)
if(NOT WINDOWS)
set(WINDOWS TRUE)
endif()
elseif(UNIX AND NOT APPLE)
if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
set(LINUX TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
set(FREEBSD TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
set(NETBSD TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
set(OPENBSD TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
set(GNU TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
set(BSDI TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
set(FREEBSD TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
set(SYSV5 TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*|SunOS.*")
set(SOLARIS TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
set(HPUX TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
set(AIX TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
set(MINIX TRUE)
endif()
elseif(APPLE)
if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
set(DARWIN TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
set(MACOSX TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
set(TVOS TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
# !!! FIXME: remove the version check when we start requiring >= 3.14.0
if(CMAKE_VERSION VERSION_LESS 3.14)
set(IOS TRUE)
endif()
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
message_error("BeOS support has been removed as of SDL 2.0.2.")
elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
set(HAIKU TRUE)
elseif(NINTENDO_3DS)
set(N3DS TRUE)
endif()
SDL_DetectCMakePlatform()
# Don't mistake osx for unix
if(UNIX AND NOT ANDROID AND NOT APPLE AND NOT RISCOS)

55
cmake/sdlplatform.cmake Normal file
View file

@ -0,0 +1,55 @@
macro(SDL_DetectCMakePlatform)
set(SDL_CMAKE_PLATFORM )
# Get the platform
if(WIN32)
set(SDL_CMAKE_PLATFORM WINDOWS)
elseif(UNIX AND NOT APPLE)
if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
set(SDL_CMAKE_PLATFORM LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
set(SDL_CMAKE_PLATFORM FREEBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
set(SDL_CMAKE_PLATFORM NETBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
set(SDL_CMAKE_PLATFORM OPENBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
set(SDL_CMAKE_PLATFORM GNU)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
set(SDL_CMAKE_PLATFORM BSDI)
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
set(SDL_CMAKE_PLATFORM FREEBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
set(SDL_CMAKE_PLATFORM SYSV5)
elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*|SunOS.*")
set(SDL_CMAKE_PLATFORM SOLARIS)
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
set(SDL_CMAKE_PLATFORM HPUX)
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
set(SDL_CMAKE_PLATFORM AIX)
elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
set(SDL_CMAKE_PLATFORM MINIX)
endif()
elseif(APPLE)
if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
set(SDL_CMAKE_PLATFORM DARWIN)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
set(SDL_CMAKE_PLATFORM MACOSX)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
set(SDL_CMAKE_PLATFORM TVOS)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
# !!! FIXME: remove the version check when we start requiring >= 3.14.0
if(CMAKE_VERSION VERSION_LESS 3.14)
set(SDL_CMAKE_PLATFORM IOS)
endif()
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
message_error("BeOS support has been removed as of SDL 2.0.2.")
elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
set(SDL_CMAKE_PLATFORM HAIKU)
elseif(NINTENDO_3DS)
set(SDL_CMAKE_PLATFORM N3DS)
endif()
if(SDL_CMAKE_PLATFORM)
set(${SDL_CMAKE_PLATFORM} TRUE)
endif()
endmacro()