Reputation: 11532
I have project with two subdirectories( projects ) inside my directory with own CMakeLists.txt files like
main_dir:
CMakeLists.txt
src/
dir_one/
CMakeLists.txt
src/
dir_two/
CMakeLists.txt
src/
My CMakeLists.txt looks like
.....
target_link_libraries (
main
/usr/lib/dir_one.so
/usr/lib/dir_two.so
)
How to make that dir_one and dir_two are builded static inside main build, to easily deploy ? ( To link statically with main ).
Upvotes: 0
Views: 51
Reputation: 7881
Just use the project name in the target_link_libraries rather than the .so file. CMake will set all the dependencies correctly, and link the output of them.
target_link_libraries(main dir_one dir_two)
Quote from the doc:
If a library name matches that of another target in the project a dependency will automatically be added in the build system to make sure the library being linked is up-to-date before the target links. Item names starting with -, but not -l or -framework, are treated as linker flags.
Upvotes: 2