CMakeLists.txt
changeset 12932 800524378309
parent 12901 5cbf6472a916
child 12938 165d577cdc63
equal deleted inserted replaced
12931:881705583f45 12932:800524378309
   151     set(OPT_DEF_SSEMATH ON)
   151     set(OPT_DEF_SSEMATH ON)
   152   endif()
   152   endif()
   153 endif()
   153 endif()
   154 if(UNIX OR MINGW OR MSYS)
   154 if(UNIX OR MINGW OR MSYS)
   155   set(OPT_DEF_LIBC ON)
   155   set(OPT_DEF_LIBC ON)
       
   156 endif()
       
   157 
       
   158 # The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
       
   159 #  so we'll just use libusb when it's available. Except that libusb
       
   160 #  requires root permissions to open devices, so that's not generally
       
   161 #  useful, and we'll disable this by default on Unix. Windows and macOS
       
   162 #  can use it without root access, though, so enable by default there.
       
   163 if(WINDOWS OR APPLE OR ANDROID)
       
   164   set(HIDAPI_SKIP_LIBUSB TRUE)
       
   165 else()
       
   166   set(HIDAPI_SKIP_LIBUSB FALSE)
       
   167 endif()
       
   168 if (HIDAPI_SKIP_LIBUSB)
       
   169   set(OPT_DEF_HIDAPI ON)
   156 endif()
   170 endif()
   157 
   171 
   158 # Compiler info
   172 # Compiler info
   159 if(CMAKE_COMPILER_IS_GNUCC)
   173 if(CMAKE_COMPILER_IS_GNUCC)
   160   set(USE_GCC TRUE)
   174   set(USE_GCC TRUE)
   356 dep_option(VIDEO_VULKAN        "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
   370 dep_option(VIDEO_VULKAN        "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
   357 set_option(VIDEO_KMSDRM        "Use KMS DRM video driver" ${UNIX_SYS})
   371 set_option(VIDEO_KMSDRM        "Use KMS DRM video driver" ${UNIX_SYS})
   358 dep_option(KMSDRM_SHARED       "Dynamically load KMS DRM support" ON "VIDEO_KMSDRM" OFF)
   372 dep_option(KMSDRM_SHARED       "Dynamically load KMS DRM support" ON "VIDEO_KMSDRM" OFF)
   359 option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
   373 option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
   360 option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
   374 option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
       
   375 set_option(HIDAPI              "Use HIDAPI for low level joystick drivers" ${OPT_DEF_HIDAPI})
   361 
   376 
   362 set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
   377 set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
   363 set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
   378 set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
   364 
   379 
   365 dep_option(SDL_STATIC_PIC      "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
   380 dep_option(SDL_STATIC_PIC      "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
   826     set(HAVE_VIDEO_DUMMY TRUE)
   841     set(HAVE_VIDEO_DUMMY TRUE)
   827     set(HAVE_SDL_VIDEO TRUE)
   842     set(HAVE_SDL_VIDEO TRUE)
   828   endif()
   843   endif()
   829 endif()
   844 endif()
   830 
   845 
       
   846 # Platform-specific options and settings
   831 if(ANDROID)
   847 if(ANDROID)
   832   file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
   848   file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
   833   set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
   849   set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
   834 
   850 
   835   # SDL_spinlock.c Needs to be compiled in ARM mode.
   851   # SDL_spinlock.c Needs to be compiled in ARM mode.
   861     file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
   877     file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
   862     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_HAPTIC_SOURCES})
   878     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_HAPTIC_SOURCES})
   863     set(HAVE_SDL_HAPTIC TRUE)
   879     set(HAVE_SDL_HAPTIC TRUE)
   864   endif()
   880   endif()
   865   if(SDL_JOYSTICK)
   881   if(SDL_JOYSTICK)
       
   882     CheckHIDAPI()
   866     set(SDL_JOYSTICK_ANDROID 1)
   883     set(SDL_JOYSTICK_ANDROID 1)
   867     file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
   884     file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
   868     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
   885     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
   869     set(HAVE_SDL_JOYSTICK TRUE)
   886     set(HAVE_SDL_JOYSTICK TRUE)
   870   endif()
   887   endif()
   932       set(VIDEO_VULKAN OFF)
   949       set(VIDEO_VULKAN OFF)
   933       message(STATUS "Vulkan doesn't work on this configuration")
   950       message(STATUS "Vulkan doesn't work on this configuration")
   934     endif()
   951     endif()
   935   endif()
   952   endif()
   936 
   953 
   937   file(GLOB ANDROID_HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/hidapi/android/*.cpp)
       
   938 
       
   939   CheckPTHREAD()
   954   CheckPTHREAD()
   940 
   955 
   941 endif()
   956 elseif(EMSCRIPTEN)
   942 
       
   943 # Platform-specific options and settings
       
   944 if(EMSCRIPTEN)
       
   945   # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
   957   # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
   946   # project. Uncomment at will for verbose cross-compiling -I/../ path info.
   958   # project. Uncomment at will for verbose cross-compiling -I/../ path info.
   947   add_definitions(-Wno-warn-absolute-paths)
   959   add_definitions(-Wno-warn-absolute-paths)
   948   if(SDL_AUDIO)
   960   if(SDL_AUDIO)
   949     set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
   961     set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
   991       set(HAVE_VIDEO_OPENGLES TRUE)
  1003       set(HAVE_VIDEO_OPENGLES TRUE)
   992       set(SDL_VIDEO_OPENGL_ES2 1)
  1004       set(SDL_VIDEO_OPENGL_ES2 1)
   993       set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1005       set(SDL_VIDEO_RENDER_OGL_ES2 1)
   994     endif()
  1006     endif()
   995   endif()
  1007   endif()
       
  1008 
   996 elseif(UNIX AND NOT APPLE AND NOT ANDROID)
  1009 elseif(UNIX AND NOT APPLE AND NOT ANDROID)
   997   if(SDL_AUDIO)
  1010   if(SDL_AUDIO)
   998     if(SYSV5 OR SOLARIS OR HPUX)
  1011     if(SYSV5 OR SOLARIS OR HPUX)
   999         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
  1012         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
  1000         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
  1013         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
  1114     endif()
  1127     endif()
  1115   endif()
  1128   endif()
  1116 
  1129 
  1117   if(SDL_JOYSTICK)
  1130   if(SDL_JOYSTICK)
  1118     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
  1131     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
       
  1132     CheckHIDAPI()
  1119     if(LINUX AND NOT ANDROID)
  1133     if(LINUX AND NOT ANDROID)
  1120       set(SDL_JOYSTICK_LINUX 1)
  1134       set(SDL_JOYSTICK_LINUX 1)
  1121       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1135       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1122       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1136       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1123       set(HAVE_SDL_JOYSTICK TRUE)
  1137       set(HAVE_SDL_JOYSTICK TRUE)
  1357       set(HAVE_VIDEO_OPENGLES TRUE)
  1371       set(HAVE_VIDEO_OPENGLES TRUE)
  1358     endif()
  1372     endif()
  1359   endif()
  1373   endif()
  1360 
  1374 
  1361   if(SDL_JOYSTICK)
  1375   if(SDL_JOYSTICK)
       
  1376     CheckHIDAPI()
       
  1377     if(HAVE_HIDAPI)
       
  1378       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/windows/hid.c)
       
  1379     endif()
  1362     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1380     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1363     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1381     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1364     if(HAVE_DINPUT_H)
  1382     if(HAVE_DINPUT_H)
  1365       set(SDL_JOYSTICK_DINPUT 1)
  1383       set(SDL_JOYSTICK_DINPUT 1)
  1366       list(APPEND EXTRA_LIBS dinput8)
  1384       list(APPEND EXTRA_LIBS dinput8)
  1402     list(APPEND EXTRA_LIBS mingw32)
  1420     list(APPEND EXTRA_LIBS mingw32)
  1403     list(APPEND EXTRA_LDFLAGS "-mwindows")
  1421     list(APPEND EXTRA_LDFLAGS "-mwindows")
  1404     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
  1422     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
  1405     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
  1423     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
  1406   endif()
  1424   endif()
       
  1425 
  1407 elseif(APPLE)
  1426 elseif(APPLE)
  1408   # TODO: rework this all for proper MacOS X, iOS and Darwin support
  1427   # TODO: rework this all for proper MacOS X, iOS and Darwin support
  1409 
  1428 
  1410   # We always need these libs on macOS at the moment.
  1429   # We always need these libs on macOS at the moment.
  1411   # !!! FIXME: we need Carbon for some very old API calls in
  1430   # !!! FIXME: we need Carbon for some very old API calls in
  1439     set(SDL_FRAMEWORK_COREAUDIO 1)
  1458     set(SDL_FRAMEWORK_COREAUDIO 1)
  1440     set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  1459     set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  1441   endif()
  1460   endif()
  1442 
  1461 
  1443   if(SDL_JOYSTICK)
  1462   if(SDL_JOYSTICK)
       
  1463     CheckHIDAPI()
       
  1464     if(HAVE_HIDAPI)
       
  1465       if(IOS)
       
  1466         set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
       
  1467       else()
       
  1468         set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/mac/hid.c)
       
  1469       endif()
       
  1470     endif()
  1444     set(SDL_JOYSTICK_IOKIT 1)
  1471     set(SDL_JOYSTICK_IOKIT 1)
  1445     if (IOS)
  1472     if (IOS)
  1446       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1473       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
  1447     else()
  1474     else()
  1448       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  1475       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  1551       endif()
  1578       endif()
  1552     endif()
  1579     endif()
  1553   endif()
  1580   endif()
  1554 
  1581 
  1555   CheckPTHREAD()
  1582   CheckPTHREAD()
       
  1583 
  1556 elseif(HAIKU)
  1584 elseif(HAIKU)
  1557   if(SDL_VIDEO)
  1585   if(SDL_VIDEO)
  1558     set(SDL_VIDEO_DRIVER_HAIKU 1)
  1586     set(SDL_VIDEO_DRIVER_HAIKU 1)
  1559     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1587     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1560     set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1588     set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1797     set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
  1825     set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX ${SDL_CMAKE_DEBUG_POSTFIX})
  1798   endif()
  1826   endif()
  1799 endif()
  1827 endif()
  1800 
  1828 
  1801 if(ANDROID)
  1829 if(ANDROID)
  1802   add_library(hidapi SHARED ${ANDROID_HIDAPI_SOURCES})
  1830   if(HAVE_HIDAPI)
       
  1831     add_library(hidapi SHARED ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
       
  1832   endif()
       
  1833 
  1803   if(MSVC AND NOT LIBC)
  1834   if(MSVC AND NOT LIBC)
  1804     # Don't try to link with the default set of libraries.
  1835     # Don't try to link with the default set of libraries.
  1805     set_target_properties(hidapi PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1836     set_target_properties(hidapi PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1806     set_target_properties(hidapi PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1837     set_target_properties(hidapi PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1807     set_target_properties(hidapi PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1838     set_target_properties(hidapi PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")