[CMake] I'm confused with Find*.cmake and *-config.cmake

Micha Renner Micha.Renner at t-online.de
Tue Apr 20 01:05:20 EDT 2010


Am Montag, den 19.04.2010, 16:07 -0400 schrieb Benoit Thomas:
> Hello,
> 
> I'm using an external library which is already compiled. I have wrapped 
> the library in a MyLib.cmake and use it in cmake as an imported library. 
> It works fine, but since the include line uses relative path, it changes 
> from projects to projects and in some case it looks just wrong.
> 
> I want to change this to something more like:
> 
> find_package (MyLib)
> include (MYLIB_CMAKE_FILE)
> # add_executable and stuff
> target_link_libraries (MyExe MyLib)
> 
> However, I'm not sure if I should create a FindMyLib.cmake file or 
> MyLib-config.cmake. Both seems to eventually do the same, but I don't 
> really understand what are the differences.
> 
> When I looked at some Find*.cmake file (FindSWIG for example) it has a 
> UseSWIG.cmake file. Syntax looks like what I'm trying to achieve, but 
> the none of the Use* files I've check create imported libray, so I guess 
> this is not the way to go.
> 
> In the book, there is an example which seems to do more what I want and 
> use *-config.cmake, which give something like
> 
> find_package (MyLib)
> # no include, since the MyLib-config.cmake already took care of the include
> # add_executable and stuff
> target_link_libraries (MyExe MyLib)
> 
> Part of what I don't understand is when a user use the find_package 
> command, is he expecting to load a Find* file or a *-config file (or he 
> doesn't care?), and is he expecting a specific behavior from each file, 
> etc, etc... And would it be a surprise for the user if the 
> find_package(MyLib) add a MyLib target into his project ? And is using 
> find_package appropriate for this kind of situation and I got it all 
> wrong :) ?
> 
> Bottom line, I'm looking for a way to write my projects so that if 
> someone else with cmake experience look into them, it will feel like 
> "common" cmake project (if such thing exists) and not something I'm the 
> only one to understand...
> 
> (Sorry if this sound confusing)

Here,
http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries#How_package_finding_works
 you can also read some statements about Find* and *config files.

Micha




More information about the CMake mailing list