[CMake] read file content to a variable at build-time

Alexander Neundorf a.neundorf-work at gmx.net
Wed Aug 21 16:36:13 EDT 2013


On Thursday 01 August 2013, Rothbauer, Stefan wrote:
> Hello,
> 
> I set up cmake to use a external project. This 3rd party library writes out
> a file which contains all include paths set by this library. For the
> master cmake project I need to read this information at build time into a
> cmake variable to set the include directories correctly. Is there a way to
> do this?

no, that's not possible.
You can read files at build time, but if you would do this, you would be 
reading the file containing the include dirs while the makefile (or whatever) 
which is being used to build your main project and which contains the include 
dirs for your main project, is already being processed.
Do you see what I mean ?

You have to find a way to figure out the include directories needed for your 
main project at cmake time.
From my experience with ExternalProject this is not hard, since you know where 
you are installing the external project to, and you can check (by looking 
manually at it) what include dirs it needs, and just set them.

Alternatively the issue can probably also be solved by converting your main 
project also into an ExternalProject, then its configure step will run after 
the 3rd party library has been built.

Alex


More information about the CMake mailing list