libnfc icon indicating copy to clipboard operation
libnfc copied to clipboard

Enable selection of static vs shared builds

Open kino-dome opened this issue 5 years ago • 5 comments

By removing the hard-coded SHARED flag in ADD_LIBRARY and setting the ARCHIVE DESTINATION to the library install path, you can choose which type of build you want by passing a BUILD_SHARED_LIBS flag when configuring.

kino-dome avatar Apr 25 '20 23:04 kino-dome

@kino-dome thanks for the contribution but we'd need some documentation added to README.md to cover this option as we as confirmation that default build hasn't changed if no action is taken.

AdamLaurie avatar May 05 '20 10:05 AdamLaurie

I can add that to the docs, no problem. Also if you want to force a default type, we can do it using cmake's option() method and say for instance option( BUILD_SHARED_LIBS "Build libnfc as a shared library. " ON ). May I ask what should the default type be for libnfc, shared or static?

kino-dome avatar May 05 '20 23:05 kino-dome

I believe the current default is to build both.

AdamLaurie avatar May 11 '20 11:05 AdamLaurie

The default was to build .so libs for libnfc and .a for nfc-tools I believe. I'm sure that at least for libnfc itself, it only built shared libs and I couldn't make it to build static libs, hence this PR.

@AdamLaurie Let me know if I should add the mentioned option() parameter and add documentation. Thanks!

kino-dome avatar May 11 '20 21:05 kino-dome

This would be very useful to have for static building of executables.

The proposed change looks good to me, this is how many CMake projects do it.

@kino-dome I propose to also improve libnfc.pc.in such that Libs.private is generated to include e.g. the libusb dependency, so that static linking will work out-of-the-box for projects that use pkg-config to discover libnfc's dependencies.

nh2 avatar Jul 13 '23 18:07 nh2