<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1433745744302_4961" style="" class="" itemprop="text">

<div id="yui_3_16_0_1_1433745744302_4960" style="" class="">So I am writing a CMake module to find some libraries which is being 
used a lot in our company. These libraries all have different versions 
and are such a mess here. In a certain library, even the name of header 
files and binary files don't match. So I am writing a CMake script to 
handle all the problems of finding each library once and for all. What I
 have in my mind is to write something like how we find boost packages 
but include the version of each component as well. Something like this:</div>

<div style="" class=""><code style="" class="">find_package(OrgName COMPONENTS librarya-1.4.3 libraryb-2.3.1 libraryc-3.6.0)</code></div>

<div id="yui_3_16_0_1_1433745744302_4963" style="" class="">So I created a <code id="yui_3_16_0_1_1433745744302_4962" style="" class="">FindOrgName.cmake</code> file and iterated on 
the requested components, then I processed the string which is passed 
and gained the library name along with its version information something
 like this (never mind the difference between include and binary files):</div>

<pre id="yui_3_16_0_1_1433745744302_4965" style="" class=""><code id="yui_3_16_0_1_1433745744302_4964" style="" class="">IF(OrgName_FIND_COMPONENTS)
   FOREACH(comp ${OrgName_FIND_COMPONENTS})
      SET(OrgName_${comp}_FOUND 0)

      STRING(FIND ${comp} "-" dashind REVERSE)
      STRING(LENGTH ${comp} length)
      STRING(SUBSTRING ${comp} 0 ${dashind} name)
      MATH(EXPR s "${dashind}+1")
      MATH(EXPR l "${length}-${dashind}-1")
      STRING(SUBSTRING ${comp} ${s} ${l} version)

      SET(OrgName_${name}_INCLUDE_DIR "/usr/local/include/OrgName/${comp}/")
      find_library(OrgName_${comp}_LIBRARIES NAMES "${comp}" HINTS "/usr/lib")

      IF(OrgName_${comp}_INCLUDE_DIR AND OrgName_${comp}_LIBRARIES)
         SET(OrgName_${comp}_FOUND 1)
      ENDIF()

      IF(NOT OrgName_${comp}_FOUND AND OrgName_FIND_REQUIRED_${comp})
         MESSAGE(FATAL_ERROR "OrgName ${comp} not available.")
      ENDIF()

      SET (OrgName_INCLUDE_DIR ${OrgName_INCLUDE_DIR} ${OrgName_${comp}_INCLUDE_DIR})
      SET (OrgName_LIBRARIES ${OrgName_LIBRARIES} ${OrgName_${comp}_LIBRARIES})
  ENDFOREACH()
ENDIF()
</code></pre>

<div id="yui_3_16_0_1_1433745744302_4989" style="" class="">Now here is the problem, imagine someone didn't enter the version 
part in components names. I want to search for the versions which he has
 installed (assume the path to library is always the same) and use the 
last version it can find, so I have to search for the files which their 
name contains the library name (${name}). First of all how can I do 
this? Second, Am I doing things right? I mean is there an easier way to 
do this task?</div><div dir="ltr">
    </div></div><div style="" class="" id="yui_3_16_0_1_1433745744302_4932"><br style="" class=""></div></div></body></html>