[CMake] foreach and find_library
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Thu Feb 22 15:33:44 EST 2007
On 2007-02-22 12:12-0800 bpwlist at cox.net wrote:
> Hi,
>
> I'm trying to construct a list of external libraries. This list needs to include the full path and name of each library. This list is to be used with the INSTALL(FILE) command. I'm trying to use FIND_LIBRARY inside a FOREACH loop command to accomplish this. For example:
>
> SET (LIBS ${OSG_LIBRARIES})
> SET (SEARCH_PATHS ${OSG_LIBRARY_DIR})
> FOREACH (LIB ${LIBS})
> FIND_LIBRARY(FOUND_LIB ${LIB} PATHS ${SEARCH_PATHS})
> MESSAGE("Lib: ${LIB}")
> MESSAGE("Found Lib: ${FOUND_LIB}")
> ENDFOREACH(LIB)
FOUND_LIB is cached with a special behaviour if the variable is set to
${LIB}-NOTFOUND (see the documentation of FIND_LIBRARY). So you must change
the name of the variable within the loop (i.e., use a variable like
FOUND${LIB}) or set it within the loop to ${LIB}-NOTFOUND (I believe this
would be the preferred solution since it doesn't fill up the cache with a
bunch of variables you are not going to use) before each call to
FIND_LIBRARY. Otherwise, all calls to FIND_LIBRARY after the first will not
change anything (as you found) because of the caching of your FOUND_LIB
variable in the above loop.
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
More information about the CMake
mailing list