free-audio / clap

Audio Plugin API
https://cleveraudio.org/
MIT License
1.77k stars 100 forks source link

Provide an installation target with CMake and pkg-config package files #199

Closed robbert-vdh closed 1 year ago

robbert-vdh commented 1 year ago

This makes it easier to consume CLAP using build systems that rely on either CMake's find_package() mechanism or on pkg-config to find package dependencies. For this to work smoothly, the main library target has been renamed to clap so it matches the project name. A clap-core alias has been provided so projects can still refer to it by that name and no existing code will break. The CMake project now also contains the CLAP version number so that applications that include the CLAP library package can check whether that version matches their supported versions.

This has been verified to work with CMake's find_package(), with Meson's dependency() (both when using the .pc file and the CMake config+config-version files). I've also built Surge XT against these headers to make sure nothing changes for existing projects (there shouldn't be any reason to think it would, but you never know).

This resolves #198.

robbert-vdh commented 1 year ago

If you disable subproject downloads (yabridge normally fetches its own copy of the CLAP headers, this is only needed for distro packaging), yabridge 5.0.0 will build as is after installing the CMake library with these changes.

abique commented 1 year ago

We need to make sure version.h is in sync with CMakeLists.txt. Can CMake parse the header to extract the version?

robbert-vdh commented 1 year ago

Oh good idea, I'll make sure to generate clap/version.h from the CMake project version.

Can CMake parse the header to extract the version?

It needs to be done the other way around. If you don't want to require going through a build system (either by including this using CMake, or going through make install once), then I think the best solution is to just keep them in sync manually.

abique commented 1 year ago

https://stackoverflow.com/questions/47066115/cmake-get-version-from-multiline-text-file

abique commented 1 year ago

Generation is problematic, imagine someone uses the submodule but with a different build system.

robbert-vdh commented 1 year ago

We can parse the version from include/clap/version.h with a regexp, but it's going to be a bit messy and it may break future builds. What's your preference, try to parse the header or keep the versions in sync manually?

abique commented 1 year ago

Either we parse the header, or we fail the build if the versions are out of sync.

abique commented 1 year ago

The stack overflow code should work for us I think.

robbert-vdh commented 1 year ago

With Meson you can directly get the value from one or more #defines. Do you happen to know if CMake has something similar? That's much more resilient to errors than trying to parse the header by hand.

abique commented 1 year ago

I can take a look.