79184077

Date: 2024-11-13 09:02:45
Score: 0.5
Natty:
Report link

The "object libraries" approach mentioned by other answers doesn't inherit target_link_libraries() of the OBJECT library.

Why not simply build static version first, then build shared version from the static one?

add_library(MyLibStatic STATIC ${SOURCES})
# target_link_libraries(MyLibStatic PRIVATE ThirdPartyLib1 ThirdPartyLib2)
add_library(MyLibShared SHARED)
target_link_libraries(MyLibShared PRIVATE MyLibStatic)

In this way, source files are compiled only once, and third party library dependencies are inherited automatically.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: liberize