You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.4 KiB

  1. # All sorts of things that we need cross project
  2. cmake_minimum_required(VERSION 2.8.0)
  3. add_definitions("-DRAYLIB_CMAKE=1")
  4. # Linking for OS X -framework options
  5. # Will do nothing on other OSes
  6. if(APPLE)
  7. find_library(OPENGL_LIBRARY OpenGL)
  8. find_library(COCOA_LIBRARY Cocoa)
  9. find_library(IOKIT_LIBRARY IOKit)
  10. find_library(COREFOUNDATION_LIBRARY CoreFoundation)
  11. find_library(COREVIDEO_LIBRARY CoreVideo)
  12. set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${COCOA_LIBRARY}
  13. ${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} ${COREVIDEO_LIBRARY})
  14. elseif(WIN32)
  15. # no pkg-config --static on Windows yet...
  16. else()
  17. if(USE_WAYLAND)
  18. set(_GLFW_WAYLAND 1)
  19. else()
  20. set(_GLFW_X11 1)
  21. endif()
  22. find_library(pthread NAMES pthread)
  23. find_package(OpenGL QUIET)
  24. if ("${OPENGL_LIBRARIES}" STREQUAL "")
  25. if(NOT USE_WAYLAND)
  26. # CFLAGS=-m32 cmake on Linux fails for some reason, so fallback to hardcoding
  27. set(LIBS_PRIVATE m pthread GL X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
  28. else()
  29. # CFLAGS=-m32 cmake on Linux fails for some reason, so fallback to hardcoding
  30. set(LIBS_PRIVATE m pthread GL wayland-client wayland-cursor wayland-egl)
  31. endif()
  32. else()
  33. if(NOT USE_WAYLAND)
  34. find_package(X11 REQUIRED X11)
  35. find_library(XRANDR_LIBRARY Xrandr)
  36. find_library(XI_LIBRARY Xi)
  37. find_library(XINERAMA_LIBRARY Xinerama)
  38. find_library(XXF86VM_LIBRARY Xxf86vm)
  39. find_library(XCURSOR_LIBRARY Xcursor)
  40. else()
  41. find_library(WAYLAND_CLIENT_LIBRARY wayland-client)
  42. find_library(WAYLAND_CURSOR_LIBRARY wayland-cursor)
  43. find_library(WAYLAND_EGL_LIBRARY wayland-egl)
  44. endif()
  45. include_directories(${OPENGL_INCLUDE_DIR})
  46. if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
  47. find_library(OSS_LIBRARY ossaudio)
  48. endif()
  49. if(NOT USE_WAYLAND)
  50. set(LIBS_PRIVATE m ${pthread} ${OPENGL_LIBRARIES} ${X11_LIBRARIES} ${XRANDR_LIBRARY} ${XINERAMA_LIBRARY} ${XI_LIBRARY} ${XXF86VM_LIBRARY} ${XCURSOR_LIBRARY} ${OSS_LIBRARY})
  51. else()
  52. set(LIBS_PRIVATE m ${pthread} ${OPENGL_LIBRARIES} ${WAYLAND_CLIENT_LIBRARY} ${WAYLAND_CURSOR_LIBRARY} ${WAYLAND_EGL_LIBRARY} ${OSS_LIBRARY})
  53. endif()
  54. endif()
  55. endif()
  56. if(USE_EXTERNAL_GLFW STREQUAL "ON")
  57. find_package(glfw3 3.2.1 REQUIRED)
  58. elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE")
  59. find_package(glfw3 3.2.1 QUIET)
  60. endif()
  61. if (glfw3_FOUND)
  62. set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw)
  63. endif()
  64. if(CMAKE_SYSTEM_NAME STREQUAL Linux)
  65. set(LINUX TRUE)
  66. set(LIBS_PRIVATE dl ${LIBS_PRIVATE})
  67. endif()
  68. foreach(L ${LIBS_PRIVATE})
  69. get_filename_component(DIR ${L} PATH)
  70. get_filename_component(LIBFILE ${L} NAME_WE)
  71. STRING(REGEX REPLACE "^lib" "" FILE ${LIBFILE})
  72. if (${L} MATCHES "[.]framework$")
  73. set(FILE_OPT "-framework ${FILE}")
  74. set(DIR_OPT "-F${DIR}")
  75. else()
  76. set(FILE_OPT "-l${FILE}")
  77. set(DIR_OPT "-L${DIR}")
  78. endif()
  79. if ("${DIR}" STREQUAL "" OR "${DIR}" STREQUAL "${LASTDIR}")
  80. set (DIR_OPT "")
  81. endif()
  82. set(LASTDIR ${DIR})
  83. set(__PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE} ${DIR_OPT} ${FILE_OPT})
  84. string (REPLACE ";" " " __PKG_CONFIG_LIBS_PRIVATE "${__PKG_CONFIG_LIBS_PRIVATE}")
  85. endforeach(L)
  86. # Do the linking for executables that are meant to link raylib
  87. function(link_libraries_to_executable executable)
  88. # Link raylib
  89. if (TARGET raylib_shared)
  90. target_link_libraries(${executable} raylib_shared)
  91. else()
  92. target_link_libraries(${executable} raylib ${__PKG_CONFIG_LIBS_PRIVATE})
  93. endif()
  94. endfunction()