1
0
Fork 0
forked from lthn/blockchain
blockchain/CMakeLists.txt
Snider ef776a93cc
Add CMake and Conan presets, update build config (#26)
* Add CMake and Conan presets, update build config

Introduces CMakePresets.json and ConanPresets.json for standardized build configuration. Updates Makefile to use CMake presets, modifies .gitignore for IDE files, and refines conanfile.py to support CI option and preset integration.

* Update Makefile

* Update _on-pr.yml

* Refactor build presets and folder layout for Windows

Updated Makefile and GitHub workflow to use configurable build and configure presets, improving flexibility for different environments. Adjusted CMakePresets.json to fix preset naming and version, and refactored conanfile.py to set build folders based on compiler type, ensuring correct folder structure for MSVC and other compilers.

* Update build presets and CPack config for Windows

Set PRESET_CONFIGURE to 'conan-default' for Windows builds in Makefile and GitHub workflow. Broaden CPack packaging conditions to include additional build types and comment out WIX generator settings for Windows in CPackConfig.cmake.
2025-10-09 00:25:29 +01:00

314 lines
11 KiB
CMake

cmake_minimum_required(VERSION 3.16)
message(STATUS "Using CMake version: ${CMAKE_VERSION}")
set(DISABLE_TOR TRUE CACHE BOOL "Disable TOR library(and related tor-connect submodule)")
PROJECT(Lethean)
set(VERSION "1.0" CACHE STRING "Build version")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(POLICY CMP0043)
cmake_policy(SET CMP0043 NEW)
endif()
if(POLICY CMP0043)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()
if(POLICY CMP0167)
cmake_policy(SET CMP0167 OLD)
endif()
include(DocBuilder)
option (USE_CCACHE "Use ccache if a usable instance is found" OFF)
if (USE_CCACHE)
include(FindCcache)
else()
message(STATUS "ccache deselected")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
add_definitions(-DMOBILE_WALLET_BUILD)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" )
add_definitions(-DIOS_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode -Wno-enum-constexpr-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -Wno-enum-constexpr-conversion")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
add_definitions(-DANDROID_BUILD)
message("Android sdk prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}")
message("Android CMAKE_CXX_COMPILER prefix: ${CMAKE_CXX_COMPILER}")
message("Android ANDROID_LD: ${ANDROID_LD}")
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# build types
if (UNIX AND NOT APPLE)
# single configurations, defaults to Release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
else()
# multi configurations for MSVC and XCode
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
else()
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
endif()
endif()
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}, and built type: ${CMAKE_BUILD_TYPE}")
enable_testing()
set(OPENSSL_USE_STATIC_LIBS TRUE) # link statically
find_package(OpenSSL REQUIRED)
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0)
endif()
set(USE_PCH FALSE CACHE BOOL "Use shared precompiled headers")
set(DISABLE_TOR FALSE CACHE BOOL "Disable TOR library(and related tor-connect submodule)")
set(TESTNET 0 CACHE BOOL "Build TESTNET")
set(BUILD_GUI FALSE CACHE BOOL "Build qt-daemon")
set(USE_BITCOIN_SECP256K1_FOR_ECDSA FALSE CACHE BOOL "Use bitcoin-secp256k1 library for validating ECDSA(instead of OpenSSL)")
if(NOT USE_BITCOIN_SECP256K1_FOR_ECDSA)
add_definitions(-DUSE_OPEN_SSL_FOR_ECDSA)
endif()
add_definitions(-DSTATICLIB)
if(TESTNET)
message("!!!!!! NOTICE: Project is building for TESTNET !!!!!!")
add_definitions(-DTESTNET)
endif()
if(CAKEWALLET)
message("NOTICE: Building libraries for CAKEWALLET")
add_definitions(-DCAKEWALLET)
add_definitions(-DDISABLE_PFR_SERIALIZATION_SELFCHECK)
endif()
set(OPENSSL_USE_STATIC_LIBS TRUE) # link statically
find_package(OpenSSL REQUIRED)
if(DISABLE_TOR)
message("NOTICE: Building with disabled TOR support!")
add_definitions(-DDISABLE_TOR)
endif()
set(STATIC ${MSVC} CACHE BOOL "Link libraries statically")
if (UNIX AND NOT APPLE)
# Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail
find_package(Threads REQUIRED)
endif()
# TODO(unassigned): expand on types and versions, and then refactor.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CLANG TRUE)
endif()
add_definitions("/DBOOST_NO_CXX98_FUNCTION_BASE")
if(WIN32)
add_definitions(-DBOOST_ALL_NO_LIB)
endif()
if(MSVC)
add_definitions("/D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0")
add_compile_options(/EHa /bigobj /Zm1000 /Z7 /MP2 /W3 /GS- /wd4996 /wd4503 /wd4345 /wd4091 /FIinline_c.h)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760 /DEBUG dbghelp.lib crypt32.lib")
if(STATIC)
foreach(VAR CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
string(REPLACE "/MD" "/MT" ${VAR} "${${VAR}}")
endforeach()
endif()
include_directories(SYSTEM src/platform/msc)
configure_file(utils/Directory.Build.props.in ${CMAKE_BINARY_DIR}/Directory.Build.props)
else()
set(ARCH default CACHE STRING "CPU to build for: -march value or default")
if("${ARCH}" STREQUAL "default")
set(ARCH_FLAG "")
else()
set(ARCH_FLAG "-march=${ARCH}")
endif()
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment -Wno-unknown-pragmas -Wno-pragmas")
# if(NOT APPLE)
# set(WARNINGS "${WARNINGS} -Werror")
# endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(WARNINGS "${WARNINGS} -Wno-implicit-function-declaration -Wno-shift-count-overflow -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
else()
set(WARNINGS "${WARNINGS} -Wno-error=write-strings -Wno-error=uninitialized")
endif()
# Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
set(CMAKE_AR "llvm-ar")
set(CMAKE_RANLIB "llvm-ranlib")
endif()
if(MINGW)
set(WARNINGS "${WARNINGS} -Wno-error=unused-value")
set(MINGW_FLAG "-DWIN32_LEAN_AND_MEAN")
include_directories(SYSTEM src/platform/mingw)
else()
set(MINGW_FLAG "")
endif()
if(APPLE)
set(APPLE_FLAG "-DGTEST_USE_OWN_TR1_TUPLE=1")
else()
set(APPLE_FLAG "")
endif()
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wstrict-prototypes -Wno-comment")
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/utils/test-static-assert.c" COMPILE_DEFINITIONS "-std=c++14")
if(STATIC_ASSERT_RES)
set(STATIC_ASSERT_FLAG "")
else()
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -ftemplate-depth-1024 -std=c++14 -D_GNU_SOURCE ${APPLE_FLAG} ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG}")
if (NOT APPLE AND NOT MSVC)
if (CLANG)
set(LLVM_USE_LINKER "gold")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
link_libraries("$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:-lstdc++fs>") # GCC < 9 requires additional linking for std::filesystem. Remove after stop supporting GCC 8.x -- sowle
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
set(DEBUG_FLAGS "-g3 -O0") #set(DEBUG_FLAGS "-g3 -Og")
else()
set(DEBUG_FLAGS "-g3 -O0")
endif()
set(RELEASE_FLAGS "-O3 -ffast-math -DNDEBUG -w")
if(NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto=auto -g3")
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW)
set(RELEASE_FLAGS "${RELEASE_FLAGS} -fno-fat-lto-objects")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}")
if(STATIC)
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
endif()
endif()
# Link Boost statically, consistent with previous setup
if(MSVC OR STATIC)
set(Boost_USE_STATIC_LIBS ON)
if (MSVC)
set(Boost_USE_MULTITHREADED ON)
endif ()
endif()
if(STATIC)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
# Define Boost components
set(BOOST_COMPONENTS system filesystem locale thread timer date_time chrono regex serialization atomic program_options)
if(NOT APPLE)
list(APPEND BOOST_COMPONENTS log)
endif()
message(STATUS "Using Boost ${Boost_VERSION} from Conan")
find_package(miniupnpc REQUIRED)
find_package(ZLIB REQUIRED)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
include_directories(src "${CMAKE_BINARY_DIR}/version")
include_directories(SYSTEM
${Boost_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/contrib/ethereum/libethash
contrib
contrib/epee/include
contrib/jwt-cpp/include
contrib/eos_portable_archive
)
# Append other needed libraries
if(MINGW)
list(APPEND Boost_LIBRARIES ws2_32 mswsock)
elseif(NOT MSVC AND NOT APPLE AND NOT CAKEWALLET AND STATIC)
message("NOTICE: Including static ICU libraries")
list(APPEND Boost_LIBRARIES icui18n.a icuuc.a icudata.a dl)
endif()
set(COMMIT_ID_IN_VERSION ON CACHE BOOL "Include commit ID in version")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
if (NOT COMMIT_ID_IN_VERSION)
set(VERSION "${VERSION}-unknown")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
elseif(DEFINED COMMIT)
string(REPLACE "." "\\." VERSION_RE "${VERSION}")
if(NOT REFS MATCHES "(\\(|, )tag: v${VERSION_RE}(\\)|, )")
set(VERSION "${VERSION}-g${COMMIT}")
endif()
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
else()
find_package(Git QUIET)
if(Git_FOUND OR GIT_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "VERSION=${VERSION}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
else()
message(STATUS "WARNING: Git was not found!")
set(VERSION "${VERSION}-unknown")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
endif()
endif()
set(BUILD_TESTS FALSE CACHE BOOL "Build Lethean tests")
set(DISABLE_MDBX FALSE CACHE BOOL "Exclude mdbx from build(need for a first time)")
if(NOT DISABLE_MDBX)
add_definitions(-DENABLED_ENGINE_MDBX)
endif()
add_subdirectory(contrib)
add_subdirectory(src)
if (BUILD_TESTS)
add_subdirectory(tests)
endif()
include(CPackConfig)