[CMake] How to have a static/shared option in a Find script ?

Barth barthelemy.von.haller at cern.ch
Thu Feb 16 02:05:33 EST 2012


Hello,

A great thanks for your extensive reply !
I am going to implement the "clean" approach following your advices.

Best regards,
Barth

On 02/16/2012 12:47 AM, Michael Hertling [via CMake] wrote:
> On 02/15/2012 03:48 PM, Barth wrote:
>
> > Hello,
> >
> > I am trying to write a Find script for a library called DIM. It is 
> something
> > basic but I have a problem with caching. I have an option to force 
> choosing
> > the static library over the shared one :
> >
> > Then, I decide what is the name of the library to search depending on
> > DIM_USE_STATIC and I find it with find_library :
> >
> >
> > The problem is that modifying DIM_USE_STATIC in ccmake doesn't work 
> even
> > though DIM_LIB_NAME is correct (ie. libdim.a). DIM_LIBRARY sticks to 
> the
> > previous value (the shared library).
> > I know that find_library will not run again if it has already found the
> > library in the past, thus how should I do ?
> >
> > Thank you in advance for your help,
> > Barth
>
> Probably, you just need to reset DIM_LIBRARY to an empty string in
> ccmake each time you change DIM_USE_STATIC; see the FIND_LIBRARY()
> documentation for more information: "If the library is found the
> result is stored in the variable and the search will not be
> repeated *unless the variable is cleared*."
>
> However, a conceptually cleaner approach is to consider the shared and
> the static version of a library as two components of a multi-component
> package, and write the find module / configuration file accordingly:
>
> (1) Use FIND_LIBRARY() to look for the shared and the static library
>     and define DIM_SHARED_LIBRARY and DIM_STATIC_LIBRARY in the cache.
> (2) Inspect DIM_FIND_COMPONENTS to see which flavor has been requested,
>     defaulting to "shared" if no components have been requested at all.
> (3) Warn or bail out if "shared" and "static" have both been requested
>     unless they can be used together - rare but not impossible a priori.
> (4) DIM_USE_STATIC decides if DIM_LIBRARIES receives DIM_STATIC_LIBRARY
>     or DIM_SHARED_LIBRARY, and because DIM_LIBRARIES is not cached, it
>     can be set anew each time FIND_PACKAGE(DIM ...) is called, so the
>     issue you report on will go away.
>
> IMO, most packages providing a library with shared and static versions
> should be considered in this manner, as this would be a robust mean to
> specifically select one or the other without the need to reset cache
> entries or bother with CMAKE_FIND_LIBRARY_SUFFIXES or the like.
>
> BTW, this approach would also account for the long-standing annoyance
> how to have FIND_LIBRARY() differentiate between a static library and
> an import library on Windows; each library type would simply have its
> own FIND_LIBRARY() call, and this would make things much easier.
>
> Regards,
>
> Michael
> -- 
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:
> http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7289496.html 
>
> To unsubscribe from How to have a static/shared option in a Find 
> script ?, click here 
> <http://cmake.3232098.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7287655&code=YmFydGhlbGVteS52b24uaGFsbGVyQGNlcm4uY2h8NzI4NzY1NXwxNDQ2NTQ5NDE=>.
> NAML 
> <http://cmake.3232098.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> 
>


--
View this message in context: http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7290177.html
Sent from the CMake mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120215/53104ee8/attachment.htm>


More information about the CMake mailing list