[CMake] foreach and find_library

bpwlist at cox.net bpwlist at cox.net
Thu Feb 22 15:12:43 EST 2007


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)

This yields the folowing output:

Lib: osg
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgUtil
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgDB
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgGA
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgFX
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgSim
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgParticle
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: osgText
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so
Lib: OpenThreads
Found Lib: /proj/visual/OSG/OpenSceneGraph/lib/Linux32/libosg.so

The code only finds the first library.  If I unroll the variable by hand and use a different output variable name with each FIND_LIBRARY, it produces the correct output.  Is this some weird scoping problem with variables?  Is there a better way of accomplishing this?

Thanks,

Bryan Walsh



More information about the CMake mailing list