larsbs / id3v2lib

id3v2lib is a library written in C to read and edit id3 tags from mp3 files.
BSD 2-Clause "Simplified" License
128 stars 44 forks source link

Support building shared libs with CMake. #41

Closed sizeak closed 1 year ago

sizeak commented 1 year ago

This PR adds support for building a shared library with CMake, in addition to a static library. The output library type can be toggled with -DBUILD_SHARED_LIBS=ON or -DBUILD_SHARED_LIBS=OFF.

I've also updated it to rely more on the built in CMake installation behaviour and to use target specific configurations over globals.

CMake now recommended to use lower case for commands etc. so I have updated where needed.

Also closes #40

Happy to discuss any changes needed to get this merged, thanks!

larsbs commented 1 year ago

Hello @simoncent, sorry for the late reply. I'm in the process of modernizing the CMake build myself and I'm interested in using some of this. There's only one thing, you mentioned that it allows building a shared library in addition to a static library, but I'm having a look at the code and it only toggles between generating one and the other, unless I'm missing something?

sizeak commented 1 year ago

No, you're not missing anything, you're absolutely correct. The change I made simply allows you to toggle between building a shared or static library, exactly as you described.

What I meant by "in addition to a static library", is that previously there wasn't a way to easily toggle the build to create a shared library, it was a static build only; additionally, exposing the CMake BUILD_SHARED_LIBS flag as an option is quite common and makes it easier to compose the project with other CMake based projects, i.e. I can set the flag on my top level CMake project of which I pull this library in as a dependency, and pass my CMake environment down and this will then automatically build a shared / static library to match the parent project.

larsbs commented 1 year ago

@simoncent thanks a lot for your reply. I'd make sure to add that option to the final CMake config.