Hi list,

What is the differences between PRIVATE and PUBLIC when used with
target_link_libraries?

I read the help and understood that it works like in C++: PRIVATE will
make everything which was PUBLIC before also PRIVATE if inherited
privately.

An example:

  add_library(lib1 INTERFACE)
  target_include_directories(lib1 INTERFACE /tmp)

  add_library(lib2 src2.c)
  target_include_directories(lib2 PUBLIC /bin)
  target_link_libraries(lib2 PRIVATE lib1) # PRIVATE here

  add_library(lib3 src3.c)
  target_include_directories(lib3 PUBLIC /bin)
  target_link_libraries(lib3 PUBLIC lib1) # PUBLIC here
 
  add_executable(exe1 exe.c)
  target_link_libraries(exe1 lib2)

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


When building exe2 both include-dirs (from lib1 and lib3) are present:

  [..] -I/bin -I/tmp  [..]

as they are for exe1 - however I would have expected to not see /tmp
because lib3 and lib1 are linked privately.

Where is my mistake?

Thanks,
--
Patrick.

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to