[CMake] for loop won't locate libs

Hendrik Sattler post at hendrik-sattler.de
Thu Jun 4 15:11:03 EDT 2009


Am Donnerstag 04 Juni 2009 20:22:12 schrieb eial at cs.bgu.ac.il:
> On Thu 04 Jun 21:15 2009 Bill Hoffman wrote:
> > eial at cs.bgu.ac.il wrote:
> > > On Thu 04 Jun 20:31 2009 Bill Hoffman wrote:
> > >> eial at cs.bgu.ac.il wrote:
> > >>> On Thu 04 Jun 20:16 2009 Tyler Roscoe wrote:
> > >>>> On Thu, Jun 04, 2009 at 07:50:08PM +0300, eial at cs.bgu.ac.il wrote:
> > >>>>> SET(LIBS AR ARMulti ARvideo)
> > >>>>> FOREACH (LIB ${LIBS})
> > >>>>>    SET(FOUND_LIB)
> > >>>>>    FIND_LIBRARY(LIB_FOUND ${LIB} /usr/lib /usr/local/lib)
> > >>>>>    SET(ARTK_LIBRARY ${ARTK_LIBRARY} ${LIB_FOUND})
> > >>>>> ENDFOREACH(LIB)
> > >>>>>
> > >>>>> the result is
> > >>>>> /usr/lib64/libAR.a/usr/lib64/libAR.a/usr/lib64/libAR.a when it
> > >>>>> should be /usr/lib64/libAR.a /usr/lib64/libARMulti.a
> > >>>>> /usr/lib64/libARvideo.a
> > >>>>
> > >>>> What's up with set(FOUND_LIB)?
> > >>>>
> > >>>> You might be running into a quoting/list expansion problem. Try:
> > >>>> SET(ARTK_LIBRARY "${ARTK_LIBRARY}" "${LIB_FOUND}")
> > >>>>
> > >>>> or use list(APPEND ...) instead.
> > >>>>
> > >>>> tyler
> > >>>
> > >>> apparently, FOUND_LIB isn't being cleaned in each loop, that is for
> > >>> cleaning. my problem is that the loop finds only the first lib's file
> > >>> but not the rest, look at the output result that I've posted.
> > >>
> > >> Look at the docs for FIND_LIBRARY:
> > >> http://www.cmake.org/cmake/help/cmake2.6docs.html#command:find_library
> > >>
> > >>
> > >> "A cache entry named by <VAR> is created to store the result of this
> > >> command. If the library is found the result is stored in the variable
> > >> and the search will not be repeated unless the variable is cleared. If
> > >> nothing is found, the result will be <VAR>-NOTFOUND, and the search
> > >> will be attempted again the next time find_library is invoked with the
> > >> same variable."
> > >>
> > >> -Bill
> > >
> > > ${FOUND_LIB-NOTFOUND} is empty in every iteration
> >
> > Sure, because it is FOUND...   Once it finds it it does not look for it
> > again.  If not CMake would try to find stuff every time it runs.  As the
> > above paragraph says: "search will not be repeated unless the variable
> > is cleared"
> >
> > So, you either need to do a cache force to clear it, or you need to use
> > a different variable for each find_library.
> >
> > -Bill
>
> ok, I've understand the problem, I'm trying to clear the var using
> SET(FOUND_LIB) but it doesn't seem to work, how can I clear the variable?

Don't do it or the that will redo the search every time that cmake runs.
The snippet at the bottom does:
1. not actively work against the optimisation,
2. sticks to the naming conventions and
3. removes /usr/lib and /usr/local/lib as they are already searched

SET(LIBS AR ARMulti ARvideo)
FOREACH (LIB ${LIBS})
  FIND_LIBRARY(${LIB}_LIBRARY ${LIB})
  IF(NOT ${LIB}_LIBRARY)
    LIST(APPEND ARTK_LIBRARIES ${LIB}_LIBRARY)
  ENDIF(NOT ${LIB}_LIBRARY)
ENDFOREACH(LIB)

HS



More information about the CMake mailing list