HomePhabricator

[CMAKE] Build bitcoinconsensus library both static and shared

Description

[CMAKE] Build bitcoinconsensus library both static and shared

Summary:
The bitcoinconsensus library exports the functions from
src/script/bitcoinconsensus.h:

  • bitcoinconsensus_verify_script
  • bitcoinconsensus_verify_script_with_amount
  • bitcoinconsensus_version

This diff adds a facility to build (if required) and install a shared
library, independently of whether the library already exists as static and/or
shared.

Note that building with BUILD_SHARED_LIBS=ON set will fail and needs a
fix which is outside the scope of this diff (the failure is not related
to this diff).

This is a replacement for D4197 and D4198.

Test Plan:

mkdir -p buildcmake/install && cd buildcmake
cmake -GNinja .. -DCMAKE_INSTALL_PREFIX=install
ninja install

ls install/lib

Should return 1 file and 2 symbolic links:

  • libbitcoinconsensus.so.0.0.0
  • libbitcoinconsensus.so.0 (link to libbitcoinconsensus.so.0.0.0)
  • libbitcoinconsensus.so (link to libbitcoinconsensus.so.0)

    ls install/include

Should return bitcoinconsensus.h.

nm -D --defined-only install/lib/libbitcoinconsensus.so

Check the exported symbols contain the 3 above mentioned functions.

ninja check # There are additional test cases in `script_tests.cpp`

rm -rf *
mkdir install
cmake -GNinja .. -DCMAKE_INSTALL_PREFIX=install \
  -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/OSX.cmake
ninja install

ls install/lib

Should return 1 file and 1 symbolic link:

  • libbitcoinconsensus.0.dylib
  • libbitcoinconsensus.dylib (link to libbitcoinconsensus.0.dylib)

    ls install/include

Should return bitcoinconsensus.h.

rm -rf *
mkdir install
cmake -GNinja .. -DCMAKE_INSTALL_PREFIX=install \
  -DBUILD_BITCOIN_SEEDER=OFF \
  -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/Win64.cmake
ninja install

ls install/lib

Should return 1 file :

  • libbitcoinconsensus-0.dll

    ls install/include

Should return bitcoinconsensus.h.

rm -rf *
cmake -GNinja .. -DCMAKE_INSTALL_PREFIX=install \
  -DBUILD_LIBBITCOINCONSENSUS=OFF
ninja install

ls install

Should have no lib nor include directory.

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D4229

Details

Provenance
FabienAuthored on Oct 30 2019, 14:09
nakihitoPushed on Oct 30 2019, 19:01
Reviewer
Restricted Project
Differential Revision
D4229: [CMAKE] Build bitcoinconsensus library both static and shared
Parents
rSTAGING8d87d3d4d28b: Add testnet-seed.bchd.cash to seeder lists
Branches
Unknown
Tags
Unknown