CMakeLists.txt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Define target name
  2. set (TARGET_NAME SDL)
  3. # Define source files
  4. file (GLOB C_FILES
  5. src/*.c src/atomic/*.c src/audio/*.c src/audio/disk/*.c src/audio/dummy/*.c src/cpuinfo/*.c src/events/*.c src/file/*.c
  6. src/haptic/*.c src/joystick/*.c src/libm/*.c src/power/*.c src/stdlib/*.c
  7. src/thread/*.c src/timer/*.c src/video/*.c src/video/dummy/*.c
  8. )
  9. if (WIN32)
  10. # New MinGW versions may evaluate whether to use A or W postfix on functions before SDL gets to define UNICODE on its own,
  11. # so make sure it is already defined
  12. if (MINGW)
  13. add_definitions (-DUNICODE=1)
  14. endif ()
  15. CHECK_INCLUDE_FILES (wbemcli.h HAVE_WBEMCLI_H)
  16. if (HAVE_WBEMCLI_H)
  17. add_definitions (-DSDL_JOYSTICK_DINPUT)
  18. add_definitions (-DSDL_HAPTIC_DINPUT)
  19. set (HAPTIC_DRIVER windows)
  20. else ()
  21. message (STATUS "Building SDL without DX joystick support due to missing wbemcli.h")
  22. message (STATUS "For MSVC, get it from Windows 7 SDK. For MinGW, get it from eg. Wine sources or from MinGW-w64")
  23. add_definitions (-DSDL_JOYSTICK_WINMM)
  24. add_definitions (-DSDL_HAPTIC_DUMMY)
  25. set (HAPTIC_DRIVER dummy)
  26. endif ()
  27. file (GLOB SYS_C_FILES
  28. src/audio/directsound/*.c src/haptic/${HAPTIC_DRIVER}/*.c src/joystick/windows/*.c src/core/windows/*.c src/loadso/windows/*.c
  29. src/power/windows/*.c src/thread/windows/*.c src/thread/generic/SDL_syscond.c src/timer/windows/*.c src/video/windows/*.c src/joystick/dummy/*.c
  30. src/filesystem/windows/*.c
  31. )
  32. elseif (IOS)
  33. file (GLOB SYS_C_FILES
  34. src/audio/coreaudio/*.c src/file/cocoa/*.m src/joystick/iphoneos/*.m src/loadso/dlopen/*.c src/power/uikit/*.m
  35. src/thread/pthread/*.c src/timer/unix/*.c src/video/uikit/*.m src/video/uikit/*.c src/haptic/dummy/*.c
  36. src/filesystem/cocoa/*.m
  37. )
  38. elseif (APPLE)
  39. file (GLOB SYS_C_FILES
  40. src/audio/coreaudio/*.c src/file/cocoa/*.m src/haptic/darwin/*.c src/joystick/darwin/*.c src/loadso/dlopen/*.c
  41. src/power/macosx/*.c src/thread/pthread/*.c src/timer/unix/*.c src/video/cocoa/*.m src/filesystem/cocoa/*.m
  42. )
  43. elseif (ANDROID)
  44. file (GLOB SYS_C_FILES
  45. src/audio/android/*.c src/core/android/*.c src/joystick/android/*.c src/loadso/dlopen/*.c src/power/android/*.c
  46. src/thread/pthread/*.c src/timer/unix/*.c src/video/android/*.c src/haptic/dummy/*.c src/filesystem/dummy/*.c
  47. )
  48. else ()
  49. # On Linux, make sure development libraries exist, and use their include file directories
  50. if (RASPI)
  51. file (GLOB VIDEO_DRIVER_C_FILES src/video/raspberry/*.c src/core/linux/*.c)
  52. else ()
  53. find_package (OpenGL REQUIRED)
  54. include_directories (${OpenGL_INCLUDE_DIRS})
  55. find_package (X11 REQUIRED)
  56. if (NOT X11_Xrandr_FOUND)
  57. message (FATAL_ERROR "Could not find XRandR (libxrandr-dev)")
  58. endif ()
  59. include_directories (${X11_INCLUDE_DIRS})
  60. if (NOT DEFINED HAVE_CONST_XEXT_ADDDISPLAY)
  61. message (STATUS "Following tests check whether X11 library installed in this system uses _Xconst in below functions")
  62. message (STATUS "A failed test result simply means the installed X11 library does not use _Xconst")
  63. message (STATUS "It is OK to proceed to build Urho3D regardless of the test result")
  64. endif ()
  65. include (CheckCSourceCompiles)
  66. set (CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
  67. check_c_source_compiles ("
  68. #include <X11/Xlib.h>
  69. #include <X11/Xproto.h>
  70. #include <X11/extensions/Xext.h>
  71. #include <X11/extensions/extutil.h>
  72. extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
  73. int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
  74. if (HAVE_CONST_XEXT_ADDDISPLAY)
  75. add_definitions (-DSDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY)
  76. endif ()
  77. check_c_source_compiles ("
  78. #include <X11/Xlibint.h>
  79. extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
  80. int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
  81. if (HAVE_CONST_XDATA32)
  82. add_definitions (-DSDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32)
  83. endif ()
  84. set (CMAKE_REQUIRED_LIBRARIES)
  85. file (GLOB VIDEO_DRIVER_C_FILES src/video/x11/*.c)
  86. endif ()
  87. find_package (ALSA REQUIRED)
  88. # todo: remove this fix when the minimum CMake version has been raised to higher than 2.8.7
  89. # There is a bug in older version of FindALSA.cmake module where it erroneously include 'alsa' directory component into the variable
  90. # For cross-compiling build to work correctly, this extra directory component must be removed
  91. if (ALSA_INCLUDE_DIRS MATCHES .*/alsa)
  92. get_filename_component (ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIRS} PATH)
  93. endif ()
  94. # end todo
  95. include_directories (${ALSA_INCLUDE_DIRS})
  96. file (GLOB SYS_C_FILES
  97. src/audio/alsa/*.c src/audio/dma/*.c src/audio/dsp/*.c src/haptic/linux/*.c src/joystick/linux/*.c src/loadso/dlopen/*.c
  98. src/power/linux/*.c src/thread/pthread/*.c src/timer/unix/*.c src/filesystem/unix/*.c
  99. )
  100. set (SYS_C_FILES ${SYS_C_FILES} ${VIDEO_DRIVER_C_FILES})
  101. endif ()
  102. file (GLOB H_FILES include/*.h)
  103. # Define source files
  104. set_source_files_properties (${C_FILES} PROPERTIES LANGUAGE C)
  105. set_source_files_properties (${SYS_C_FILES} PROPERTIES LANGUAGE C)
  106. set (SOURCE_FILES ${C_FILES} ${SYS_C_FILES} ${H_FILES})
  107. # Install dependency for SDL_android_main.c, D3D9GraphicsImpl.h, OGLGraphicsImpl.h, InputEvents.h, File.h, and Cursor.h
  108. install (DIRECTORY include/ DESTINATION ${DEST_INCLUDE_DIR}/SDL ${DEST_PERMISSIONS} FILES_MATCHING PATTERN *.h) # Note: the trailing slash is significant
  109. set (INSTALL_INCLUDE_DIRS ${INSTALL_INCLUDE_DIRS} SDL PARENT_SCOPE)
  110. install (FILES src/main/android/SDL_android_main.c DESTINATION ${DEST_INCLUDE_DIR})
  111. # Define dependency libs
  112. set (INCLUDE_DIRS_ONLY include)
  113. # Setup target
  114. setup_library ()