L.Integra
L.Integra

Reputation: 179

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

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.

Upvotes: 5

Views: 3749

Answers (1)

Chris Kitching
Chris Kitching

Reputation: 2655

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.

Upvotes: 4

Related Questions