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.
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.
pkg_check_modules. Checks for all the given modules, setting a variety of result variables in the calling scope.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With