[CMake] inherit include directories from child directory

Philip Lowman philip at yhbt.com
Sat Apr 4 12:26:55 EDT 2009


On Sat, Apr 4, 2009 at 5:13 AM, elizabeta petreska <
elizabeta.petreska at gmail.com> wrote:

> Thanks for the help.I'm sorry if my question was not clear enough or maybe
> I don't understand your answer
>
> My question was how the parent directory may inherit the include
> directories from the child directory (added with add_subdirectory)  ?
>
>  The current behavior is that the include directories from the child
> directory are added to the list of includes in the parent.
>

Elizabeta,

Provided the directory name is an absolute path I think you could use the
PARENT_SCOPE option to set() to pass the include directories up a directory
to the parent.  This is provided you're using CMake >= 2.6.0.  If you are on
2.4.x or have to pass variables up many directories there are alternatives
to this that will effectively provide you global variables (was a recent
thread on the mailing list about this).

*parent_dir/CMakeLists.txt:
*add_subdirectory(child_dir)
include_directories(${my_include_dirs})

*    child_dir/CMakeLists.txt:
*    set(my_include_dirs ${FOO_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/another_child_dir) # can't use relative paths
here
    include_directories(${my_include_dirs})
    set(my_include_dirs ${my_include_dirs} PARENT_SCOPE)

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090404/178964c6/attachment.htm>


More information about the CMake mailing list