rools
rools

Reputation: 1675

Dependency between two subdirectories in CMake

In my root CMakeLists.txt, I have:

add_subdirectory(libs)
add_subdirectory(main)

In libs, I have my own CMakeLists.txt to build external projects. In main, there is a CMakeLists.txt from another repository, which I do not control.

To build main, libs needs to be built. I do not know how to specify the dependency between main and libs.

In libs, with my external projects lib1 and lib2, I used add_dependencies(lib1 lib2) and I have lib2 built before lib1. I did not find how to do that for main and libs.

The difficulty for me is I have to mix external projects and subdirectories, and I did not find any answer or was not able to adapt them.

Upvotes: 5

Views: 2091

Answers (1)

rools
rools

Reputation: 1675

I converted add_subdirectory(main) into an external project. Since it is not possible to make a dependency on subdirectories, I use directly the inner targets. With all that I got:

include(ExternalProject)

add_subdirectory(libs)

ExternalProject_Add(main
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/main
  ...
)
add_dependencies(main lib1 lib2)

Upvotes: 1

Related Questions