Building both static and shared libraries at the same time #424
Description
Nomadic Labs is using libusb
and hidapi
for the Octez project at https://gitlab.com/tezos/tezos written in Ocaml.
Is there a clean way to compile and install both static and shared libraries at the same time?
@pietro submitted an MR to Alpine aports
to have both static and shared libraries for package libusb-dev
and is now available in Alpine 3.15+
:
https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/23613
We did the same for package hidapi-dev
but the switch to cmake
removed the static libraries from Alpine 3.15
starting with 0.11.0
:
https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/23615
https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/community/hidapi/APKBUILD
At the moment we have no other solutions than building from source or use a custom Alpine package. We copied the current GitHub workflow for Ubuntu and run the configure/build/install twice:
https://gitlab.com/nomadic-labs/hidapi-apk/-/blob/main/APKBUILD#L21
# Shared libraries
cmake -B build/shared -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=TRUE
cmake --build build/shared
cmake --install build/shared
# Static libraries
cmake -B build/static -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=FALSE
cmake --build build/static
cmake --install build/static
I have no experience with cmake
, my concern is that we overwrite the following files instlalling twice:
/usr/lib/cmake/hidapi/hidapi-config-version.cmake
/usr/lib/cmake/hidapi/hidapi-config.cmake
/usr/lib/cmake/hidapi/hidapi-release.cmake
/usr/lib/cmake/hidapi/hidapi.cmake
Note: Alpine aports
MR https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/35251