CMake: Search dependencies and build pkg-config's Libs.private with it

This commit is contained in:
Ahmad Fatoum 2018-01-26 23:44:01 +01:00
parent 1093766669
commit 7f7aac643a
No known key found for this signature in database
GPG key ID: C3EAC3DE9321D59B
2 changed files with 43 additions and 43 deletions

View file

@ -90,25 +90,28 @@ set(sources ${raylib_sources} ${mini_al})
# Which platform? # Which platform?
if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
if(LINUX)
foreach(L ${LIBS_PRIVATE}) foreach(L ${LIBS_PRIVATE})
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -l${L}") get_filename_component(DIR ${L} PATH)
endforeach(L) get_filename_component(LIBFILE ${L} NAME_WE)
STRING(REGEX REPLACE "^lib" "" FILE ${LIBFILE})
if (${L} MATCHES "[.]framework$")
set(FILE_OPT "-framework ${FILE}")
set(DIR_OPT "-F${DIR} ")
else()
set(FILE_OPT "-l${FILE}")
set(DIR_OPT "-L${DIR} ")
endif() endif()
if(APPLE) if ("${DIR}" STREQUAL "" OR "${DIR}" STREQUAL "${LASTDIR}")
# TODO extract framework location and name from ${LIBS_PRIVATE} set (DIR_OPT "")
# and specify them as -F and -framework instead of hardcoding
foreach(F OpenGL Cocoa)
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -framework ${F}")
endforeach(F)
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) set(LASTDIR ${DIR})
foreach(L ${LIBS_PRIVATE})
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -l${L}") set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} ${DIR_OPT}${FILE_OPT}")
endforeach(L) endforeach(L)
endif()
if(${SHARED_RAYLIB}) if(${SHARED_RAYLIB})
add_library(${RAYLIB}_shared SHARED ${sources}) add_library(${RAYLIB}_shared SHARED ${sources})

View file

@ -1,9 +1,5 @@
# All sorts of things that we need cross project # All sorts of things that we need cross project
cmake_minimum_required(VERSION 2.8.0) cmake_minimum_required(VERSION 2.8.)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LINUX TRUE)
endif()
# Linking for OS X -framework options # Linking for OS X -framework options
# Will do nothing on other OSes # Will do nothing on other OSes
@ -16,32 +12,33 @@ if(APPLE)
set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${COCOA_LIBRARY} set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${COCOA_LIBRARY}
${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} ${COREVIDEO_LIBRARY}) ${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} ${COREVIDEO_LIBRARY})
elseif(WIN32)
# no pkg-config --static on Windows yet...
else()
find_library(pthread NAMES pthread)
find_package(OpenGL)
if ("${OPENGL_LIBRARIES}" STREQUAL "")
# 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()
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)
include_directories(${OPENGL_INCLUDE_DIR})
set(LIBS_PRIVATE m ${pthread} ${OPENGL_LIBRARIES} ${X11_LIBRARIES} ${XRANDR_LIBRARY} ${XINERAMA_LIBRARY} ${XI_LIBRARY} ${XXF86VM_LIBRARY} ${XCURSOR_LIBRARY})
endif()
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL Linux) if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LIBS_PRIVATE set(LINUX TRUE)
m pthread dl set(LIBS_PRIVATE dl ${LIBS_PRIVATE})
GL
X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
find_package(X11 REQUIRED)
find_library(pthread NAMES pthread)
find_library(Xrandr NAMES Xrandr)
find_library(Xi NAMES Xi)
find_library(Xinerama NAMES Xinerama)
find_library(Xxf86vm NAMES Xxf86vm)
find_library(Xcursor NAMES Xcursor)
set(LIBS_PRIVATE m ${pthread} ${X11_LIBRARIES} ${Xrandr} ${Xinerama} ${Xi} ${Xxf86vm} ${Xcursor})
endif()
# TODO Support Windows
# Do the linking for executables that are meant to link raylib # Do the linking for executables that are meant to link raylib
function(link_libraries_to_executable executable) function(link_libraries_to_executable executable)
# And raylib # And raylib