PPP
PPP

Reputation: 1840

How to link a library generated by cmake on other directory?

Supppose I have a project with its own CMakeLists.txt:

project/CMakeLists.txt

And I need to compile another Cmake project into a library to use in my project. This other project already has its own CMakeLists.txt which is very complex and I want to use it instead of specifying how to build this lib in my own CMakeLists.txt.

This seems to be the only way:

add_subdirectory(/path/to/my/other/project folder_in_my_project)

but it won't build the outer project first so I can use its generated libraries generated in folder_in_my_project.

It has to be built first, but it won't be built because of the line

add_library(libjrtp STATIC IMPORTED)
SET_PROPERTY(TARGET libjrtp PROPERTY IMPORTED_LOCATION jrtplib/src/libjrtp.a)

It requires libjrtp.a, but libjrtp.a will only be built after everything gets built.

I know I'm asking too much here but there's no documentation about this behavior on cmake docs

Upvotes: 1

Views: 2305

Answers (1)

Kaveh Vahedipour
Kaveh Vahedipour

Reputation: 3477

You need to add the library as dependency.

add_dependencies(libjrtp)

Upvotes: 1

Related Questions