CMake - merge several libraries into one

Say I have executables A, B, C, and I have external libraries X, Y, Z

SET(EXTERNAL_LIB X Y Z)
TARGET_LINK_LIBRARIES(A, ${EXTERNAL_LIB})
TARGET_LINK_LIBRARIES(B, ${EXTERNAL_LIB})
TARGET_LINK_LIBRARIES(C, ${EXTERNAL_LIB})

However, if I visualize this (using the parameter cmake --graphviz, I get a complex two-sided graph with edges from each of the executable files A, B and C to each of the libraries X, Y and Z.

I was wondering if there is a way to combine all the libraries into one.

+3
source share
1 answer

All this depends a little on your platform, compiler and type of libraries:

  • In the case, you can create X, Y, Z yourself: create a new project XYZbuilt from the aggregated source files X, Y and Z. But I think, if it were possible, you would not ask about SO.

  • , (dll/so), . -, X, Y Z A, B C.

  • , SO. , , lib ar.

? , D, X. Y ( libs).

+3

All Articles