Generate and install pkg-config pc file
After installation, compiling new programs is possible with $ cc game.c `pkg-config --static --libs --cflags raylib` or $ cc game.c `pkg-config --libs --cflags raylib` depending on configuration Also adds following configuration options: - WITH_PIC "Compile static library as position-independent code" - STATIC_RAYLIB "Build raylib as a static library" - MACOS_FATLIB "Build fat library for both i386 and x86_64 on macOS"
This commit is contained in:
parent
589cec0dd5
commit
44376c04fa
@ -13,9 +13,9 @@ env:
|
|||||||
global:
|
global:
|
||||||
- VERBOSE=1
|
- VERBOSE=1
|
||||||
matrix:
|
matrix:
|
||||||
- CFLAGS=-m64
|
- CFLAGS=-m64 SHARED=ON
|
||||||
- CFLAGS=-m32
|
- CFLAGS=-m32 SHARED=OFF
|
||||||
|
# We don't install x11 32-bit libraries, so skip shared libraries on -m32
|
||||||
before_script:
|
before_script:
|
||||||
- export CFLAGS="-std=gnu99 $CFLAGS"
|
- export CFLAGS="-std=gnu99 $CFLAGS"
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ before_install:
|
|||||||
script:
|
script:
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- cmake -DBUILD_EXAMPLES=OFF -DBUILD_GAMES=OFF ..
|
- cmake -DSTATIC_RAYLIB=ON -DSHARED_RAYLIB=$SHARED -DBUILD_EXAMPLES=OFF -DBUILD_GAMES=OFF ..
|
||||||
- make
|
- make
|
||||||
# - make package
|
# - make package
|
||||||
# - sudo make install
|
# - sudo make install
|
||||||
|
@ -37,7 +37,7 @@ before_build:
|
|||||||
- cd build
|
- cd build
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- cmake -G %GENERATOR% -DBUILD_EXAMPLES=OFF -DBUILD_GAMES=OFF ..
|
- cmake -G %GENERATOR% -DSTATIC_RAYLIB=ON -DSHARED_RAYLIB=OFF -DBUILD_EXAMPLES=OFF -DBUILD_GAMES=OFF ..
|
||||||
- cmake --build . --target install
|
- cmake --build . --target install
|
||||||
|
|
||||||
after_build:
|
after_build:
|
||||||
|
13
raylib.pc.in
Normal file
13
raylib.pc.in
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${exec_prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
Name: raylib
|
||||||
|
Description: Simple and easy-to-use library to learn videogames programming
|
||||||
|
URL: https://github.com/raysan5/raylib
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
Libs: -L${libdir} -lraylib
|
||||||
|
Libs.private:@PKG_CONFIG_LIBS_PRIVATE@
|
||||||
|
Requires.private:
|
||||||
|
Cflags: -I${includedir}
|
@ -8,8 +8,17 @@ set(RAYLIB raylib) # Name of the generated library
|
|||||||
|
|
||||||
|
|
||||||
### Config options ###
|
### Config options ###
|
||||||
# Build a static or shared raylib?
|
# Shared library is always PIC. Static library should be PIC too if linked into a shared library
|
||||||
|
set(WITH_PIC OFF CACHE BOOL "Compile static library as position-independent code" OFF)
|
||||||
|
# Build a static and/or shared raylib?
|
||||||
set(SHARED_RAYLIB OFF CACHE BOOL "Build raylib as a dynamic library")
|
set(SHARED_RAYLIB OFF CACHE BOOL "Build raylib as a dynamic library")
|
||||||
|
set(STATIC_RAYLIB ON CACHE BOOL "Build raylib as a static library")
|
||||||
|
set(MACOS_FATLIB ON CACHE BOOL "Build fat library for both i386 and x86_64 on macOS")
|
||||||
|
|
||||||
|
if(NOT (STATIC_RAYLIB OR SHARED_RAYLIB))
|
||||||
|
message(FATAL_ERROR "Nothing to do if both -DSHARED_RAYLIB=OFF and -DSTATIC_RAYLIB=OFF...")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Platform
|
# Platform
|
||||||
set(PLATFORM "Desktop" CACHE STRING "Platform to build for.")
|
set(PLATFORM "Desktop" CACHE STRING "Platform to build for.")
|
||||||
@ -66,6 +75,14 @@ elseif(${PLATFORM} MATCHES "Raspberry Pi")
|
|||||||
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
|
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_MACOS_FATLIB)
|
||||||
|
if (CMAKE_OSX_ARCHITECTURES)
|
||||||
|
message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides BUILD_MACOS_FATLIB=ON")
|
||||||
|
else()
|
||||||
|
SET(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Get the sources together
|
# Get the sources together
|
||||||
file(GLOB raylib_sources *.c)
|
file(GLOB raylib_sources *.c)
|
||||||
file(GLOB stb_vorbis external/stb_vorbis.c)
|
file(GLOB stb_vorbis external/stb_vorbis.c)
|
||||||
@ -73,40 +90,72 @@ set(sources ${raylib_sources} ${stb_vorbis})
|
|||||||
|
|
||||||
# Which platform?
|
# Which platform?
|
||||||
if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
|
if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
|
||||||
# Build a static or shared raylib?
|
|
||||||
# TODO clean this up a bit?
|
if(LINUX)
|
||||||
|
foreach(L ${LIBS_PRIVATE})
|
||||||
|
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -l${L}")
|
||||||
|
endforeach(L)
|
||||||
|
|
||||||
|
elseif(APPLE)
|
||||||
|
# TODO extract framework location and name from ${LIBS_PRIVATE}
|
||||||
|
# and specify them as -F and -framework instead of hardcoding
|
||||||
|
foreach(F OpenGL OpenAL Cocoa)
|
||||||
|
set(PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE} -framework ${F}")
|
||||||
|
endforeach(F)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
if(${SHARED_RAYLIB})
|
if(${SHARED_RAYLIB})
|
||||||
# Shared library
|
add_library(${RAYLIB}_shared SHARED ${sources})
|
||||||
add_library(${RAYLIB} SHARED ${sources})
|
|
||||||
|
|
||||||
# Will link -framework (if on OS X)
|
target_compile_definitions(${RAYLIB}_shared
|
||||||
link_os_x_frameworks(raylib)
|
PUBLIC ${PLATFORM}
|
||||||
else()
|
PUBLIC ${GRAPHICS}
|
||||||
# Static library
|
)
|
||||||
add_library(${RAYLIB} STATIC ${sources})
|
|
||||||
|
|
||||||
if(LINUX)
|
set_property(TARGET ${RAYLIB}_shared PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
# On Linux, need to link a few extra things for static
|
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
|
||||||
target_link_libraries(${RAYLIB} m pthread dl)
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
target_link_libraries(${RAYLIB} X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
|
set(CMAKE_MACOSX_RPATH ON)
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Always need to link OpenAL and OpenGL
|
target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE})
|
||||||
if(LINUX)
|
set_target_properties(${RAYLIB}_shared PROPERTIES PUBLIC_HEADER "raylib.h")
|
||||||
# Elsewhere (such as Linux), need `-lopenal -lGL`
|
if(WIN32)
|
||||||
target_link_libraries(${RAYLIB} openal)
|
|
||||||
target_link_libraries(${RAYLIB} GL)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Library file & Header
|
|
||||||
set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h")
|
|
||||||
install(
|
install(
|
||||||
TARGETS ${RAYLIB}
|
TARGETS ${RAYLIB}_shared
|
||||||
ARCHIVE DESTINATION lib
|
RUNTIME DESTINATION lib
|
||||||
|
PUBLIC_HEADER DESTINATION include
|
||||||
|
)
|
||||||
|
else() # Keep lib*.(a|dll) name, but avoid *.lib files overwriting each other on Windows
|
||||||
|
set_target_properties(${RAYLIB}_shared PROPERTIES OUTPUT_NAME ${RAYLIB})
|
||||||
|
install(
|
||||||
|
TARGETS ${RAYLIB}_shared
|
||||||
LIBRARY DESTINATION lib
|
LIBRARY DESTINATION lib
|
||||||
PUBLIC_HEADER DESTINATION include
|
PUBLIC_HEADER DESTINATION include
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
endif(${SHARED_RAYLIB})
|
||||||
|
|
||||||
|
if(${STATIC_RAYLIB})
|
||||||
|
add_library(${RAYLIB} STATIC ${sources})
|
||||||
|
|
||||||
|
target_compile_definitions(${RAYLIB}
|
||||||
|
PUBLIC ${PLATFORM}
|
||||||
|
PUBLIC ${GRAPHICS}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (WITH_PIC)
|
||||||
|
set_property(TARGET ${RAYLIB} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
endif()
|
||||||
|
set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h")
|
||||||
|
install(TARGETS ${RAYLIB}
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
PUBLIC_HEADER DESTINATION include
|
||||||
|
)
|
||||||
|
endif(${STATIC_RAYLIB})
|
||||||
|
|
||||||
|
configure_file(../raylib.pc.in raylib.pc @ONLY)
|
||||||
|
install(FILES ${CMAKE_BINARY_DIR}/release/raylib.pc DESTINATION lib/pkgconfig)
|
||||||
|
|
||||||
# Copy the header files to the build directory
|
# Copy the header files to the build directory
|
||||||
file(COPY "raylib.h" DESTINATION ".")
|
file(COPY "raylib.h" DESTINATION ".")
|
||||||
@ -119,15 +168,6 @@ elseif(${PLATFORM} MATCHES "PLATFORM_WEB")
|
|||||||
add_executable(${RAYLIB} ${sources})
|
add_executable(${RAYLIB} ${sources})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Set the compile flags to raylib
|
|
||||||
target_compile_definitions(${RAYLIB}
|
|
||||||
PUBLIC ${PLATFORM}
|
|
||||||
PUBLIC ${GRAPHICS}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Print the flags for the user
|
# Print the flags for the user
|
||||||
message(STATUS "Compiling with the flags:")
|
message(STATUS "Compiling with the flags:")
|
||||||
message(STATUS " PLATFORM=" ${PLATFORM})
|
message(STATUS " PLATFORM=" ${PLATFORM})
|
||||||
|
30
utils.cmake
30
utils.cmake
@ -1,5 +1,5 @@
|
|||||||
# All sorts of things that we need cross project
|
# All sorts of things that we need cross project
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 2.8.0)
|
||||||
|
|
||||||
# Detect linux
|
# Detect linux
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
@ -8,33 +8,27 @@ 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
|
||||||
function(link_os_x_frameworks binary)
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
find_library(OPENGL_LIBRARY OpenGL)
|
find_library(OPENGL_LIBRARY OpenGL)
|
||||||
find_library(OPENAL_LIBRARY OpenAL)
|
find_library(OPENAL_LIBRARY OpenAL)
|
||||||
find_library(COCOA_LIBRARY Cocoa)
|
find_library(COCOA_LIBRARY Cocoa)
|
||||||
|
|
||||||
set(OSX_FRAMEWORKS ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} ${COCOA_LIBRARY})
|
set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} ${COCOA_LIBRARY})
|
||||||
target_link_libraries(${binary} ${OSX_FRAMEWORKS})
|
elseif(LINUX)
|
||||||
|
# Elsewhere (such as Linux), need `-lopenal -lGL`, etc...
|
||||||
|
set(LIBS_PRIVATE
|
||||||
|
m pthread dl
|
||||||
|
openal
|
||||||
|
GL
|
||||||
|
X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
|
||||||
|
else()
|
||||||
|
# TODO Windows
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
|
||||||
|
|
||||||
|
|
||||||
# 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)
|
||||||
# Link the libraries
|
# Link the libraries
|
||||||
if(APPLE)
|
target_link_libraries(${executable} ${LIBS_PRIVATE})
|
||||||
# OS X, we use frameworks
|
|
||||||
link_os_x_frameworks(${executable})
|
|
||||||
elseif(LINUX)
|
|
||||||
# Elsewhere (such as Linux), need `-lopenal -lGL`, etc...
|
|
||||||
target_link_libraries(${executable} m pthread dl)
|
|
||||||
target_link_libraries(${executable} openal)
|
|
||||||
target_link_libraries(${executable} GL)
|
|
||||||
target_link_libraries(${executable} X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
|
|
||||||
else()
|
|
||||||
# TODO windows
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# And raylib
|
# And raylib
|
||||||
target_link_libraries(${executable} raylib)
|
target_link_libraries(${executable} raylib)
|
||||||
|
Loading…
Reference in New Issue
Block a user