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.