[CMake] $<> expressions in include_directories command

Jean-Christophe Fillion-Robin jchris.fillionr at kitware.com
Tue Jul 12 17:57:38 EDT 2011


Hi Daniel,

This sounds like a great feature :), do you think you could also associate a
test with your changes ?

Out of curiosity, why "*the right set of include directories is unknown
until all components
have been processed*" ?

If it resumes not to be the case, I believe using a CMakeCache variable
could do the job.

For example:

# Clear foo bar
set(FOOBAR_DIRS "" CACHE STRING "Foobar dirs" FORCE)

...

add_subdirectory(C)
set(C_DIRS ..) # Collect C directories
set(FOOBAR_DIRS ${FOOBAR_DIRS} ${C_DIRS} CACHE STRING "Foobar dirs" FORCE)
include_directories(${FOOBAR_DIRS})
add_libraries(C ...)


...

add_subdirectory(B)
set(B_DIRS ..) # Collect B directories
set(FOOBAR_DIRS ${FOOBAR_DIRS} ${B_DIRS} CACHE STRING "Foobar dirs" FORCE)
include_directories(${FOOBAR_DIRS})
add_libraries(B ...)

...

add_subdirectory(A)
set(A_DIRS ..) # Collect A directories
set(FOOBAR_DIRS ${FOOBAR_DIRS} ${A_DIRS} CACHE STRING "Foobar dirs" FORCE)
include_directories(${FOOBAR_DIRS})
add_libraries(A ...)

Hth
Jc

On Tue, Jul 12, 2011 at 12:34 PM, Daniel Pfeifer <purplekarrot at gmail.com>wrote:

> Hi fellows of Ryppl and CMake,
>
> we are currently in the process of modularizing the Boost C++
> Libraries into small individual components. All these components may
> depend upon each other, circular dependencies may occur too. We use
> CMake to configure, build, test, package etc. We are quite successful.
>
> Concerning include directories, we make all header files available
> from one directory. We do this either with symlinks or with forwading
> headers, depending on whether symlinks are possible on that platform
> or not. This works, but has several drawbacks:
>
> 1. It is slow. Generating forwarding headers for all headers that we
> use is a matter of minutes. We can improve the speed by checking the
> existence of files or symlinking directories, but then:
>
> 2. It is fragile. When we add a file header file in a directory that
> is forwarded via a symlink we may accidentally put it into the source
> directory.
>
> 3. it is not correct. Each component may access all header files. It
> should be able to access the headers of its dependency tree only.
>
>
> For a fast, stable, and correct solution, we want to add the right set
> of include directories directly, without forwarding anything. However,
> the right set of include directories is unknown until all components
> have been processed.
>
> Example: We have the components A, B, C. A depends on B, B depends on
> C. Therefore, A should be using the include directories of B and C.
> This information however is unknown until the components B and C have
> been processed. The include directories cannot be declared while
> processing A.
>
>
> The ideal solution for us would be the following:
>
> > include_directories($<FOOBAR_DIRS>)
> > ...
> > set(FOOBAR_DIRS /usr/include/foo)
>
> The generator expression $<FOOBAR_DIRS> is evaluated in the final pass
> of the include_directories command. It is possible to 'use' the value
> FOOBAR_LIBS before it has been set.
>
> I already implemented the functionality above. The generator
> expressions are expanded incrementally and recursive expansion is
> taken care of. See:
> https://github.com/purpleKarrot/CMake/commit/5f73bcf40fe8b9150bf61afaa3783b56be9e8270
>
> Can we get this functionality upstream?
>
> cheers, Daniel
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
+1 919 869 8849
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110712/dc2030bf/attachment.htm>


More information about the CMake mailing list