I am trying to migrate a boost-build build system to cmake.
One of the features boost-build has is automatically linking dependencies of dependencies.
For example:
boost-build:
I'm building an executable app
. It depends on lib2
exe app
: [ glob *.cpp ]
/proj/lib2//lib2
;
In turn, lib2
depends on lib1
lib lib2
: [ glob *.cpp ]
/proj/lib1//lib1
;
and lib1
has no dependencies
lib lib1
: [ glob *.cpp ]
;
Both lib1
and lib2
are static libs.
boost-build will automatically add lib1.a
to the linker line for app
because it knows that lib2.a
depends on lib1.a
cmake:
Explicitly stating both lib1
and lib2
in the target_link_libraries
directive works:
lib1:
add_library(lib1 STATIC ${SOURCES})
lib2:
add_library(lib2 STATIC ${SOURCES})
app:
add_executable(app ${SOURCES})
target_link_libraries(app lib1 lib2)
As the number of libraries grows this becomes cumbersome.
target_link_libraries(app lib1 lib2 lib3 lib4 lib5 lib6 lib7 lib8 lib9 ... libN)
Questions:
- Is there a way to specify that
lib2
depends onlib1
- Is there a way to tell
app
to pull inlib2
and whateverlib2
depends on?