MantisBT - CMake
View Issue Details
0016102CMakeCMakepublic2016-05-12 18:092016-05-15 07:45
pboettch 
 
normalmajoralways
closedno change required 
LinuxDebianStretch
CMake 3.5.2 
 
0016102: target_include_directories behaves differently on STATIC and SHARED libraries
Consider the following CMakeLists.txt:

  add_library(lib1 INTERFACE)
  target_include_directories(lib1 INTERFACE /lib1-dir)
 
  add_library(lib3 STATIC src3.c)
  target_include_directories(lib3 PUBLIC /lib3-dir)
  target_link_libraries(lib3 PRIVATE lib1)

  add_executable(exe1 exe.c)
  target_link_libraries(exe1 lib3)

Here lib3 is privately linking with lib1. However, during the compilation of exe.c I see -I/lib1-dir is passed to gcc.

When creating lib3 as a SHARED library it works as expected.

I understand that lib1 needs to be linked to exe1 if lib3 is STATIC and that this not necessary when lib3 is SHARED.

However this logic does not apply for include_directories (or compile-definitions and compile-options), which should, IMHO, never be passed on if link is PRIVATE. Hence this bug-report.
No tags attached.
Issue History
2016-05-12 18:09pboettchNew Issue
2016-05-13 08:56Brad KingNote Added: 0041064
2016-05-13 08:56Brad KingStatusnew => resolved
2016-05-13 08:56Brad KingResolutionopen => no change required
2016-05-13 08:56Brad KingSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=2111#r2111
2016-05-15 07:45pboettchStatusresolved => closed

Notes
(0041064)
Brad King   
2016-05-13 08:56   
This functionality depends on CMP0022 being set to NEW. Use

  cmake_minimum_required(VERSION 2.8.12) # or higher

at the top of your top-level CMakeLists.txt file to make this happen.