[CMake] How can I write CMakeLists.txt to link a special library?

Michael Wild themiwi at gmail.com
Mon Dec 15 11:05:04 EST 2008


On 15. Dec, 2008, at 16:46, Werner Smekal wrote:

> Hi,
>
> On 15.12.2008, at 16:39, Hendrik Sattler wrote:
>
>> Michael Wild schrieb:
>>> if (NOT WIN32)
>>> # use pkg-config to get the directories and then use these values
>>> # in the FIND_PATH() and FIND_LIBRARY() calls
>>> find_package( PkgConfig REQUIRED )
>>> pkg_check_modules( _sigcxx2  REQUIRED sigc++-2.0 )
>>> endif (NOT WIN32)
>>
>> pkgconfig can also be used on win32, so this is not correct,  
>> especially
>> when using MSYS.
>
> true, works even on windows command line interpreter with MinGW.  
> Download pkconfig for Windows here: http://www.gtk.org/download-windows.html
>

That's true, but will it be any good on Windows? Besides, the  
displayed code will even work without pkg-config, because it just uses  
the results of pkg-config as a "hint" for the find_path and  
find_library commands. So, actually, one might rework the whole  
passage as:

# use pkg-config (if available) to get the directories and then use  
these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package( PkgConfig )
if( PKGCONFIG_FOUND )
pkg_check_modules( _sigcxx2 sigc++-2.0 )
endif( PKGCONFIG_FOUND )

In case you wonder: the original implementation was inspired by  
FindLibXml2.cmake, which also contains the WIN32 conditional. That's  
the only reason it was there...


Michael


More information about the CMake mailing list