1

[I can't find how to properly ask my question to google, so here I am]

My project is roughly organized this way:

Project/
+ Sources/
| + foo1/              # foo1 is a library
| | + bar/
| |   + config.in.h
| |   + bar.h          # includes config.h
| |   + bar.cpp        # includes bar.h
| + foo2/
| ...
| + foon/
| + Tests/
|   + foo1/
|     + bar/
|       + test-bar.cpp # includes bar.h
+ Build-debug/
  + foo1/bar/config.h  # <-- generated from config.h.in

bar.h includes config.h which is generated from config.in.h. And bar.h is included in bar.cpp and test-bar.cpp.

What I'm looking for is a way to specify that all files that depend (i.e. that include directly or indirectly) on bar.h, which ever directory they are in, shall add ${PROJECT_BINARY_DIR}/foo1/bar to the included directories when compiled.

So far I've tried variations on

set_property(
    SOURCE bar.h 
    APPEND_STRING
    PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})

but with no success.

Is what I want to achieve even possible ? And if so, how ?

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83

1 Answers1

3

Specify usage requirements on the bar target instead:

http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#build-specification-and-usage-requirements

See possible duplicates:

CMake target_link_libraries Interface Dependencies

Possible to add an imported library to target_link_libraries that takes care of include directories too?

Getting the compiler to find a Cmake-created file

Update: As you say it's private, you can do this:

add_library(bar ...) # Whatever
add_library(barPrivate INTERFACE)
target_include_directories(barPrivate 
    INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
              ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(barPrivate INTERFACE bar)

Then use

target_link_libraries(the_test barPrivate)

instead of linking to bar.

I'm skeptical of your privateness claim anyway though, and the $<BUILD_INTERFACE> generator expression may be used to differentiate between build-dir and install location usage requirements.

http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html

Community
  • 1
  • 1
steveire
  • 10,694
  • 1
  • 37
  • 48
  • The thing is `bar.h` is actually an internal header file. It isn't meant to be exposed, and neither is the `config.h` file. The only (other) place where I need to "patch" the list of included directories, is in the tests. That's why I was looking for a way to bind the property to one (private) source file and not to a (public) target. I guess I'll resort to the plain old good `INCLUDE_DIRECTORIES()`. Thanks. – Luc Hermitte Sep 30 '14 at 15:46
  • You can use a INTERFACE library for a private target. The link to read is still the same ;p. – steveire Sep 30 '14 at 15:52