HomePhabricator

[CMAKE] Build bitcoinconsensus library both static and shared

Authored by Fabien on Oct 30 2019, 14:09.

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

Committed
FabienOct 30 2019, 14:10
Pushed
FabienOct 30 2019, 14:10
Reviewer
Restricted Project
Differential Revision
D4229: [CMAKE] Build bitcoinconsensus library both static and shared
Parents
rABC8d87d3d4d28b: Add testnet-seed.bchd.cash to seeder lists
Branches
Unknown
Tags
Unknown