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?
if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
if(LINUX)
foreach(L ${LIBS_PRIVATE})
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -l${L}")
endforeach(L)
endif()
foreach(L ${LIBS_PRIVATE})
get_filename_component(DIR ${L} PATH)
get_filename_component(LIBFILE ${L} NAME_WE)
STRING(REGEX REPLACE "^lib" "" FILE ${LIBFILE})
if(APPLE)
# TODO extract framework location and name from ${LIBS_PRIVATE}
# 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()
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()
if ("${DIR}" STREQUAL "" OR "${DIR}" STREQUAL "${LASTDIR}")
set (DIR_OPT "")
endif()
set(LASTDIR ${DIR})
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} ${DIR_OPT}${FILE_OPT}")
endforeach(L)
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
foreach(L ${LIBS_PRIVATE})
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -l${L}")
endforeach(L)
endif()
if(${SHARED_RAYLIB})
add_library(${RAYLIB}_shared SHARED ${sources})

View File

@ -1,9 +1,5 @@
# All sorts of things that we need cross project
cmake_minimum_required(VERSION 2.8.0)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LINUX TRUE)
endif()
cmake_minimum_required(VERSION 2.8.)
# Linking for OS X -framework options
# Will do nothing on other OSes
@ -16,32 +12,33 @@ if(APPLE)
set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${COCOA_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()
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LIBS_PRIVATE
m pthread dl
GL
X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
set(LINUX TRUE)
set(LIBS_PRIVATE dl ${LIBS_PRIVATE})
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
function(link_libraries_to_executable executable)
# And raylib