<meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  
  
    Hello, <br>
    <br>
    Thank you very much for your message. You have been very helpful. <br>
    <br>
    Best regards,<br>
    Barth<br>
    <br>
    On 02/16/2012 05:18 PM, Michael Hertling [via CMake] wrote:
    <blockquote cite="mid:4F3D2C4F.40407@online.de" type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      On 02/16/2012 03:14 PM, Barth wrote:
      <br>
      &gt; Hi again,
      <br>
      &gt; <br>
      &gt; I have understood what you meant :)
      <br>
      <br>
      Hhm, actually, I talked nonsense w.r.t. DIM_USE_STATIC. ;)
      <br>
      <br>
      &gt; For records here is what I did :
      <br>
      &gt; <br>
      &gt; # (1) Use FIND_LIBRARY() to look for the shared and the
      static library
      <br>
      &gt; # &nbsp; &nbsp; and define DIM_SHARED_LIBRARY and DIM_STATIC_LIBRARY in
      the cache. <br>
      &gt; find_library(DIM_STATIC_LIBRARY NAMES libdim.a PATHS
      $ENV{DIMDIR}
      <br>
      &gt; PATH_SUFFIXES linux)
      <br>
      &gt; find_library(DIM_SHARED_LIBRARY NAMES dim PATHS $ENV{DIMDIR}
      PATH_SUFFIXES
      <br>
      &gt; linux)
      <br>
      <br>
      If libdim.so doesn't exist, but libdim.a does, the last
      FIND_LIBRARY()
      <br>
      call would return libdim.a, too, which is probably not desired.
      Here,
      <br>
      one should consider to narrow the search for the respective
      library
      <br>
      type, e.g. by manipulating CMAKE_FIND_LIBRARY_SUFFIXES; see also
      <br>
      CMAKE_{SHARED,STATIC}_LIBRARY_{PREFIX,SUFFIX} in this regard.
      <br>
      <br>
      &gt; # (2) Inspect DIM_FIND_COMPONENTS to see which flavor has
      been requested,
      <br>
      &gt; # &nbsp; &nbsp; defaulting to "shared" if no components have been
      requested at all. <br>
      &gt; LIST(FIND DIM_FIND_COMPONENTS static ASK_STATIC_COMP) <br>
      &gt; LIST(FIND DIM_FIND_COMPONENTS shared ASK_SHARED_COMP) <br>
      <br>
      No need for them; use DIM_FIND_REQUIRED_{STATIC,SHARED} -
      predefined
      <br>
      by FIND_PACKAGE(). Refer to Modules/readme.txt for more
      information.
      <br>
      <br>
      &gt; # (3) Warn or bail out if "shared" and "static" have both
      been requested
      <br>
      &gt; if ( ${ASK_STATIC_COMP} GREATER -1 AND ${ASK_SHARED_COMP}
      GREATER -1)
      <br>
      &gt; &nbsp; &nbsp; message(WARNING "Two incompatible components specified :
      static and
      <br>
      &gt; shared. We are going to ignore the static component.")
      <br>
      &gt; endif ( ${ASK_STATIC_COMP} GREATER -1 AND ${ASK_SHARED_COMP}
      GREATER -1)
      <br>
      <br>
      IF(DIM_FIND_REQUIRED_SHARED AND DIM_FIND_REQUIRED_STATIC)
      <br>
      &nbsp; &nbsp; MESSAGE(WARNING ...)
      <br>
      &nbsp; &nbsp; LIST(REMOVE_ITEM DIM_FIND_COMPONENTS static)
      <br>
      &nbsp; &nbsp; UNSET(DIM_FIND_REQUIRED_STATIC)
      <br>
      ENDIF()
      <br>
      <br>
      Do something to the contrary if DIM_FIND_COMPONENTS is empty:
      <br>
      <br>
      IF(NOT DIM_FIND_COMPONENTS)
      <br>
      &nbsp; &nbsp; LIST(APPEND DIM_FIND_COMPONENTS shared)
      <br>
      &nbsp; &nbsp; SET(DIM_FIND_REQUIRED_SHARED TRUE)
      <br>
      ENDIF()
      <br>
      <br>
      The point is that DIM_FIND_COMPONENTS and DIM_FIND_REQUIRED_* are
      set
      <br>
      up properly *before* you are going to actually enable the
      components.
      <br>
      <br>
      &gt; # (4) DIM_USE_STATIC decides if DIM_LIBRARIES receives
      DIM_STATIC_LIBRARY
      <br>
      &gt; # &nbsp; &nbsp; or DIM_SHARED_LIBRARY
      <br>
      &gt; option(DIM_FORCE_STATIC "Turn on to force the use of the
      static library"
      <br>
      &gt; OFF)
      <br>
      &gt; if( ${DIM_FORCE_STATIC} OR ${ASK_STATIC_COMP} GREATER -1) <br>
      &gt; &nbsp; &nbsp; set(DIM_LIBRARIES ${DIM_STATIC_LIBRARY} )
      <br>
      &gt; else ( ${DIM_FORCE_STATIC} OR ${ASK_STATIC_COMP} GREATER -1)
      <br>
      &gt; &nbsp; &nbsp; set(DIM_LIBRARIES ${DIM_SHARED_LIBRARY} )
      <br>
      &gt; endif( ${DIM_FORCE_STATIC} OR ${ASK_STATIC_COMP} GREATER -1)
      <br>
      <br>
      UNSET(DIM_INCLUDE_DIRS)
      <br>
      UNSET(DIM_LIBRARIES)
      <br>
      <br>
      SET(DIM_FOUND FALSE)
      <br>
      <br>
      FIND_PATH(DIM_INCLUDE_DIR ...)
      <br>
      <br>
      IF(DIM_INCLUDE_DIR)
      <br>
      &nbsp; &nbsp; SET(DIM_FOUND TRUE)
      <br>
      ENDIF
      <br>
      <br>
      IF(DIM_FIND_REQUIRED_SHARED)
      <br>
      &nbsp; &nbsp; FIND_LIBRARY(DIM_SHARED_LIBRARY ...)
      <br>
      &nbsp; &nbsp; FIND_PACKAGE_HANDLE_STANDARD_ARGS(
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DIM_SHARED
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DEFAULT_MSG
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DIM_INCLUDE_DIR
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DIM_SHARED_LIBRARY)
      <br>
      &nbsp; &nbsp; IF(DIM_SHARED_FOUND)
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; LIST(APPEND DIM_INCLUDE_DIRS ${DIM_INCLUDE_DIR} ...)
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; LIST(APPEND DIM_LIBRARIES ${DIM_SHARED_LIBRARY} ...)
      <br>
      &nbsp; &nbsp;ENDIF()
      <br>
      &nbsp; &nbsp;LIST(REMOVE DIM_FIND_COMPONENTS shared)
      <br>
      &nbsp; &nbsp;UNSET(DIM_FIND_REQUIRED_SHARED)
      <br>
      ENDIF()
      <br>
      <br>
      IF(DIM_FIND_REQUIRED_STATIC)
      <br>
      &nbsp; &nbsp; FIND_LIBRARY(DIM_STATIC_LIBRARY ...)
      <br>
      &nbsp; &nbsp; FIND_PACKAGE_HANDLE_STANDARD_ARGS(
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DIM_STATIC
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DEFAULT_MSG
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DIM_INCLUDE_DIR
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; DIM_STATIC_LIBRARY)
      <br>
      &nbsp; &nbsp; IF(DIM_STATIC_FOUND)
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; LIST(APPEND DIM_INCLUDE_DIRS ${DIM_INCLUDE_DIR} ...)
      <br>
      &nbsp; &nbsp; &nbsp; &nbsp; LIST(APPEND DIM_LIBRARIES ${DIM_STATIC_LIBRARY} ...)
      <br>
      &nbsp; &nbsp;ENDIF()
      <br>
      &nbsp; &nbsp;LIST(REMOVE DIM_FIND_COMPONENTS static)
      <br>
      &nbsp; &nbsp;UNSET(DIM_FIND_REQUIRED_STATIC)
      <br>
      ENDIF()
      <br>
      <br>
      # Consider to handle remaining components in DIM_FIND_COMPONENTS.
      <br>
      <br>
      Note that due to the preparatory work on DIM_FIND_COMPONENTS and
      the
      <br>
      DIM_FIND_REQUIRED_* variables, the blocks for enabling the shared
      and
      <br>
      static component have a straight forward structure. Note further
      that
      <br>
      this can be achieved only with a quite simple package like yours
      with
      <br>
      two mutually exclusive libraries; with packages providing more
      subtly
      <br>
      related components - e.g. with inter-component dependencies -
      things
      <br>
      can be much more complicated. Note finally that the user must
      issue
      <br>
      <br>
      IF(DIM_FOUND AND DIM_SHARED_FOUND)
      <br>
      <br>
      e.g., in order to check for the library's availability unless the
      <br>
      REQUIRED flag was given to FIND_PACKAGE(). Checking for DIM_FOUND
      <br>
      or DIM_SHARED_FOUND alone is *not* reliable, just as referring to
      <br>
      a component that hasn't been requested explicitly - or enabled by
      <br>
      default which, in turn, should be documented explicitly.
      <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-tp7287655p7291471.html" target="_top" rel="nofollow" link="external">http://cmake.3232098.n2.nabble.com/How-to-have-a-static-shared-option-in-a-Find-script-tp7287655p7291471.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&amp;id=instant_html%21nabble%3Aemail.naml&amp;base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&amp;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-tp7287655p7300806.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/>