Adding a library to a library

CMake newbie here. I have a library, add_library(crypto... that needs to incorporate another library add_library(defprov ... In Unix I can just add libdefprov.a to the $(CC) line. How do I write that in cmake?

Something like that from samples

add_library(defprov ${DEFPROV_SRC_HERE})

add_library(crypto ${CRYPTO_SRC_HERE})
# add defprov public dependency to crypto library
target_link_libraries(crypto PUBLIC defprov)
...

Lean above cmake keywords in documentation https://cmake.org/cmake/help/latest/

HTH.

Short answer: thanks that works! I had been building the source list in an error-prone way (each subdir ending with set...PARENT_SCOPE) but I had errors and typo’s. Since the source are additive, I just do multiple target_sources(defprov ...) and things are much better. Thanks.

1 Like