[CMake] Re: Lib dependencies discovery

Bill Hoffman bill.hoffman at kitware.com
Tue Apr 24 21:25:34 EDT 2007


Pascal Fleury wrote:
> On Wednesday 25 April 2007 02:04:15 Matthew Woehlke wrote:
>   
>> Pascal Fleury wrote:
>> In my project, I wrote this macro:
>>
>> MACRO(CHECK_LIBRARY LIB_NAME LIB_DESC LIB_TEST_SOURCE)
>>     
>
> Sorry that I cannot express my problem more clearly ;-)
>
> I have this in place, but there are some tests that are spead over multiple 
> CMakeLists.txt files. At some point, at the end of the processing of these 
> CMakeLists.txt I would like to access the collected information about what 
> macros such as yours did find. Some of these libs depend on user flags, to 
> include/exclude some modules, and hence changing the list of libraries that 
> would need linking later on.
>
> Example:
> user 1 compiles the mainlib with default flags, which include the networking 
> component. When she wants to link her app against the produced mainlib.(a|
> lib), she will need the socket/ws2_32.lib lib as well.
> user 2 compiles the mainlib with the flag -DNETWORK_SUPPORT=OFF, so that the 
> networking component is not present in the mainlib. When user 2 wants to link 
> her own app to this mainlib, the socket/ws2_32.lib is actually not needed for 
> the application to link properly.
>  
> So in mainlib's CMakeLists.txts, how can I find out what the resulting list of 
> libs would be, depending on the user flags and/or the discoveries cmake did 
> for me ? (besides maintaining a parallel list to what cmae already manages)
>
> I currently am using the 'mainlib_LIB_DEPENDS', which seem to contain 
> a ';'-separated list of libs, with some quirks (some are absolute paths, some 
> are just the name, some have leading '-l' etc.) I cleanup this list, and put 
> this into the pkg-config, that is then picked up by the application's 
> cmakelists.txt files that link the app. Is that mainlib_LIB_DEPENDS variable 
> portable ?
>
>   

Try this command:

    * *|EXPORT_LIBRARY_DEPENDENCIES|*: Write out the dependency
      information for all targets of a project.

        EXPORT_LIBRARY_DEPENDENCIES(FILE [APPEND])
          

      Create a file that can be included into a CMake listfile with the
      INCLUDE command. The file will contain a number of SET commands
      that will set all the variables needed for library dependency
      information. This should be the last command in the top level
      CMakeLists.txt file of the project. If the APPEND option is
      specified, the SET commands will be appended to the given file
      instead of replacing it.

That is what we use in VTK to export all the link information from one 
project to another.

-Bill




More information about the CMake mailing list