CMake does not pick up INTERFACE_INCLUDE_DIRECTORIES linked library

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}") 

What does this

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

How can it be? When mggle is connected, it must 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 INTERFACE_INCLUDE_DIRECTORIES and add them to the motor, so what am I doing wrong?

  • CMake verison: cmake version 2.8.12.2
  • OS: Arch Linux
+2
source share
1 answer

CMake does some processing at "setup time" and some processing at "generation time".

message() is executed during setup, but linked libraries are checked later when time is generated. Because your included directories depend on linked libraries, inclusion directories are not fully resolved until time is generated.

The file(GENERATE) command evaluates the contents of the generator expression when generating time and writes it to a file, so something like this will write the final included directories in include.txt:

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

If your goal is debugging, try setting CMAKE_VERBOSE_MAKEFILE to 1 to see the compiler command line or try installing

 set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES) 

and he will show you the return route for which each of the included directories for each target comes.

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

+6
source

Source: https://habr.com/ru/post/1271779/


All Articles