cmake: add pkg-config pc file generation

Create libperiphery.pc file for pkg-config. Allows to use
PKG_CHECK_MODULE in cmake, meson or autotools projet.

Example with cmake:
In CMakeLists:
pkg_check_modules(CPERIPHERY libperiphery REQUIRED)

-- Checking for module 'libperiphery'
--   Found libperiphery, version 2.1.0

Signed-off-by: Joris Offouga <offougajoris@gmail.com>

Rebase to use fixed variable names and updated cmake project name.
Also, rearrange some definitions in CMakeLists.txt.

Resolves #21.

Signed-off-by: Vanya A. Sergeev <v@sergeev.io>
This commit is contained in:
Joris Offouga
2020-04-05 18:31:45 +02:00
committed by Vanya A. Sergeev
parent 2e7ae374c0
commit 671e6182cd
2 changed files with 23 additions and 2 deletions

View File

@@ -34,9 +34,20 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_library(periphery ${periphery_SOURCES} ${periphery_HEADERS})
set_target_properties(periphery PROPERTIES SOVERSION ${VERSION})
include(GNUInstallDirs)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
# Generate pkg-config pc file
configure_file(${CMAKE_SOURCE_DIR}/src/libperiphery.pc.in ${CMAKE_BINARY_DIR}/libperiphery.pc @ONLY)
# Declare install targets
install(TARGETS periphery DESTINATION lib)
install(FILES ${periphery_HEADERS} DESTINATION include/${PROJECT_NAME})
install(TARGETS periphery DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${periphery_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
install(FILES ${CMAKE_BINARY_DIR}/libperiphery.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Declare tests targets
foreach(TEST_SOURCE ${periphery_TESTS})

10
src/libperiphery.pc.in Normal file
View File

@@ -0,0 +1,10 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libperiphery
Description: Library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux
Version: @VERSION@
Libs: -L${libdir} -lperiphery
Cflags: -I${includedir}