I have a project with both target shared libraries and target executables. Using a minimal example for illustration purpose, the layout is as following:
project
bin
lib
build
CMakeList.txt
foo
CMakeList.txt
foo.hpp
foo.cpp
test_foo
CMakeList.txt
test_foo.cpp
Subdirectory foo creates a shared library foo.so. Subdirectory test_foo creates an executable test_foo, which is linked against foo in the build tree. The build is successful. However during installation I can not figure out how to install foo.so to lib, test_foo to bin, while having bin/test_foo linked against lib/foo.so. I used the install command:
install(TARGETS foo LIBRARY DESTINATION lib)
install(TARGETS foo_test RUNTIME DESTINATION bin)
in the respective subdirectory CMakeList.txt of foo and test_foo. foo.so appeared in lib and test_foo appeared in bin. However bin/test_foo is not linked to lib/foo.so. What's the correct way to do this?