[CMake] Querying global property in FindXXX.cmake: good or bad?

Clinton Stimpson clinton at elemtech.com
Tue Jul 14 10:56:01 EDT 2009


On 07/14/2009 03:34 AM, Marcel Loose wrote:
> Hi all,
>
> I was wondering whether it is good or bad practice to query a (global)
> property in a FindXXX.cmake file.
>
> The reason I wanted to do this is, that when creating statically linked
> executables you will have to link against every library that you
> (indirectly) depend upon. When creating dynamically linked executables
> you usually don't have to worry so much, because indirect dependencies
> will be handled by the dynamic loader (assuming that the library you
> directly depend upon has its run-time dependencies set up properly).
>
> So, for example, assume I want to link against libldap. The 'ldd'
> command reveals all libraries that (the dynamic library) libldap.so
> depends upon. When creating a statically linked executable, I would have
> to link against each and every (static) library in that list. On the
> other hand, when linking dynamically, I would only have to link against
> libldap.so.
>
> Testing needlessly for the presence of all these (static) libraries
> makes CMake run unnecessary slow, so I would prefer to only do this if
> absolutely necessary: i.e. when creating a statically linked executable.
>
> For this I could query the global property TARGET_SUPPORTS_SHARED_LIBS,
> and have my FindXXX macro only check for all indirect dependencies when
> that property is FALSE.
>
> Good idea or bad idea?
>
> Best regards,
> Marcel Loose.
>
>    

Not all linkers behave that way.
There are some that require dependent shared libraries to be specified.

Clint




More information about the CMake mailing list