[CMake] Cmake and pkg-config and linking

rael at edge.ping.de rael at edge.ping.de
Sat Jul 29 12:18:30 EDT 2006


Hello! 

On my way for looking for simpler building of my C++ code and easy support 
for windows and Mac OS X (bundles) (which seem to be lot of fun to build 
with my current autoconf/automake aproach) I found CMake and decided to test 
it. 

I wrote a simple makefile for one of my binaries for windows and msys 
environment. 

However I have problems building my program that accesses a library that 
supports a pkg-config file for easy linking. 

I found some information about the available pkgconfig support. 

Adding CFLAGS is simple by setting "CMAKE_CXX_FLAGS" (however this makes the 
flags getting added also to the linking step, too, which seemto be wrong to 
me). However setting equivalent "CMAKE_CXX_LINK_FLAGS" or using 
SET_TARGET_PROPERTIES... LINK_FLAGS did not success because the order of 
arguments in this case is wrong for linking. The objects of my binary are 
places behind the library arguments (-L and -l) thus resulting in unresolved 
symbols. The linker flags for the library have to get placed *after* the 
program object files! 

Using higher level cmake stuff is not easy (variables for search ddiretories 
and libraries), because my linker flags include -L and -l options which have 
to be splited first (and what if one directory contains a space?) and is 
ugly because I have to add this code block to every of my programs. 

Is there an easy way to place my library linker arguments after the program 
objects files or has somebody code for splitting pkg-config result values 
for the higher level cmake variables? Or can I write a pkg-config pc file 
files while compiling my library to gets read by cmake directly (whichout 
yet switching the build of my library to cmake)? 

Another remark:
My pkg-config 0.15 and also the current version have aditional access 
options which already split compiler flags and linker flags into directory 
including parts and library linking and other parts. Which seems to be 
exactly the information that has to be injected into cmake. Why were such 
options not used? 

 --libs                                         output all linker flags
 --libs-only-l                                  output -l flags
 --libs-only-other                              output other libs (e.g.
                                                -pthread)
 --libs-only-L                                  output -L flags
 --cflags                                       output all pre-processor and
                                                compiler flags
 --cflags-only-I                                output -I flags
 --cflags-only-other                            output cflags not covered by
                                                the cflags-only-I option
Property support for pkg-config IMHO is high priority because more and more 
unix software makes use of it - and it is realy simple to use. 

-- 
Gruß...
      Tim.


More information about the CMake mailing list