[CMake] How to add dependency relations between libs and executable

Anatoly Shirokov shirokov_a at mail.ru
Sun Apr 17 07:10:33 EDT 2016


*folder*
CMakeLists.txt:
project(root)
add_subdirectory(proj_b)
add_subdirectory(proj_c)
add_subdirectory(proj_a)

*folder/proj_a*
CMakeList.txt:
project(proj_a)
add_executable(*main *main.cpp)
target_link_libraries(*main **proj_b* *proj_c*)

*folder/proj_b*
CMakeList.txt:
project(proj_b)
add_library(*proj_b* proj_b.cpp)

*folder/proj_c*
CMakeList.txt:
project(proj_c)
add_library(*proj_c *proj_b.cpp)



17.04.2016 11:31, vakano пишет:
> Hi,
>
> The project structure as below:
>
> folder/proj_a folder/proj_b folder/proj_c
>
> proj_a, proj_b, proj_c are in the same level,  proj_a is the main project
> use to generate executable main,
>
> proj_b and proj_c use to generate lib_b, lib_c, then link with executable
> main, my question is how to
>
> add the dependency to let the lib_b and lib_c compile before executable
> main,  I have tried the function,
>
> add_dependencies(main lib_b lib_c) and target_link_libraries(main lib_b
> lib_c), but did not work,
>
> what I want is to achieve the make file dependency setting like:
>
> "${MAKE}"  -f Makefile-${CND_CONF}.mk main
>
> main: lib_b, lib_c
>
> Any suggestion will be highly appreciated!
>
> BTW, as checked from another topic, I use different project name in
> cmakelist( project(proj_a),
>
> project(proj_b), project(proj_c) ), does it block the dependency generation
> automatically?
>
> Thanks,
> Le
>
>
>
> --
> View this message in context: http://cmake.3232098.n2.nabble.com/How-to-add-dependency-relations-between-libs-and-executable-tp7593264.html
> Sent from the CMake mailing list archive at Nabble.com.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160417/0578061a/attachment.html>


More information about the CMake mailing list