2

I have a similar requirement to that described here, CMake: reuse object files built for a lib into another lib target. The answer there was to use object libraries and I have tried them out with success. However like the original poster I wanted to build both the library and use the object files. How to do that wasn't answered. Now I can just have

add_library(foo-objects OBJECT foo.cpp)
add_library(foo_static SHARED $<TARGET_OBJECTS:foo-objects>)

but this leads to twice as many projects appearing in Visual Studio ( which is what I mostly use ) which isn't good when you already have hundreds! Looking at the output VS projects the OBJECT library project actually builds a static library anyway, the SHARED project just uses the object files from the OBJECT project. I'm wondering if there is a way to do this without having two projects. Also is there any reason why $<TARGET_OBJECTS:foo-objects> can't just be populated even for a add_library(foo_static SHARED foo.cpp). The library project builds all the object files anyway?

goneskiing
  • 1,659
  • 1
  • 13
  • 22

0 Answers0