cmake: move platform detection to cmake/sdl/paltform.cmake for re-use by SDL2-compat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 75068d8..d484956 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/cmake/sdlplatform.cmake b/cmake/sdlplatform.cmake
new file mode 100644
index 0000000..f55ad31
--- /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()