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.

102 lines
3.0 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(${PLATFORM} MATCHES "Android")
  7. find_library(OPENGL_LIBRARY OpenGL)
  8. set(LIBS_PRIVATE m log android EGL GLESv2 OpenSLES atomic c)
  9. elseif(${PLATFORM} MATCHES "Web")
  10. elseif(APPLE)
  11. find_library(OPENGL_LIBRARY OpenGL)
  12. find_library(COCOA_LIBRARY Cocoa)
  13. find_library(IOKIT_LIBRARY IOKit)
  14. find_library(COREFOUNDATION_LIBRARY CoreFoundation)
  15. find_library(COREVIDEO_LIBRARY CoreVideo)
  16. set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${COCOA_LIBRARY}
  17. ${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} ${COREVIDEO_LIBRARY})
  18. elseif(WIN32)
  19. # no pkg-config --static on Windows yet...
  20. else()
  21. find_library(pthread NAMES pthread)
  22. find_package(OpenGL QUIET)
  23. if ("${OPENGL_LIBRARIES}" STREQUAL "")
  24. set(OPENGL_LIBRARIES "GL")
  25. endif()
  26. include_directories(${OPENGL_INCLUDE_DIR})
  27. if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
  28. find_library(OSS_LIBRARY ossaudio)
  29. endif()
  30. set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
  31. # TODO: maybe read those out of glfw's cmake config?
  32. if(USE_WAYLAND)
  33. set(LIBS_PRIVATE ${LIBS_PRIVATE} wayland-client wayland-cursor wayland-egl)
  34. else()
  35. set(LIBS_PRIVATE ${LIBS_PRIVATE} X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
  36. endif()
  37. endif()
  38. if(${PLATFORM} MATCHES "Desktop")
  39. if(USE_EXTERNAL_GLFW STREQUAL "ON")
  40. find_package(glfw3 3.2.1 REQUIRED)
  41. elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE")
  42. find_package(glfw3 3.2.1 QUIET)
  43. endif()
  44. if (glfw3_FOUND)
  45. set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw)
  46. endif()
  47. endif()
  48. # Ugly crutch. Temporary workaround for #551
  49. if("${CMAKE_SYSTEM_NAME}" MATCHES "(Free|Net|Open)BSD")
  50. link_directories("/usr/local/lib")
  51. endif()
  52. if(CMAKE_SYSTEM_NAME STREQUAL Linux)
  53. set(LINUX TRUE)
  54. set(LIBS_PRIVATE dl ${LIBS_PRIVATE})
  55. endif()
  56. foreach(L ${LIBS_PRIVATE})
  57. get_filename_component(DIR ${L} PATH)
  58. get_filename_component(LIBFILE ${L} NAME_WE)
  59. STRING(REGEX REPLACE "^lib" "" FILE ${LIBFILE})
  60. if (${L} MATCHES "[.]framework$")
  61. set(FILE_OPT "-framework ${FILE}")
  62. set(DIR_OPT "-F${DIR}")
  63. else()
  64. set(FILE_OPT "-l${FILE}")
  65. set(DIR_OPT "-L${DIR}")
  66. endif()
  67. if ("${DIR}" STREQUAL "" OR "${DIR}" STREQUAL "${LASTDIR}")
  68. set (DIR_OPT "")
  69. endif()
  70. set(LASTDIR ${DIR})
  71. set(__PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE} ${DIR_OPT} ${FILE_OPT})
  72. string (REPLACE ";" " " __PKG_CONFIG_LIBS_PRIVATE "${__PKG_CONFIG_LIBS_PRIVATE}")
  73. endforeach(L)
  74. # Do the linking for executables that are meant to link raylib
  75. function(link_libraries_to_executable executable)
  76. # Link raylib
  77. if (TARGET raylib_shared)
  78. target_link_libraries(${executable} raylib_shared)
  79. elseif(${PLATFORM} MATCHES "Web")
  80. target_link_libraries(${executable} ${__PKG_CONFIG_LIBS_PRIVATE})
  81. target_link_libraries(${executable} raylib)
  82. else()
  83. target_link_libraries(${executable} raylib ${__PKG_CONFIG_LIBS_PRIVATE})
  84. endif()
  85. endfunction()