[cmake-developers] Using cmake pkg-config-like in non-cmake builds

Alexander Neundorf neundorf at kde.org
Tue Nov 23 15:37:47 EST 2010


On Monday 22 November 2010, Alan W. Irwin wrote:
> On 2010-11-22 21:55+0100 Alexander Neundorf wrote:
> > Hi,
> >
> > there can be the case that a package which has been built with cmake,
> > should be used in a project which doesn't use cmake.
> > There is a feature request that cmake should help with generating
> > pkg-config pc-files: http://public.kitware.com/Bug/view.php?id=11446
> >
> > I don't like that idea, because a) this means duplicating information,
> > and b) doing that in a less powerful format.
> >
> > I have a slightly different idea: instead of having cmake generate
> > pc-files, modify/extend cmake so that it can be used similar to
> > pkg-config by projects which don't use cmake as their buildsystem.
> > I attached a first very quick try to that bug report.
> > It's a small cmake script which can be executed by cmake with -P, and
> > which basically contains one find_package() call and prints the results,
> > so they can be fed into a compiler invocation in a makefile.
> >
> > It already somewhat works:
> > $ cmake -DMODE=COMPILE -DCOMPILER_ID=GNU -DPACKAGE=PNG -P
> > cmake-config.cmake -I/usr/include -I/usr/include
> >
> > $ cmake -DMODE=LINK -DCOMPILER_ID=GNU -DPACKAGE=PNG -P cmake-config.cmake
> > /usr/lib/libpng.so /usr/lib/libz.so
> >
> >
> > Do you think this makes sense ?
>
> Hi Alex:
>
> How did you collect that compiler flag information? 

I simply concatenated the include directories found in ${FOO_INCLUDE_DIRS}.
The script is attached to the bug report.

> As far as I know
> the command "install(EXPORT ....)" only writes out information about
> the link flags but not the compile flags associated with a given
> library target. If your method of obtaining compile flag information
> is general enough, then it should be straightforward to modifiy that
> install signature to write out the compile flags as well, and that
> would be a huge win.
>
> For example, PLplot currently uses install(EXPORT ....) to collect
> link flag information for all its libraries for the use of external
> projects.  And we use that information for an external CMake-based
> build system we have implemented to build and exhaustively test our
> installed examples. That build system would be a lot less cumbersome
> if we had access to compile flags for each of our libraries through
> the EXPORTed cmake file.

You can write any information you want into the install Config-file.
What I usually do is to configure() the Config-file, and that Config-file then 
include()s the exports-file.

Alex



More information about the cmake-developers mailing list