CMake: как создать единую общую библиотеку из всех статических библиотек подпроектов?
У меня есть следующий макет:
top_project
+ subproject1
+ subproject2
Каждый изsubproject1
а такжеsubproject2
создает статическую библиотеку. Я хотел бы связать эти статические библиотеки в единую общую библиотеку наtop_project
уровень.
Информация, которую я собрал до сих пор:
Either compile using-fPic
(necessary on everything but Windows) in order to create position-independent code which will allow linking the static libraries into a single shared library or decompress all static libraries (e.g. using ar
) and re-link them into a shared library (which I think is an inelegant & non-portable solution)
All source files must be given explicitly to the add_library
command: for some reason which I cannot comprehend, simply writing add_library(${PROJECT_NAME} SHARED subproject1 subproject2)
does not work as expected (it essentially creates an empty library & does not register the dependencies properly)
There is an OBJECT library feature in CMake but I don't think it's purpose is really to do what I want.
Какие-нибудь мысли?