Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create my own cmake target with pkg-config settings?

Tags:

My project is shared library, and I would like to create installation target with settings for pkg-config.

Currently it builds by only one, very simple rule:

add_library(mylib SHARED src/mylib.cxx)

And here I'm stuck with further configuration because every installation rule should be dependent on the preconfigured installation paths and flags. To keep it simple, let's say, the target will be installed to include and lib directories and preconfigured .pc rules will be something like -lmylib -I/...include -L/....lib

How can I configure cmake's installation targets with pkg-config support ? I guess it does not have builtin support of pkg-config and I need your help to find a proper solution.

like image 493
L.Integra Avatar asked Feb 13 '18 14:02

L.Integra


People also ask

What is CMake config file?

A config-file package is a set of files provided by upstreams for downstreams to use. CMake searches in a number of locations for package configuration files, as described in the find_package() documentation.

What is Pkg_check_modules?

pkg_check_modules. Checks for all the given modules, setting a variety of result variables in the calling scope.

What is Pkgconfig in Linux?

pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line so an application can use gcc -o test test. c `pkg-config --libs --cflags glib-2.0` for instance, rather than hard-coding values on where to find glib (or other libraries).


1 Answers

CMake can interoperate with pkg-config in both directions, though it's a little bit clunky.

FindPkgConfig allows you to find and use libraries using their pkg-config files.

To have cmake generate a pkg-config file for your own library, you'll have to use configure_file and have a template pkg-config file.

like image 124
Chris Kitching Avatar answered Sep 21 '22 12:09

Chris Kitching