# 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)
and
# 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@
CMake can generate pkg-config .pc files for packages. The .pc file serves as a Rosetta stone for many build systems.
A good basic reference for pkg-config .pc syntax is helpful.
Relevant code:
and
Possible problems: How to generate .pc (pkg-config) file supporting –prefix of the cmake –install?