Skip to content

Commit

Permalink
Add pkg-config files, optionally installed by CMake on Linux builds
Browse files Browse the repository at this point in the history
The modules provided are:

  - csfml-system
  - csfml-graphics
  - csfml-window
  - csfml-audio
  - csfml-network
  - csfml-all (depends on all the above modules)

They are installed to the standard location for pkg-config files on Linux.

This is adapted from SFML own pkg-config files.
  • Loading branch information
tintou authored and eXpl0it3r committed Jun 27, 2023
1 parent a05be24 commit 6476e94
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ if(CSFML_BUILD_DOC)
add_subdirectory(doc)
endif()

# on Linux and BSD-like OS, install pkg-config files by default
set(CSFML_INSTALL_PKGCONFIG_DEFAULT FALSE)

if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
set(CSFML_INSTALL_PKGCONFIG_DEFAULT TRUE)
endif()

csfml_set_option(CSFML_INSTALL_PKGCONFIG_FILES ${CSFML_INSTALL_PKGCONFIG_DEFAULT} BOOL "TRUE to automatically install pkg-config files so other projects can find SFML")

if(CSFML_INSTALL_PKGCONFIG_FILES)
csfml_set_option(CSFML_PKGCONFIG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/${CSFML_PKGCONFIG_DIR}" PATH "Install directory for CSFML's pkg-config .pc files")

foreach(csfml_module IN ITEMS all system window graphics audio network)
configure_file(
"tools/pkg-config/csfml-${csfml_module}.pc.in"
"tools/pkg-config/csfml-${csfml_module}.pc"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/csfml-${csfml_module}.pc"
DESTINATION "${CSFML_PKGCONFIG_INSTALL_PREFIX}")
endforeach()
endif()

# setup the install rules
install(DIRECTORY include
DESTINATION .
Expand Down
8 changes: 8 additions & 0 deletions cmake/Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ else()
return()
endif()

# set pkgconfig install directory
# this could be e.g. macports on mac or msys2 on windows etc.
set(CSFML_PKGCONFIG_DIR "/${CMAKE_INSTALL_LIBDIR}/pkgconfig")

if(SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
set(CSFML_PKGCONFIG_DIR "/libdata/pkgconfig")
endif()

# detect the compiler and its version
# Note: The detection is order is important because:
# - Visual Studio can both use MSVC and Clang
Expand Down
10 changes: 10 additions & 0 deletions tools/pkg-config/csfml-all.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include

Name: CSFML-all
Description: The Simple and Fast Multimedia Library for C, all modules.
URL: https://www.sfml-dev.org
Version: @PROJECT_VERSION@
Requires: csfml-system, csfml-window, csfml-graphics, csfml-audio, csfml-network
13 changes: 13 additions & 0 deletions tools/pkg-config/csfml-audio.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include

Name: CSFML-audio
Description: The Simple and Fast Multimedia Library for C, audio module.
URL: https://www.sfml-dev.org
Version: @PROJECT_VERSION@
Requires: csfml-system
Requires.private: sfml-audio
Libs: -L${libdir} -lcsfml-audio
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions tools/pkg-config/csfml-graphics.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include

Name: CSFML-graphics
Description: The Simple and Fast Multimedia Library for C, graphics module.
URL: https://www.sfml-dev.org
Version: @PROJECT_VERSION@
Requires: csfml-window, csfml-system
Requires.private: sfml-graphics
Libs: -L${libdir} -lcsfml-graphics
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions tools/pkg-config/csfml-network.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include

Name: CSFML-network
Description: The Simple and Fast Multimedia Library for C, network module.
URL: https://www.sfml-dev.org
Version: @PROJECT_VERSION@
Requires: csfml-system
Requires.private: sfml-network
Libs: -L${libdir} -lcsfml-network
Cflags: -I${includedir}
12 changes: 12 additions & 0 deletions tools/pkg-config/csfml-system.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include

Name: CSFML-system
Description: The Simple and Fast Multimedia Library for C, system module.
URL: https://www.sfml-dev.org
Version: @PROJECT_VERSION@
Requires.private: sfml-system
Libs: -L${libdir} -lcsfml-system
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions tools/pkg-config/csfml-window.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include

Name: CSFML-window
Description: The Simple and Fast Multimedia Library for C, window module.
URL: https://www.sfml-dev.org
Version: @PROJECT_VERSION@
Requires: csfml-system
Requires.private: sfml-window
Libs: -L${libdir} -lcsfml-window
Cflags: -I${includedir}

0 comments on commit 6476e94

Please sign in to comment.