CMake: (Properly) build glfw separately with CMake

This reverts commit 2d6fb5c628,
and adds a fix for Alien::raylib's test failures.

The tests failed because the resulting static library didn't reexport
GLFW symbols. As a fix, we now have GLFW create a CMake "object library"
target that we can link with both the static and shared raylib.

This is arguably ugly... Proper fix would probably be a GLFW upstream
object library target.

Closes #536.
This commit is contained in:
Ahmad Fatoum
2018-05-12 15:39:13 +02:00
parent a09d6fd428
commit 0f1aaa474a
4 changed files with 63 additions and 71 deletions

51
utils.cmake Normal file → Executable file
View File

@ -17,47 +17,24 @@ if(APPLE)
elseif(WIN32)
# no pkg-config --static on Windows yet...
else()
if(USE_WAYLAND)
set(_GLFW_WAYLAND 1)
else()
set(_GLFW_X11 1)
endif()
find_library(pthread NAMES pthread)
find_package(OpenGL QUIET)
if ("${OPENGL_LIBRARIES}" STREQUAL "")
if(NOT USE_WAYLAND)
# CFLAGS=-m32 cmake on Linux fails for some reason, so fallback to hardcoding
set(LIBS_PRIVATE m pthread GL X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
else()
# CFLAGS=-m32 cmake on Linux fails for some reason, so fallback to hardcoding
set(LIBS_PRIVATE m pthread GL wayland-client wayland-cursor wayland-egl)
endif()
set(OPENGL_LIBRARIES "GL")
endif()
include_directories(${OPENGL_INCLUDE_DIR})
if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
find_library(OSS_LIBRARY ossaudio)
endif()
set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
# TODO: maybe read those out of glfw's cmake config?
if(USE_WAYLAND)
set(LIBS_PRIVATE ${LIBS_PRIVATE} wayland-client wayland-cursor wayland-egl)
else()
if(NOT USE_WAYLAND)
find_package(X11 REQUIRED X11)
find_library(XRANDR_LIBRARY Xrandr)
find_library(XI_LIBRARY Xi)
find_library(XINERAMA_LIBRARY Xinerama)
find_library(XXF86VM_LIBRARY Xxf86vm)
find_library(XCURSOR_LIBRARY Xcursor)
else()
find_library(WAYLAND_CLIENT_LIBRARY wayland-client)
find_library(WAYLAND_CURSOR_LIBRARY wayland-cursor)
find_library(WAYLAND_EGL_LIBRARY wayland-egl)
endif()
include_directories(${OPENGL_INCLUDE_DIR})
if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
find_library(OSS_LIBRARY ossaudio)
endif()
if(NOT USE_WAYLAND)
set(LIBS_PRIVATE m ${pthread} ${OPENGL_LIBRARIES} ${X11_LIBRARIES} ${XRANDR_LIBRARY} ${XINERAMA_LIBRARY} ${XI_LIBRARY} ${XXF86VM_LIBRARY} ${XCURSOR_LIBRARY} ${OSS_LIBRARY})
else()
set(LIBS_PRIVATE m ${pthread} ${OPENGL_LIBRARIES} ${WAYLAND_CLIENT_LIBRARY} ${WAYLAND_CURSOR_LIBRARY} ${WAYLAND_EGL_LIBRARY} ${OSS_LIBRARY})
endif()
set(LIBS_PRIVATE ${LIBS_PRIVATE} X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
endif()
endif()