7

I have this in my cmake-file

get_target_property(moggle_interface_includes moggle INTERFACE_INCLUDE_DIRECTORIES) message("Moggle interface includes: ${moggle_interface_includes}") target_link_libraries(motor moggle ) get_target_property(motor_includes motor INCLUDE_DIRECTORIES) message("MOTOR includes ${motor_includes}") 

Which outputs this

Moggle interface includes: "/home/nick/code/onegame/motor/moggle/include" Motor includes:" " 

How can this be? When moggle is linked, it should also, according to this

CMake will also propagate "usage requirements" from linked library targets. Usage requirements affect compilation of sources in the <target>. They are specified by properties defined on linked targets. During generation of the build system, CMake integrates usage requirement property values with the corresponding build properties for <target>: INTERFACE_COMPILE_DEFINITONS: Appends to COMPILE_DEFINITONS INTERFACE_INCLUDE_DIRECTORIES: Appends to INCLUDE_DIRECTORIES 

... pick up the INTERFACE_INCLUDE_DIRECTORIES and add them to motor's, so what am I doing wrong?

  • CMake verison: cmake version 2.8.12.2
  • OS: Arch Linux
5
  • Did you figure out what the problem was? I'm running into the same issue. Commented Jul 27, 2016 at 10:55
  • @rubenvb The answer I marked correct was the answer. Do you need some additional information? Commented Jul 27, 2016 at 14:45
  • Well, I'm having trouble with an INTERFACE library with INTERFACE_INCLUDE_DIRECTORIES set. These aren't used (it seems) when you add this library to a a project's SHARED library. But perhaps I should get a minimal example and ask my own question ;). Commented Jul 27, 2016 at 16:53
  • SHARED or not shouldn't matter. Have you turned on set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES) and watched the output? Commented Jul 27, 2016 at 22:25
  • I hit an issue with scope with add_subdirectory. I needed to add GLOBAL to add_library. Commented Apr 22, 2020 at 4:40

1 Answer 1

11

CMake does some processing at 'configure time' and some processing at 'generate time'.

The message() is executed at configure time, but linked libraries are only evaluated later at generate time. Because your include directories depend on the linked libraries, the include directories are not fully resolved until generate time.

The file(GENERATE) command evaluates generator expression content at generate time and writes it to a file, so something like this will write the final include directories to includes.txt:

file(GENERATE OUTPUT "includes.txt" CONTENT "$<TARGET_PROPERTY:motor,INCLUDE_DIRECTORIES>\n" ) 

If your purpose is debugging, then try setting CMAKE_VERBOSE_MAKEFILE to 1 to see the compiler command lines or try setting

set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES) 

and it will show you a backtrace for where each of the include directories on each target comes from.

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

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

http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_DEBUG_TARGET_PROPERTIES.html

http://www.cmake.org/cmake/help/git-master/command/file.html

Sign up to request clarification or add additional context in comments.

1 Comment

I was actually trying to figure out why it wasn't showing up in the 'verbose' make, while it should have... in the compilation step, there's no -I/home/nick/code/onegame/motor/moggle/include and it's breaking the build! :( Thanks a lot for that debugging line though, bound to come in useful! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.