[CMake] How to create transitive include dirs and preprocessor defs

Tyler Roscoe tyler at cryptio.net
Wed Apr 22 11:31:58 EDT 2009


On Wed, Apr 22, 2009 at 10:03:53AM +0200, Marcel Loose wrote:
> Suppose that one of subA1's header files includes a header file from
> ext1. I can specify this in subA1 CMakeLists file by using
> include_directories(). However, subA2 will fail to compile when it
> includes this header file, because the compiler cannot find ext1's
> header file. More or less the same can be said about preprocessor
> variables; you would like to "inherit" the preprocessor variables from
> the project that you depend upon.

I don't know if it's best, but the way I handle this is by defining
${ext1_includes} and ${ext1_definitions} in a common place accessible to
both subA1 and subA2. I use a separate CMakeVars.txt for each project
that defines variables which a dependent might need to communicate with
that project. You could also use [set|get]_target_property.

Then subA1 and subA2 simply have ${ext1_includes} in their
include_directories() invocation.

tyler


More information about the CMake mailing list