[CMake] Reading lists of items from an external file (fwd)

Brad King brad.king at kitware.com
Mon Oct 11 18:05:50 EDT 2004


Hinderk Buss wrote:
> I would like to store information about those libraries against which I 
> want to link my target in a seperate file. This file should simply contain 
> a number of filenames or names of other targets already build:
> 
> explBasic
> explMath
> explElement
> 3rd_party/lib/libxerces-c_1_6_0.so
> 
> ...
> 
> I tried to imort this information with the following directive:
> 
> FILE( READ libraries.txt LINKLIBRARIES )
> 
> The variable LINKLIBRARIES thus created contains all the newlines and the 
> whitespace present in the file "libraries.txt".

You could use this to turn the list of lines into a list:

STRING(REGEX REPLACE "[ \\t\\r\\n][ \\t\\r\\n]*" ";"
        LINKLIBRARIES "${LINKLIBRARIES}")

The above is untested.  You might have to tweak the regular expression.

Alternatively, you could make the contents of the file look like this:

SET(LINKLIBRARIES
...list here...
)

and then load the file with the INCLUDE command.

-Brad


More information about the CMake mailing list