Reputation:
My solution consists of a static library and a console application that uses it. The solution is generated from CMakeLists.txt files (top-level file and two files for every project) As I know project dependencies in CMake are managed by changing add_subdirectory() order. However, it does not work for me
Providing the complete top-level file
cmake_minimum_required(VERSION 2.8)
project(vtun CXX)
set(TARGET vtun)
set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS ON)
set(BOOST_ROOT ${MY_BOOST_DIR})
find_package(Boost 1.55.0)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost libraries are required")
endif()
add_subdirectory(vtunlib)
add_subdirectory(console_client)
vtunlib project goes first, but anyway *.sln file does not include dependencies information and console_client is always built first
CMake 3.0, Visual Studio 2013
Upvotes: 3
Views: 3989
Reputation: 10195
Project dependencies in CMake are not managed by changing add_subdirectory()
order. You can specify target dependencies explicitly by add_dependencies command:
add_dependencies(< target> [< target-dependency>]...)
Make a top-level < target> depend on other top-level targets to ensure that they build before < target> does.
or some commands like target_link_libraries do it automatically:
...the build system to make sure the library being linked is up-to-date before the target links.
So in case console_client
links vtunlib
, the command target_link_libraries(console_client vtunlib)
will handle build order automatically.
Upvotes: 7