View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0010444CMakeCMakepublic2010-03-19 12:492010-03-25 19:20
ReporterAndrey Vihrov 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product VersionCMake-2-8 
Target VersionFixed in Version 
Summary0010444: Indirect shared library dependencies are added to the final executable
DescriptionIf target A depends on shared library B which itself is a CMake target, then A gets linked directly with libraries LIBS added for B with target_link_libraries (see example below). However, A neither uses LIBS directly, nor does it need them to link properly. Thus the current behavior adds extraneous and useless entries in A's dynamic section.
Additional Information> cat CMakeLists.txt
cmake_minimum_required (VERSION 2.8)

add_library (lib SHARED lib.cpp)
target_link_libraries (lib pthread) # pthread was randomly chosen

add_executable (exe exe.cpp)
target_link_libraries (exe lib)

> make VERBOSE=1
/usr/bin/cmake -H/home/andrey/tmp/bug -B/home/andrey/tmp/bug --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/andrey/tmp/bug/CMakeFiles /home/andrey/tmp/bug/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/andrey/tmp/bug'
make -f CMakeFiles/lib.dir/build.make CMakeFiles/lib.dir/depend
make[2]: Entering directory `/home/andrey/tmp/bug'
cd /home/andrey/tmp/bug && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/andrey/tmp/bug /home/andrey/tmp/bug /home/andrey/tmp/bug /home/andrey/tmp/bug /home/andrey/tmp/bug/CMakeFiles/lib.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/andrey/tmp/bug'
make -f CMakeFiles/lib.dir/build.make CMakeFiles/lib.dir/build
make[2]: Entering directory `/home/andrey/tmp/bug'
/usr/bin/cmake -E cmake_progress_report /home/andrey/tmp/bug/CMakeFiles 2
[ 50%] Building CXX object CMakeFiles/lib.dir/lib.cpp.o
/usr/bin/c++ -Dlib_EXPORTS -fPIC -o CMakeFiles/lib.dir/lib.cpp.o -c /home/andrey/tmp/bug/lib.cpp
Linking CXX shared library liblib.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/lib.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -shared -Wl,-soname,liblib.so -o liblib.so CMakeFiles/lib.dir/lib.cpp.o -lpthread
-------------------------------------------------------------------------------------------------^ As expected, "target_link_libraries (lib pthread)" specifies this
make[2]: Leaving directory `/home/andrey/tmp/bug'
/usr/bin/cmake -E cmake_progress_report /home/andrey/tmp/bug/CMakeFiles 2
[ 50%] Built target lib
make -f CMakeFiles/exe.dir/build.make CMakeFiles/exe.dir/depend
make[2]: Entering directory `/home/andrey/tmp/bug'
cd /home/andrey/tmp/bug && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/andrey/tmp/bug /home/andrey/tmp/bug /home/andrey/tmp/bug /home/andrey/tmp/bug /home/andrey/tmp/bug/CMakeFiles/exe.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/andrey/tmp/bug'
make -f CMakeFiles/exe.dir/build.make CMakeFiles/exe.dir/build
make[2]: Entering directory `/home/andrey/tmp/bug'
/usr/bin/cmake -E cmake_progress_report /home/andrey/tmp/bug/CMakeFiles 1
[100%] Building CXX object CMakeFiles/exe.dir/exe.cpp.o
/usr/bin/c++ -o CMakeFiles/exe.dir/exe.cpp.o -c /home/andrey/tmp/bug/exe.cpp
Linking CXX executable exe
/usr/bin/cmake -E cmake_link_script CMakeFiles/exe.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/exe.dir/exe.cpp.o -o exe -rdynamic liblib.so -lpthread -Wl,-rpath,/home/andrey/tmp/bug
------------------------------------------------------------------------------^ Incorrect, target `exe' does not directly depend on libpthread
make[2]: Leaving directory `/home/andrey/tmp/bug'
/usr/bin/cmake -E cmake_progress_report /home/andrey/tmp/bug/CMakeFiles 1
[100%] Built target exe
make[1]: Leaving directory `/home/andrey/tmp/bug'
/usr/bin/cmake -E cmake_progress_start /home/andrey/tmp/bug/CMakeFiles 0
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0020010)
Alex Neundorf (developer)
2010-03-25 19:19

You can set the LINK_INTERFACE_LIBRARIES property of a shared lib using
target_link_libraries(lib LINK_INTERFACE_LIBRARIES foo bar)

This would mean that everything that links against "lib", will also be linked against foo and bar.
target_link_libraries(lib LINK_INTERFACE_LIBRARIES "")
will make it empty, so when linking against lib, nothing else will be linked automatically.

This is in cmake I think since 2.6.2.

Alex
(0020011)
Alex Neundorf (developer)
2010-03-25 19:20

I'm closing this issue since I think you can do what you need with the LINK_INTERFACE property.
If there is anything left, feel free to reopen it.

Alex

 Issue History
Date Modified Username Field Change
2010-03-19 12:49 Andrey Vihrov New Issue
2010-03-25 19:19 Alex Neundorf Note Added: 0020010
2010-03-25 19:20 Alex Neundorf Note Added: 0020011
2010-03-25 19:20 Alex Neundorf Status new => closed
2010-03-25 19:20 Alex Neundorf Resolution open => no change required


Copyright © 2000 - 2018 MantisBT Team