0

CMake provides BUILD_SHARED_LIBS to allow library targets to be either STATIC or SHARED.

What if I decide that I want to build the target as an object library for aggregation with other targets?

Will this need to be an if/elseif/else tree in every target.

CraigDavid
  • 1,046
  • 1
  • 12
  • 26
  • *but y tho (out of curiosity). what would that achieve for you that you couldn't achieve just by using static libraries? – starball Apr 01 '23 at 01:57
  • 1
    "Will this need to be an if/elseif/else tree in every target." - No, this is not the only solution. You could compute STATIC/SHARED/OBJECT value **once** (with a single is/elseif/else tree), store it to a variable, and use this variable every time when you create a library. Or you could create your own wrapper for add_library (name it, e.g., `add_component`) and implement the logic inside the wrapper. – Tsyvarev Apr 01 '23 at 07:49
  • @user historically, our code base was compiled down to 6 libraries all of which were delivered to customers. Recently, a major customer requested that we deliver one library. Their reasoning is that they have to security scan every library, and are worried about having versioning problems between the 6 libraries. They want one library to deal with from us. CMake's object libraries are supposed to be a good (recommended) way to merge several components together into one. We've been trying to combine static libraries, but it has been very painful. – CraigDavid Apr 02 '23 at 00:20
  • @Tsyvarev very good suggestions. Ideally (imo) there would be some CMake switch to enable this, so I don't have to change the CMake infra of all my dependencies, which live in projects I don't fully control. Maybe I'll log a feature request. – CraigDavid Apr 02 '23 at 00:27
  • "_Their reasoning is that they have to security scan every library_". [How to merge two "ar" static libraries into one?](/q/3821916/11107541), [How to "combine" two static libraries?](/q/61689155/11107541) I don't get it. If they're so fixed on having one library binary, why can't they just merge your static libs manually on their end, and how could they get versioning problems? – starball Apr 02 '23 at 05:22

0 Answers0