From: CryptoManiac Date: Mon, 20 Dec 2021 00:47:14 +0000 (+0300) Subject: CMake file for novacoind (USE_LEVELDB does not work yet) X-Git-Tag: nvc-v0.5.9~106 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=e4e08bd7d780e8237aa073f2b1c24bebd7ea7cfa CMake file for novacoind (USE_LEVELDB does not work yet) --- diff --git a/.gitmodules b/.gitmodules index 4ad9fa1..a43a6ab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://github.com/machinezone/IXWebSocket [submodule "src/additional/leveldb"] path = src/additional/leveldb - url = https://github.com/google/leveldb \ No newline at end of file + url = https://github.com/google/leveldb diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..e592419 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,104 @@ +cmake_minimum_required(VERSION 3.4.1) + +## +## mkdir build && cd build +## +## cmake -DBerkeleyDB_ROOT:STRING=/opt/homebrew/Cellar/berkeley-db@4/4.8.30 .. +## cmake -DUSE_ASM=1 .. +## cmake -DUSE_SSE2 .. +## + +project(novacoind VERSION 0.5.9 LANGUAGES C CXX) + +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set(CMAKE_C_COMPILER_LAUNCHER ccache) + set(CMAKE_CXX_COMPILER_LAUNCHER ccache) +endif(CCACHE_FOUND) + +set (CMAKE_C_FLAGS "-flto -O3 -fPIC -Wno-deprecated -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2") +set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fexceptions -frtti") + +# Add path for custom modules +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/additional/cmake) + +find_package(Boost REQUIRED COMPONENTS atomic chrono filesystem program_options system thread) +find_package(OpenSSL REQUIRED) +add_subdirectory(additional/IXWebSocket) + +if (NOT BerkeleyDB_ROOT) +set(BerkeleyDB_ROOT /usr) +endif() + +set(generic_sources + ${CMAKE_CURRENT_SOURCE_DIR}/addrman.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/alert.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/base58.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/bitcoinrpc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/checkpoints.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/crypter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/db.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/init.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ipcollector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/irc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kernel_worker.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kernelrecord.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/key.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/keystore.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/miner.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/net.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/netbase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/noui.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ntp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/protocol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcblockchain.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcdump.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcmining.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcnet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcrawtransaction.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rpcwallet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/script.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/stun.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sync.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/util.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wallet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/walletdb.cpp +) + +list(APPEND ALL_SOURCES ${generic_sources}) +list(APPEND ALL_LIBRARIES ${BerkeleyDB_ROOT}/lib/libdb_cxx.a ${Boost_LIBRARIES} ixwebsocket OpenSSL::Crypto) + +if(USE_LEVELDB) + add_subdirectory(additional/leveldb) + list(APPEND ALL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/txdb-leveldb.cpp) + list(APPEND ALL_LIBRARIES leveldb) +else() + list(APPEND ALL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/txdb-bdb.cpp) +endif() + +if (USE_ASM) + # Assembler implementation + set(asm_sources + ${CMAKE_CURRENT_SOURCE_DIR}/crypto/scrypt/asm/scrypt-arm.S + ${CMAKE_CURRENT_SOURCE_DIR}/crypto/scrypt/asm/scrypt-x86.S + ${CMAKE_CURRENT_SOURCE_DIR}/crypto/scrypt/asm/scrypt-x86_64.S + ) + + list(APPEND ALL_SOURCES ${generic_sources} ${asm_sources}) +elseif (USE_SSE2) + list( APPEND ALL_SOURCES ${generic_sources} ${CMAKE_CURRENT_SOURCE_DIR}/crypto/scrypt/intrin/scrypt-sse2.cpp ) +else() + list( APPEND ALL_SOURCES ${generic_sources} ${CMAKE_CURRENT_SOURCE_DIR}/crypto/scrypt/generic/scrypt-generic.cpp ) +endif() + +add_executable(novacoind ${ALL_SOURCES}) +target_include_directories(novacoind PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/json ${BerkeleyDB_ROOT}/include ${CMAKE_CURRENT_SOURCE_DIR}/additional/leveldb/helpers ${Boost_INCLUDE_DIRS}) +target_link_libraries(novacoind ${ALL_LIBRARIES}) + +set_property(TARGET novacoind PROPERTY CXX_STANDARD 17) +set_property(TARGET novacoind PROPERTY CXX_STANDARD_REQUIRED TRUE) +set_property(TARGET novacoind PROPERTY CMAKE_WARN_DEPRECATED FALSE) diff --git a/src/additional/cmake/BrewHelper.cmake b/src/additional/cmake/BrewHelper.cmake new file mode 100644 index 0000000..6bf45d2 --- /dev/null +++ b/src/additional/cmake/BrewHelper.cmake @@ -0,0 +1,21 @@ +# Copyright (c) 2018 The Bitcoin developers + +find_program(BREW brew) + +function(find_brew_prefix VAR NAME) + if(NOT BREW) + return() + endif() + + if(DEFINED ${VAR}) + return() + endif() + + execute_process( + COMMAND ${BREW} --prefix ${NAME} + OUTPUT_VARIABLE PREFIX + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(${VAR} ${PREFIX} PARENT_SCOPE) +endfunction() diff --git a/src/additional/cmake/ExternalLibraryHelper.cmake b/src/additional/cmake/ExternalLibraryHelper.cmake new file mode 100644 index 0000000..b4251a0 --- /dev/null +++ b/src/additional/cmake/ExternalLibraryHelper.cmake @@ -0,0 +1,58 @@ +include(FindPackageMessage) + +# Find a library component, set the variables and create an imported target. +# Variable names are compliant with cmake standards. +function(find_component LIB COMPONENT) + cmake_parse_arguments(ARG + "" + "" + "HINTS;INCLUDE_DIRS;INTERFACE_LINK_LIBRARIES;NAMES;PATHS;PATH_SUFFIXES" + ${ARGN} + ) + + # If the component is not requested, skip the search. + if(${LIB}_FIND_COMPONENTS AND NOT ${COMPONENT} IN_LIST ${LIB}_FIND_COMPONENTS) + return() + endif() + + find_library(${LIB}_${COMPONENT}_LIBRARY + NAMES ${ARG_NAMES} + PATHS "" ${ARG_PATHS} + HINTS "" ${ARG_HINTS} + PATH_SUFFIXES "lib" ${ARG_PATH_SUFFIXES} + ) + mark_as_advanced(${LIB}_${COMPONENT}_LIBRARY) + + if(${LIB}_${COMPONENT}_LIBRARY) + # On success, set the standard FOUND variable... + set(${LIB}_${COMPONENT}_FOUND TRUE PARENT_SCOPE) + + # ... and append the library path to the LIBRARIES variable ... + list(APPEND ${LIB}_LIBRARIES + "${${LIB}_${COMPONENT}_LIBRARY}" + ${ARG_INTERFACE_LINK_LIBRARIES} + ) + list(REMOVE_DUPLICATES ${LIB}_LIBRARIES) + set(${LIB}_LIBRARIES ${${LIB}_LIBRARIES} PARENT_SCOPE) + + # ... and create an imported target for the component, if not already + # done. + if(NOT TARGET ${LIB}::${COMPONENT}) + add_library(${LIB}::${COMPONENT} UNKNOWN IMPORTED) + set_target_properties(${LIB}::${COMPONENT} PROPERTIES + IMPORTED_LOCATION "${${LIB}_${COMPONENT}_LIBRARY}" + ) + set_property(TARGET ${LIB}::${COMPONENT} PROPERTY + INTERFACE_INCLUDE_DIRECTORIES ${ARG_INCLUDE_DIRS} + ) + set_property(TARGET ${LIB}::${COMPONENT} PROPERTY + INTERFACE_LINK_LIBRARIES ${ARG_INTERFACE_LINK_LIBRARIES} + ) + endif() + + find_package_message("${LIB}_${COMPONENT}" + "Found ${LIB} component ${COMPONENT}: ${${LIB}_${COMPONENT}_LIBRARY}" + "[${${LIB}_${COMPONENT}_LIBRARY}][${ARG_INCLUDE_DIRS}]" + ) + endif() +endfunction() diff --git a/src/additional/cmake/FindQREncode.cmake b/src/additional/cmake/FindQREncode.cmake new file mode 100644 index 0000000..3794197 --- /dev/null +++ b/src/additional/cmake/FindQREncode.cmake @@ -0,0 +1,58 @@ +# Copyright (c) 2019-2020 The Bitcoin developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#.rst +# FindQREncode +# ------------- +# +# Find the QREncode library. The following +# components are available:: +# qrencode +# +# This will define the following variables:: +# +# QREncode_FOUND - system has QREncode lib +# QREncode_INCLUDE_DIRS - the QREncode include directories +# QREncode_LIBRARIES - Libraries needed to use QREncode +# +# And the following imported target:: +# +# QREncode::qrencode + +include(BrewHelper) +find_brew_prefix(_QREncode_BREW_HINT qrencode) + +find_package(PkgConfig) +pkg_check_modules(PC_QREncode QUIET libqrencode) + +find_path(QREncode_INCLUDE_DIR + NAMES qrencode.h + HINTS ${_QREncode_BREW_HINT} + PATHS ${PC_QREncode_INCLUDE_DIRS} + PATH_SUFFIXES include +) + +set(QREncode_INCLUDE_DIRS "${QREncode_INCLUDE_DIR}") +mark_as_advanced(QREncode_INCLUDE_DIR) + +# TODO: extract a version number. +# For now qrencode does not provide an easy way to extract a version number. + +if(QREncode_INCLUDE_DIR) + include(ExternalLibraryHelper) + find_component(QREncode qrencode + NAMES qrencode + HINTS ${_QREncode_BREW_HINT} + PATHS ${PC_QREncode_LIBRARY_DIRS} + INCLUDE_DIRS ${QREncode_INCLUDE_DIRS} + ) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(QREncode + REQUIRED_VARS + QREncode_INCLUDE_DIR + REASON_FAILURE_MESSAGE "if displaying QR codes is not required, it can be skipped by passing -DENABLE_QRCODE=OFF to the cmake command line" + HANDLE_COMPONENTS +)