diff --git a/cmake/modules/InstallationHelper.cmake b/cmake/modules/InstallationHelper.cmake --- a/cmake/modules/InstallationHelper.cmake +++ b/cmake/modules/InstallationHelper.cmake @@ -3,9 +3,19 @@ include(GNUInstallDirs) macro(install_target _target) + set(RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}") + # CMake installs Windows shared libraries to the RUNTIME destination folder, + # but autotools install them into the LIBRARY destination folder. + # This special case only purpose is to provide identical installation trees + # between CMake and autotools. + get_target_property(_target_type ${_target} TYPE) + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND _target_type STREQUAL "SHARED_LIBRARY") + set(RUNTIME_DESTINATION "${CMAKE_INSTALL_LIBDIR}") + endif() + install( TARGETS ${_target} - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + RUNTIME DESTINATION "${RUNTIME_DESTINATION}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ option(BUILD_BITCOIN_CLI "Build bitcoin-cli" ON) option(BUILD_BITCOIN_TX "Build bitcoin-tx" ON) option(BUILD_BITCOIN_QT "Build bitcoin-qt" ON) +option(BUILD_LIBBITCOINCONSENSUS "Build the bitcoinconsenus library" ON) option(ENABLE_HARDENING "Harden the executables" ON) option(ENABLE_REDUCE_EXPORTS "Reduce the amount of exported symbols" OFF) option(ENABLE_STATIC_LIBSTDCXX "Statically link libstdc++" OFF) @@ -553,3 +554,40 @@ if(BUILD_BITCOIN_QT) add_subdirectory(qt) endif() + +if(BUILD_LIBBITCOINCONSENSUS) + add_library(bitcoinconsensus SHARED $) + target_include_directories(bitcoinconsensus PRIVATE $) + target_compile_definitions(bitcoinconsensus PUBLIC HAVE_CONFIG_H BUILD_BITCOIN_INTERNAL) + + set_target_properties(bitcoinconsensus PROPERTIES PUBLIC_HEADER script/bitcoinconsensus.h) + + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + # On linux: libbitcoinconsensus.so --symlink--> libbitcoinconsensus.so.0 --symlink--> libbitcoinconsensus.so.0.0.0 + set_target_properties(bitcoinconsensus PROPERTIES + # FIXME For compatibility reason with autotools, the version is set + # to 0.0.0 (major being actually 0). This is obviously wrong and the + # version of the library should reflect the version of the release. + # On platforms other than linux, only the major version (0) is used. + # Replace the VERSION line with the statement below to set the + # correct version: + # VERSION "${bitcoin-abc_VERSION}" + VERSION "${bitcoin-abc_VERSION_MAJOR}.0.0" + SOVERSION "${bitcoin-abc_VERSION_MAJOR}" + ) + else() + set_target_properties(bitcoinconsensus PROPERTIES + VERSION "${bitcoin-abc_VERSION_MAJOR}" + ) + endif() + + # For autotools compatibility, rename the library to + # libbitcoinconsensus-0.dll + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set_target_properties(bitcoinconsensus PROPERTIES + OUTPUT_NAME "bitcoinconsensus-${bitcoin-abc_VERSION_MAJOR}" + ) + endif() + + install_target(bitcoinconsensus) +endif() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -178,3 +178,7 @@ ../wallet/test/coinselector_tests.cpp ) endif() + +if(BUILD_LIBBITCOINCONSENSUS) + target_compile_definitions(test_bitcoin PRIVATE HAVE_CONSENSUS_LIB) +endif()