<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
Hello, <br>
<br>
A great thanks for your extensive reply !<br>
I am going to implement the "clean" approach following your advices.
<br>
<br>
Best regards,<br>
Barth<br>
<br>
On 02/16/2012 12:47 AM, Michael Hertling [via CMake] wrote:
<blockquote cite="mid:4F3C4407.8080305@online.de" type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
On 02/15/2012 03:48 PM, Barth wrote:
<div class="shrinkable-quote"><br>
> Hello, <br>
> <br>
> I am trying to write a Find script for a library called
DIM. It is something
<br>
> basic but I have a problem with caching. I have an option
to force choosing
<br>
> the static library over the shared one : <br>
> <br>
> Then, I decide what is the name of the library to search
depending on
<br>
> DIM_USE_STATIC and I find it with find_library : <br>
> <br>
> <br>
> The problem is that modifying DIM_USE_STATIC in ccmake
doesn't work even
<br>
> though DIM_LIB_NAME is correct (ie. libdim.a). DIM_LIBRARY
sticks to the
<br>
> previous value (the shared library). <br>
> I know that find_library will not run again if it has
already found the
<br>
> library in the past, thus how should I do ? <br>
> <br>
> Thank you in advance for your help, <br>
> Barth
</div>
<br>
Probably, you just need to reset DIM_LIBRARY to an empty string in
<br>
ccmake each time you change DIM_USE_STATIC; see the FIND_LIBRARY()
<br>
documentation for more information: "If the library is found the
<br>
result is stored in the variable and the search will not be
<br>
repeated *unless the variable is cleared*."
<br>
<br>
However, a conceptually cleaner approach is to consider the shared
and
<br>
the static version of a library as two components of a
multi-component
<br>
package, and write the find module / configuration file
accordingly:
<br>
<br>
(1) Use FIND_LIBRARY() to look for the shared and the static
library
<br>
and define DIM_SHARED_LIBRARY and DIM_STATIC_LIBRARY in the
cache.
<br>
(2) Inspect DIM_FIND_COMPONENTS to see which flavor has been
requested,
<br>
defaulting to "shared" if no components have been requested at
all.
<br>
(3) Warn or bail out if "shared" and "static" have both been
requested
<br>
unless they can be used together - rare but not impossible a
priori.
<br>
(4) DIM_USE_STATIC decides if DIM_LIBRARIES receives
DIM_STATIC_LIBRARY
<br>
or DIM_SHARED_LIBRARY, and because DIM_LIBRARIES is not
cached, it
<br>
can be set anew each time FIND_PACKAGE(DIM ...) is called, so
the
<br>
issue you report on will go away.
<br>
<br>
IMO, most packages providing a library with shared and static
versions
<br>
should be considered in this manner, as this would be a robust
mean to
<br>
specifically select one or the other without the need to reset
cache
<br>
entries or bother with CMAKE_FIND_LIBRARY_SUFFIXES or the like.
<br>
<br>
BTW, this approach would also account for the long-standing
annoyance
<br>
how to have FIND_LIBRARY() differentiate between a static library
and
<br>
an import library on Windows; each library type would simply have
its
<br>
own FIND_LIBRARY() call, and this would make things much easier.
<br>
<br>
Regards,
<br>
<br>
Michael
<br>
--
<br>
<br>
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com" target="_top" rel="nofollow" link="external">www.kitware.com</a>
<br>
<br>
Visit other Kitware open-source projects at <a
moz-do-not-send="true"
href="http://www.kitware.com/opensource/opensource.html"
target="_top" rel="nofollow" link="external">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a
moz-do-not-send="true"
href="http://www.cmake.org/Wiki/CMake_FAQ" target="_top" rel="nofollow" link="external">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:
<br>
<a moz-do-not-send="true"
href="http://www.cmake.org/mailman/listinfo/cmake" target="_top" rel="nofollow" link="external">http://www.cmake.org/mailman/listinfo/cmake</a><br>
<br>
<br>
<hr color="#cccccc" noshade="noshade" size="1">
<div style="color:#444; font: 12px
tahoma,geneva,helvetica,arial,sans-serif;">
<div style="font-weight:bold">If you reply to this email, your
message will be added to the discussion below:</div>
<a moz-do-not-send="true"
href="http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7289496.html" target="_top" rel="nofollow" link="external">http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7289496.html</a>
</div>
<div style="color:#666; font: 11px
tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em">
To unsubscribe from How to have a static/shared option in a Find
script ?, <a moz-do-not-send="true"
href="" target="_top" rel="nofollow" link="external">click
here</a>.<br>
<a moz-do-not-send="true"
href="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" rel="nofollow" style="font:9px serif" target="_top" link="external">NAML</a> </div>
</blockquote>
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7290177.html">Re: How to have a static/shared option in a Find script ?</a><br/>
Sent from the <a href="http://cmake.3232098.n2.nabble.com/">CMake mailing list archive</a> at Nabble.com.<br/>