diff --git a/CMakeLists.txt b/CMakeLists.txt index fa1864340..9a6406d5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ find_package(PkgConfig) list(APPEND CMAKE_MODULE_PATH "${SDL3_SOURCE_DIR}/cmake") include(${SDL3_SOURCE_DIR}/cmake/macros.cmake) include(${SDL3_SOURCE_DIR}/cmake/sdlchecks.cmake) +include(${SDL3_SOURCE_DIR}/cmake/sdlplatform.cmake) include(${SDL3_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake) # Enable large file support on 32-bit glibc, so that we can access files @@ -146,56 +147,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() set(SDL_CHECK_REQUIRED_INCLUDES "" CACHE STRING "Extra includes (for CMAKE_REQUIRED_INCLUDES)") set(SDL_CHECK_REQUIRED_LINK_OPTIONS "" CACHE STRING "Extra link options (for CMAKE_REQUIRED_LINK_OPTIONS)") diff --git a/cmake/sdlplatform.cmake b/cmake/sdlplatform.cmake new file mode 100644 index 000000000..f55ad313b --- /dev/null +++ b/cmake/sdlplatform.cmake @@ -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()