Skip to content

Instantly share code, notes, and snippets.

@scivision

scivision/CMakeLists.txt

Last active Feb 17, 2021
Embed
What would you like to do?
CMake pkg-config .pc.in generate template
# this fragment generates build/my_package.pc
#
# cmake -B build -DCMAKE_INSTALL_PREFIX=~/mylib
cmake_minimum_required(VERSION 3.0)
project(mylib
LANGUAGES C
HOMEPAGE_URL https://github.invalid/username/mylib
DESCRIPTION "example library"
VERSION 1.1.2)
add_library(mine mine.c)
add_library(support support.c)
set(target1 mine)
set(target2 support)
set(pc_libs_private)
set(pc_req_private)
set(pc_req_public)
configure_file(my_package.pc.in my_package.pc @ONLY)
# this template is filled-in by CMake `configure_file(... @ONLY)`
# the `@....@` are filled in by CMake configure_file(),
# from variables set in your CMakeLists.txt or by CMake itself
#
# Good tutoral for understanding .pc files:
# https://people.freedesktop.org/~dbn/pkg-config-guide.html
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/lib"
includedir="${prefix}/include"
Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Requires: @pc_req_public@
Requires.private: @pc_req_private@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -l@target1@ -l@target2@
Libs.private: -L"${libdir}" -l@target1@ -l@target2@ @pc_libs_private@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment