CMake: Build glfw separately with CMake

Makes it easier to support Wayland later on.
This commit is contained in:
Ahmad Fatoum 2018-05-10 22:51:17 +02:00
parent 0df501be91
commit 0adb4b67de
No known key found for this signature in database
GPG Key ID: C3EAC3DE9321D59B
3 changed files with 39 additions and 57 deletions

View File

@ -25,11 +25,12 @@ before_install:
sudo apt-get install -y gcc-multilib sudo apt-get install -y gcc-multilib
libasound2-dev:$ARCH libasound2-dev:$ARCH
libxcursor-dev:$ARCH libxinerama-dev:$ARCH mesa-common-dev:$ARCH libxcursor-dev:$ARCH libxinerama-dev:$ARCH mesa-common-dev:$ARCH
libx11-dev:$ARCH libxrandr-dev:$ARCH libxi-dev:$ARCH libx11-dev:$ARCH libxrandr-dev:$ARCH libxrandr2:$ARCH libxi-dev:$ARCH
libgl1-mesa-dev:$ARCH libglu1-mesa-dev:$ARCH; libgl1-mesa-dev:$ARCH libglu1-mesa-dev:$ARCH;
if [ "$ARCH" == "i386" ]; then
export CMAKE_ARCH_ARGS='-DCMAKE_C_FLAGS=-m32 -DCMAKE_SYSTEM_LIBRARY_PATH=/usr/lib/i386-linux-gnu';
fi;
export RAYLIB_PACKAGE_SUFFIX="-Linux-$ARCH"; export RAYLIB_PACKAGE_SUFFIX="-Linux-$ARCH";
if [ "$ARCH" == "i386" ]; then export CFLAGS="-m32"; fi;
if [ "$ARCH" == "amd64" ]; then export CFLAGS="-m64"; fi;
if [ "$GLFW" == "SYSTEM" ]; then if [ "$GLFW" == "SYSTEM" ]; then
wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3_3.2.1-1_amd64.deb'; wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3_3.2.1-1_amd64.deb';
wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3-dev_3.2.1-1_amd64.deb'; wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3-dev_3.2.1-1_amd64.deb';
@ -45,7 +46,7 @@ before_install:
script: script:
- mkdir build - mkdir build
- cd build - cd build
- cmake -DMACOS_FATLIB=ON -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON -DUSE_EXTERNAL_GLFW=IF_POSSIBLE .. - cmake $CMAKE_ARCH_ARGS -DMACOS_FATLIB=ON -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON -DUSE_EXTERNAL_GLFW=IF_POSSIBLE ..
- make VERBOSE=1 - make VERBOSE=1
- make package - make package

36
src/CMakeLists.txt Normal file → Executable file
View File

@ -10,16 +10,28 @@ include("CMakeOptions.txt")
configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h) configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h)
include_directories(${CMAKE_BINARY_DIR}) include_directories(${CMAKE_BINARY_DIR})
if(MACOS_FATLIB)
if (CMAKE_OSX_ARCHITECTURES)
message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides -DMACOS_FATLIB=ON")
else()
SET(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
endif()
endif()
if(NOT glfw3_FOUND)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_USE_WAYLAND ${USE_WAYLAND} CACHE BOOL "" FORCE)
add_subdirectory(external/glfw)
endif()
include("../utils.cmake") include("../utils.cmake")
# Get the sources together # Get the sources together
file(GLOB raylib_sources *.c) file(GLOB raylib_sources *.c)
list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/rglfw.c)
if(glfw3_FOUND)
list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/rglfw.c)
else()
include_directories(external/glfw/include)
endif()
if(USE_AUDIO) if(USE_AUDIO)
file(GLOB stb_vorbis external/stb_vorbis.c) file(GLOB stb_vorbis external/stb_vorbis.c)
@ -51,7 +63,6 @@ if(${PLATFORM} MATCHES "Desktop")
# See: https://github.com/raysan5/raylib/issues/341 # See: https://github.com/raysan5/raylib/issues/341
if(APPLE) if(APPLE)
set(GRAPHICS "GRAPHICS_API_OPENGL_33") set(GRAPHICS "GRAPHICS_API_OPENGL_33")
set_source_files_properties(rglfw.c PROPERTIES COMPILE_FLAGS "-x objective-c")
link_libraries("${LIBS_PRIVATE}") link_libraries("${LIBS_PRIVATE}")
elseif(WIN32) elseif(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
@ -76,14 +87,6 @@ elseif(${PLATFORM} MATCHES "Raspberry Pi")
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
endif() endif()
if(MACOS_FATLIB)
if (CMAKE_OSX_ARCHITECTURES)
message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides -DMACOS_FATLIB=ON")
else()
SET(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
endif()
endif()
# Which platform? # Which platform?
if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
@ -100,7 +103,7 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_MACOSX_RPATH ON) set(CMAKE_MACOSX_RPATH ON)
target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE}) target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE} glfw)
if (UNIX AND ${FILESYSTEM_LACKS_SYMLINKS}) if (UNIX AND ${FILESYSTEM_LACKS_SYMLINKS})
MESSAGE(WARNING "Can't version UNIX shared library on file system without symlink support") MESSAGE(WARNING "Can't version UNIX shared library on file system without symlink support")
else() else()
@ -137,6 +140,7 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
) )
set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE}) set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE})
target_link_libraries(${RAYLIB} glfw)
if (WITH_PIC) if (WITH_PIC)
set_property(TARGET ${RAYLIB} PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET ${RAYLIB} PROPERTY POSITION_INDEPENDENT_CODE ON)

51
utils.cmake Normal file → Executable file
View File

@ -17,47 +17,24 @@ if(APPLE)
elseif(WIN32) elseif(WIN32)
# no pkg-config --static on Windows yet... # no pkg-config --static on Windows yet...
else() else()
if(USE_WAYLAND)
set(_GLFW_WAYLAND 1)
else()
set(_GLFW_X11 1)
endif()
find_library(pthread NAMES pthread) find_library(pthread NAMES pthread)
find_package(OpenGL QUIET) find_package(OpenGL QUIET)
if ("${OPENGL_LIBRARIES}" STREQUAL "") if ("${OPENGL_LIBRARIES}" STREQUAL "")
if(NOT USE_WAYLAND) set(OPENGL_LIBRARIES "GL")
# CFLAGS=-m32 cmake on Linux fails for some reason, so fallback to hardcoding endif()
set(LIBS_PRIVATE m pthread GL X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
else() include_directories(${OPENGL_INCLUDE_DIR})
# 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) if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
endif() 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() else()
if(NOT USE_WAYLAND) set(LIBS_PRIVATE ${LIBS_PRIVATE} X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
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()
endif() endif()
endif() endif()