[CMake] More control with includes? and non-immediate controls

Brad King brad.king at kitware.com
Wed Jun 22 13:19:13 EDT 2005


Bradley Lowekamp wrote:
> Hello,
> 
> Based on the behavior I have seen, I coded up this example of what I 
> find to be odd behavior. Consider the following cmake simplified example:
> 
>     INCLUDE_DIRECTORIES(foo/include)
>     ADD_LIBRARY(foo  ${FOOS_SRC})
>     INCLUDE_DIRECTORIES(bar/include)
>     ADD_LIBRARY(bar ${BARS_SRC})
> 
> With these lines I find it interesting that both libraries get compiled 
> with both include! This is something that is good to know. I guess there 
> are probably alot of there configuration variables that will fall into 
> this category of non-immediate effect. The code that I wrote when I ran 
> into this issue was something like this:
> 
> GET_DIRECTORY_PROPERTY(OLD_INCLUDE_DIRS INCLUDE_DIRECTORIES)
> SET_DIRECTORY_PROPERTIES(PROPERTIES INCLUDE_DIRECTORIES 
> "${OLD_INCLUDE_DIRS};${ANOTHER_INCLUDE_DIR}")
> ADD_LIBRARY(somelib ${SOME_SRC})
> SET_DIRECTORY_PROPERTIES(PROPERTIES INCLUDE_DIRECTORIES 
> "${OLD_INCLUDE_DIRS};)
> 
> I this may be a bigger topic then just the target includes. And probably 
> comes from the core design of cmake, and could not easily be done? What 
> are your thoughts on this behavior?

The INCLUDE_DIRECTORIES command sets the INCLUDE_DIRECTORIES directory 
property.  Directory properties are accumulated and processed after all 
commands in the directory's CMakeLists.txt file have been executed.  The 
ADD_LIBRARY command just adds a library to the current directory's build 
and the generator uses the directory-level properties for the include 
paths.  Adding a per-target INCLUDE_DIRECTORIES property would allow 
specific targets to override the directory-level setting.  I suggest you 
include this in any feature request you make about this issue in the bug 
tracker.

-Brad


More information about the CMake mailing list