From 3aa1aa8a6168c8e1408692e669c9fffb51b9aad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 26 Jul 2023 12:28:22 +0500 Subject: [PATCH 01/16] build: CMake: Make ASM compiler optional --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f458556791..e9ea4d4d38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ project("Gridcoin" VERSION 5.4.5.4 DESCRIPTION "POS-based cryptocurrency that rewards BOINC computation" HOMEPAGE_URL "https://gridcoin.us" - LANGUAGES ASM C CXX + LANGUAGES C CXX ) set(CLIENT_VERSION_IS_RELEASE "false") @@ -114,6 +114,10 @@ if(SYSTEM_UNIVALUE) pkg_check_modules(UNIVALUE REQUIRED IMPORTED_TARGET libunivalue) endif() +if(USE_ASM) + enable_language(ASM) +endif() + if(ENABLE_GUI) find_package(Qt5 ${QT5_MINIMUM_VERSION} REQUIRED COMPONENTS Concurrent From 5fd63fa824a08cc36dc2a31589fa3debbd80f4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 13:41:45 +0500 Subject: [PATCH 02/16] build: CMake: Support bundled Boost This starts a series of commits introducing Hunter Package Manager support. The end goal is to make building with CMake on Windows possible. --- CMakeLists.txt | 55 ++- build-aux/cmake/Hunter/config.cmake | 0 build-aux/cmake/HunterGate.cmake | 543 ++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 +- 4 files changed, 589 insertions(+), 11 deletions(-) create mode 100644 build-aux/cmake/Hunter/config.cmake create mode 100644 build-aux/cmake/HunterGate.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e9ea4d4d38..1eab634228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,25 @@ # CMake support is experimental. Use with caution and report any bugs. cmake_minimum_required(VERSION 3.18) +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build-aux/cmake") + + +# Hunter Package Manager +# ====================== + +# Windows doesn't yet have a package manager that can be used for managing +# dependencies, so we use Hunter on it. +option(HUNTER_ENABLED "Enable Hunter package manager" OFF) +include(HunterGate) +HunterGate( + URL "https://github.com/cpp-pm/hunter/archive/refs/tags/v0.25.3.tar.gz" + SHA1 "0dfbc2cb5c4cf7e83533733bdfd2125ff96680cb" + FILEPATH "${CMAKE_CURRENT_SOURCE_DIR}/build-aux/cmake/Hunter/config.cmake" +) + + +# Project configuration +# ===================== project("Gridcoin" VERSION 5.4.5.4 @@ -37,20 +56,21 @@ string(REPLACE "NDEBUG" "_NDEBUG" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_REL string(REPLACE "NDEBUG" "_NDEBUG" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") -# Load modules from the source tree -# ================================= - -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build-aux/cmake") +# Load CMake modules +# ================== include(CheckCXXSymbolExists) include(CheckFunctionExists) include(CheckIncludeFile) include(CheckPIESupported) +include(CheckSymbolExists) + include(CheckSSE) include(CheckStrerrorR) -include(CheckSymbolExists) +include(HunterGate) include(VersionFromGit) + # Define options # ============== @@ -74,21 +94,32 @@ option(ENABLE_QRENCODE "Enable generation of QR Codes for receiving payments" O option(ENABLE_UPNP "Enable UPnP port mapping support" OFF) option(DEFAULT_UPNP "Turn UPnP on startup" OFF) option(USE_DBUS "Enable DBus support" OFF) + +# Bundled packages option(SYSTEM_BDB "Find system installation of Berkeley DB CXX 5.3" OFF) option(SYSTEM_LEVELDB "Find system installation of leveldb" OFF) option(SYSTEM_SECP256K1 "Find system installation of libsecp256k1 with pkg-config" OFF) option(SYSTEM_UNIVALUE "Find system installation of Univalue with pkg-config" OFF) option(SYSTEM_XXD "Find system xxd binary" OFF) +# Hunter packages +option(BUNDLED_BOOST "Use the bundled version of Boost" ${HUNTER_ENABLED}) -# Find dependencies -# ================= -set(BOOST_MINIMUM_VERSION 1.63.0) +# Handle dependencies +# =================== + set(QT5_MINIMUM_VERSION 5.15.0) +set(BOOST_MINIMUM_VERSION 1.63.0) +set(BOOST_COMPONENTS filesystem iostreams thread) +set(BOOST_HUNTER_COMPONENTS ${BOOST_COMPONENTS}) +if(ENABLE_TESTS) + list(APPEND BOOST_COMPONENTS unit_test_framework) + list(APPEND BOOST_HUNTER_COMPONENTS test) +endif() + find_package(Atomics REQUIRED) -find_package(Boost ${BOOST_MINIMUM_VERSION} COMPONENTS filesystem iostreams thread REQUIRED) find_package(CURL COMPONENTS HTTP HTTPS SSL REQUIRED) find_package(OpenSSL REQUIRED) find_package(Threads REQUIRED) @@ -114,6 +145,11 @@ if(SYSTEM_UNIVALUE) pkg_check_modules(UNIVALUE REQUIRED IMPORTED_TARGET libunivalue) endif() +if(BUNDLED_BOOST) + hunter_add_package(Boost COMPONENTS ${BOOST_HUNTER_COMPONENTS}) +endif() +find_package(Boost ${BOOST_MINIMUM_VERSION} COMPONENTS ${BOOST_COMPONENTS} CONFIG REQUIRED) + if(USE_ASM) enable_language(ASM) endif() @@ -146,7 +182,6 @@ if(ENABLE_UPNP) endif() if(ENABLE_TESTS) - find_package(Boost ${BOOST_MINIMUM_VERSION} COMPONENTS unit_test_framework REQUIRED) enable_testing() if(SYSTEM_XXD) diff --git a/build-aux/cmake/Hunter/config.cmake b/build-aux/cmake/Hunter/config.cmake new file mode 100644 index 0000000000..e69de29bb2 diff --git a/build-aux/cmake/HunterGate.cmake b/build-aux/cmake/HunterGate.cmake new file mode 100644 index 0000000000..17c6d38038 --- /dev/null +++ b/build-aux/cmake/HunterGate.cmake @@ -0,0 +1,543 @@ +# Copyright (c) 2013-2019, Ruslan Baratov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This is a gate file to Hunter package manager. +# Include this file using `include` command and add package you need, example: +# +# cmake_minimum_required(VERSION 3.5) +# +# include("cmake/HunterGate.cmake") +# HunterGate( +# URL "https://github.com/path/to/hunter/archive.tar.gz" +# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" +# ) +# +# project(MyProject) +# +# hunter_add_package(Foo) +# hunter_add_package(Boo COMPONENTS Bar Baz) +# +# Projects: +# * https://github.com/cpp-pm/gate/ +# * https://github.com/cpp-pm/hunter + +option(HUNTER_ENABLED "Enable Hunter package manager support" ON) + +if(HUNTER_ENABLED) + if(CMAKE_VERSION VERSION_LESS "3.5") + message( + FATAL_ERROR + "At least CMake version 3.5 required for Hunter dependency management." + " Update CMake or set HUNTER_ENABLED to OFF." + ) + endif() +endif() + +include(CMakeParseArguments) # cmake_parse_arguments + +option(HUNTER_STATUS_PRINT "Print working status" ON) +option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) +option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON) +set(HUNTER_ROOT "" CACHE FILEPATH "Override the HUNTER_ROOT.") + +set(HUNTER_ERROR_PAGE "https://hunter.readthedocs.io/en/latest/reference/errors") + +function(hunter_gate_status_print) + if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) + foreach(print_message ${ARGV}) + message(STATUS "[hunter] ${print_message}") + endforeach() + endif() +endfunction() + +function(hunter_gate_status_debug) + if(HUNTER_STATUS_DEBUG) + foreach(print_message ${ARGV}) + string(TIMESTAMP timestamp) + message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") + endforeach() + endif() +endfunction() + +function(hunter_gate_error_page error_page) + message("------------------------------ ERROR ------------------------------") + message(" ${HUNTER_ERROR_PAGE}/${error_page}.html") + message("-------------------------------------------------------------------") + message("") + message(FATAL_ERROR "") +endfunction() + +function(hunter_gate_internal_error) + message("") + foreach(print_message ${ARGV}) + message("[hunter ** INTERNAL **] ${print_message}") + endforeach() + message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") + message("") + hunter_gate_error_page("error.internal") +endfunction() + +function(hunter_gate_fatal_error) + cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}") + if("${hunter_ERROR_PAGE}" STREQUAL "") + hunter_gate_internal_error("Expected ERROR_PAGE") + endif() + message("") + foreach(x ${hunter_UNPARSED_ARGUMENTS}) + message("[hunter ** FATAL ERROR **] ${x}") + endforeach() + message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") + message("") + hunter_gate_error_page("${hunter_ERROR_PAGE}") +endfunction() + +function(hunter_gate_user_error) + hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data") +endfunction() + +function(hunter_gate_self root version sha1 result) + string(COMPARE EQUAL "${root}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("root is empty") + endif() + + string(COMPARE EQUAL "${version}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("version is empty") + endif() + + string(COMPARE EQUAL "${sha1}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("sha1 is empty") + endif() + + string(SUBSTRING "${sha1}" 0 7 archive_id) + + if(EXISTS "${root}/cmake/Hunter") + set(hunter_self "${root}") + else() + set( + hunter_self + "${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" + ) + endif() + + set("${result}" "${hunter_self}" PARENT_SCOPE) +endfunction() + +# Set HUNTER_GATE_ROOT cmake variable to suitable value. +function(hunter_gate_detect_root) + # Check CMake variable + if(HUNTER_ROOT) + set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") + return() + endif() + + # Check environment variable + if(DEFINED ENV{HUNTER_ROOT}) + set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") + return() + endif() + + # Check HOME environment variable + if(DEFINED ENV{HOME}) + set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") + return() + endif() + + # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) + if(WIN32) + if(DEFINED ENV{SYSTEMDRIVE}) + set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug( + "HUNTER_ROOT set using SYSTEMDRIVE environment variable" + ) + return() + endif() + + if(DEFINED ENV{USERPROFILE}) + set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug( + "HUNTER_ROOT set using USERPROFILE environment variable" + ) + return() + endif() + endif() + + hunter_gate_fatal_error( + "Can't detect HUNTER_ROOT" + ERROR_PAGE "error.detect.hunter.root" + ) +endfunction() + +function(hunter_gate_download dir) + string( + COMPARE + NOTEQUAL + "$ENV{HUNTER_DISABLE_AUTOINSTALL}" + "" + disable_autoinstall + ) + if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) + hunter_gate_fatal_error( + "Hunter not found in '${dir}'" + "Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" + "Settings:" + " HUNTER_ROOT: ${HUNTER_GATE_ROOT}" + " HUNTER_SHA1: ${HUNTER_GATE_SHA1}" + ERROR_PAGE "error.run.install" + ) + endif() + string(COMPARE EQUAL "${dir}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("Empty 'dir' argument") + endif() + + string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") + endif() + + string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("HUNTER_GATE_URL empty") + endif() + + set(done_location "${dir}/DONE") + set(sha1_location "${dir}/SHA1") + + set(build_dir "${dir}/Build") + set(cmakelists "${dir}/CMakeLists.txt") + + hunter_gate_status_debug("Locking directory: ${dir}") + file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) + hunter_gate_status_debug("Lock done") + + if(EXISTS "${done_location}") + # while waiting for lock other instance can do all the job + hunter_gate_status_debug("File '${done_location}' found, skip install") + return() + endif() + + file(REMOVE_RECURSE "${build_dir}") + file(REMOVE_RECURSE "${cmakelists}") + + file(MAKE_DIRECTORY "${build_dir}") # check directory permissions + + # Disabling languages speeds up a little bit, reduces noise in the output + # and avoids path too long windows error + file( + WRITE + "${cmakelists}" + "cmake_minimum_required(VERSION 3.5)\n" + "if(POLICY CMP0114)\n" + " cmake_policy(SET CMP0114 NEW)\n" + "endif()\n" + "if(POLICY CMP0135)\n" + " cmake_policy(SET CMP0135 NEW)\n" + "endif()\n" + "project(HunterDownload LANGUAGES NONE)\n" + "include(ExternalProject)\n" + "ExternalProject_Add(\n" + " Hunter\n" + " URL\n" + " \"${HUNTER_GATE_URL}\"\n" + " URL_HASH\n" + " SHA1=${HUNTER_GATE_SHA1}\n" + " DOWNLOAD_DIR\n" + " \"${dir}\"\n" + " TLS_VERIFY\n" + " ${HUNTER_TLS_VERIFY}\n" + " SOURCE_DIR\n" + " \"${dir}/Unpacked\"\n" + " CONFIGURE_COMMAND\n" + " \"\"\n" + " BUILD_COMMAND\n" + " \"\"\n" + " INSTALL_COMMAND\n" + " \"\"\n" + ")\n" + ) + + if(HUNTER_STATUS_DEBUG) + set(logging_params "") + else() + set(logging_params OUTPUT_QUIET) + endif() + + hunter_gate_status_debug("Run generate") + + # Need to add toolchain file too. + # Otherwise on Visual Studio + MDD this will fail with error: + # "Could not find an appropriate version of the Windows 10 SDK installed on this machine" + if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") + get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) + set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") + else() + # 'toolchain_arg' can't be empty + set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") + endif() + + string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) + if(no_make) + set(make_arg "") + else() + # Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM + set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") + endif() + + execute_process( + COMMAND + "${CMAKE_COMMAND}" + "-H${dir}" + "-B${build_dir}" + "-G${CMAKE_GENERATOR}" + "${toolchain_arg}" + ${make_arg} + WORKING_DIRECTORY "${dir}" + RESULT_VARIABLE download_result + ${logging_params} + ) + + if(NOT download_result EQUAL 0) + hunter_gate_internal_error( + "Configure project failed." + "To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}" + "In directory ${dir}" + ) + endif() + + hunter_gate_status_print( + "Initializing Hunter workspace (${HUNTER_GATE_SHA1})" + " ${HUNTER_GATE_URL}" + " -> ${dir}" + ) + execute_process( + COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" + WORKING_DIRECTORY "${dir}" + RESULT_VARIABLE download_result + ${logging_params} + ) + + if(NOT download_result EQUAL 0) + hunter_gate_internal_error("Build project failed") + endif() + + file(REMOVE_RECURSE "${build_dir}") + file(REMOVE_RECURSE "${cmakelists}") + + file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") + file(WRITE "${done_location}" "DONE") + + hunter_gate_status_debug("Finished") +endfunction() + +# Must be a macro so master file 'cmake/Hunter' can +# apply all variables easily just by 'include' command +# (otherwise PARENT_SCOPE magic needed) +macro(HunterGate) + if(HUNTER_GATE_DONE) + # variable HUNTER_GATE_DONE set explicitly for external project + # (see `hunter_download`) + set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) + endif() + + # First HunterGate command will init Hunter, others will be ignored + get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) + + if(NOT HUNTER_ENABLED) + # Empty function to avoid error "unknown function" + function(hunter_add_package) + endfunction() + + set( + _hunter_gate_disabled_mode_dir + "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode" + ) + if(EXISTS "${_hunter_gate_disabled_mode_dir}") + hunter_gate_status_debug( + "Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}" + ) + list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}") + endif() + elseif(_hunter_gate_done) + hunter_gate_status_debug("Secondary HunterGate (use old settings)") + hunter_gate_self( + "${HUNTER_CACHED_ROOT}" + "${HUNTER_VERSION}" + "${HUNTER_SHA1}" + _hunter_self + ) + include("${_hunter_self}/cmake/Hunter") + else() + set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}") + + string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) + if(_have_project_name) + hunter_gate_fatal_error( + "Please set HunterGate *before* 'project' command. " + "Detected project: ${PROJECT_NAME}" + ERROR_PAGE "error.huntergate.before.project" + ) + endif() + + cmake_parse_arguments( + HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} + ) + + string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) + string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) + string( + COMPARE + NOTEQUAL + "${HUNTER_GATE_UNPARSED_ARGUMENTS}" + "" + _have_unparsed + ) + string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) + string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) + + if(_have_unparsed) + hunter_gate_user_error( + "HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" + ) + endif() + if(_empty_sha1) + hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") + endif() + if(_empty_url) + hunter_gate_user_error("URL suboption of HunterGate is mandatory") + endif() + if(_have_global) + if(HUNTER_GATE_LOCAL) + hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") + endif() + if(_have_filepath) + hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") + endif() + endif() + if(HUNTER_GATE_LOCAL) + if(_have_global) + hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") + endif() + if(_have_filepath) + hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") + endif() + endif() + if(_have_filepath) + if(_have_global) + hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") + endif() + if(HUNTER_GATE_LOCAL) + hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") + endif() + endif() + + hunter_gate_detect_root() # set HUNTER_GATE_ROOT + + # Beautify path, fix probable problems with windows path slashes + get_filename_component( + HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE + ) + hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") + if(NOT HUNTER_ALLOW_SPACES_IN_PATH) + string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) + if(NOT _contain_spaces EQUAL -1) + hunter_gate_fatal_error( + "HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." + "Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" + "(Use at your own risk!)" + ERROR_PAGE "error.spaces.in.hunter.root" + ) + endif() + endif() + + string( + REGEX + MATCH + "[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" + HUNTER_GATE_VERSION + "${HUNTER_GATE_URL}" + ) + string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) + if(_is_empty) + set(HUNTER_GATE_VERSION "unknown") + endif() + + hunter_gate_self( + "${HUNTER_GATE_ROOT}" + "${HUNTER_GATE_VERSION}" + "${HUNTER_GATE_SHA1}" + _hunter_self + ) + + set(_master_location "${_hunter_self}/cmake/Hunter") + if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter") + # Hunter downloaded manually (e.g. by 'git clone') + set(_unused "xxxxxxxxxx") + set(HUNTER_GATE_SHA1 "${_unused}") + set(HUNTER_GATE_VERSION "${_unused}") + else() + get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) + set(_done_location "${_archive_id_location}/DONE") + set(_sha1_location "${_archive_id_location}/SHA1") + + # Check Hunter already downloaded by HunterGate + if(NOT EXISTS "${_done_location}") + hunter_gate_download("${_archive_id_location}") + endif() + + if(NOT EXISTS "${_done_location}") + hunter_gate_internal_error("hunter_gate_download failed") + endif() + + if(NOT EXISTS "${_sha1_location}") + hunter_gate_internal_error("${_sha1_location} not found") + endif() + file(READ "${_sha1_location}" _sha1_value) + string(TOLOWER "${_sha1_value}" _sha1_value_lower) + string(TOLOWER "${HUNTER_GATE_SHA1}" _HUNTER_GATE_SHA1_lower) + string(COMPARE EQUAL "${_sha1_value_lower}" "${_HUNTER_GATE_SHA1_lower}" _is_equal) + if(NOT _is_equal) + hunter_gate_internal_error( + "Short SHA1 collision:" + " ${_sha1_value} (from ${_sha1_location})" + " ${HUNTER_GATE_SHA1} (HunterGate)" + ) + endif() + if(NOT EXISTS "${_master_location}") + hunter_gate_user_error( + "Master file not found:" + " ${_master_location}" + "try to update Hunter/HunterGate" + ) + endif() + endif() + include("${_master_location}") + set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) + endif() +endmacro() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 012281546c..02dc647772 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -220,7 +220,7 @@ target_include_directories(gridcoin_util PUBLIC target_link_libraries(gridcoin_util PUBLIC -lm ${ATOMICS_LIBRARIES} ${RT_LIBRARIES} ${LIBBDB_CXX} ${LIBLEVELDB} ${LIBSECP256K1} ${LIBUNIVALUE} - Boost::filesystem Boost::headers Boost::iostreams Boost::thread + Boost::boost Boost::filesystem Boost::iostreams Boost::thread CURL::libcurl OpenSSL::Crypto OpenSSL::SSL Threads::Threads From 1e9b371313dc6da57b559c971fddbe44edc286f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 14:17:40 +0500 Subject: [PATCH 03/16] build: CMake: Support bundled OpenSSL --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eab634228..640ca7734c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ option(SYSTEM_XXD "Find system xxd binary" OFF) # Hunter packages option(BUNDLED_BOOST "Use the bundled version of Boost" ${HUNTER_ENABLED}) +option(BUNDLED_OPENSSL "Use the bundled version of OpenSSL" ${HUNTER_ENABLED}) # Handle dependencies @@ -121,7 +122,6 @@ endif() find_package(Atomics REQUIRED) find_package(CURL COMPONENTS HTTP HTTPS SSL REQUIRED) -find_package(OpenSSL REQUIRED) find_package(Threads REQUIRED) find_package(libzip REQUIRED) @@ -150,6 +150,11 @@ if(BUNDLED_BOOST) endif() find_package(Boost ${BOOST_MINIMUM_VERSION} COMPONENTS ${BOOST_COMPONENTS} CONFIG REQUIRED) +if(BUNDLED_OPENSSL) + hunter_add_package(OpenSSL) +endif() +find_package(OpenSSL REQUIRED) + if(USE_ASM) enable_language(ASM) endif() From d43cc504b16f786c139d89968c86c0ac8799e761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 14:17:58 +0500 Subject: [PATCH 04/16] build: CMake: Support bundled cURL --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 640ca7734c..7256ed5aeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ option(SYSTEM_XXD "Find system xxd binary" OFF) # Hunter packages option(BUNDLED_BOOST "Use the bundled version of Boost" ${HUNTER_ENABLED}) +option(BUNDLED_CURL "Use the bundled version of cURL" ${HUNTER_ENABLED}) option(BUNDLED_OPENSSL "Use the bundled version of OpenSSL" ${HUNTER_ENABLED}) @@ -121,7 +122,6 @@ if(ENABLE_TESTS) endif() find_package(Atomics REQUIRED) -find_package(CURL COMPONENTS HTTP HTTPS SSL REQUIRED) find_package(Threads REQUIRED) find_package(libzip REQUIRED) @@ -155,6 +155,13 @@ if(BUNDLED_OPENSSL) endif() find_package(OpenSSL REQUIRED) +if(BUNDLED_CURL) + hunter_add_package(CURL) + find_package(CURL CONFIG REQUIRED) +else() + find_package(CURL REQUIRED) +endif() + if(USE_ASM) enable_language(ASM) endif() From 5456a0d97c567a46124babb93a5327888f9f2abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 14:31:52 +0500 Subject: [PATCH 05/16] build: CMake: Support bundled libzip --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7256ed5aeb..095484f2c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ option(SYSTEM_XXD "Find system xxd binary" OFF) # Hunter packages option(BUNDLED_BOOST "Use the bundled version of Boost" ${HUNTER_ENABLED}) option(BUNDLED_CURL "Use the bundled version of cURL" ${HUNTER_ENABLED}) +option(BUNDLED_LIBZIP "Use the bundled version of libzip" ${HUNTER_ENABLED}) option(BUNDLED_OPENSSL "Use the bundled version of OpenSSL" ${HUNTER_ENABLED}) @@ -123,7 +124,6 @@ endif() find_package(Atomics REQUIRED) find_package(Threads REQUIRED) -find_package(libzip REQUIRED) if(SYSTEM_BDB) find_package(BerkeleyDB 5.3...<5.4 COMPONENTS CXX REQUIRED) @@ -162,6 +162,11 @@ else() find_package(CURL REQUIRED) endif() +if(BUNDLED_LIBZIP) + hunter_add_package(libzip) +endif() +find_package(libzip CONFIG REQUIRED) + if(USE_ASM) enable_language(ASM) endif() From 33c0bdb2e42920cdf63570aeba90497ab9f5afc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 15:31:04 +0500 Subject: [PATCH 06/16] build: CMake: Support bundled Qt --- CMakeLists.txt | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 095484f2c1..e7f9408625 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,12 +107,21 @@ option(BUNDLED_BOOST "Use the bundled version of Boost" ${HUNTER_ENABLED}) option(BUNDLED_CURL "Use the bundled version of cURL" ${HUNTER_ENABLED}) option(BUNDLED_LIBZIP "Use the bundled version of libzip" ${HUNTER_ENABLED}) option(BUNDLED_OPENSSL "Use the bundled version of OpenSSL" ${HUNTER_ENABLED}) +option(BUNDLED_QT "Use the bundled version of Qt" ${HUNTER_ENABLED}) # Handle dependencies # =================== -set(QT5_MINIMUM_VERSION 5.15.0) +set(QT5_MINIMUM_VERSION 5.9.5) +set(QT5_COMPONENTS Concurrent Core Gui LinguistTools Network Widgets) +set(QT5_HUNTER_COMPONENTS qtbase qttools) +if(USE_DBUS) + list(APPEND QT5_COMPONENTS DBus) +endif() +if(ENABLE_TESTS) + list(APPEND QT5_COMPONENTS Test) +endif() set(BOOST_MINIMUM_VERSION 1.63.0) set(BOOST_COMPONENTS filesystem iostreams thread) @@ -172,26 +181,25 @@ if(USE_ASM) endif() if(ENABLE_GUI) - find_package(Qt5 ${QT5_MINIMUM_VERSION} REQUIRED COMPONENTS - Concurrent - Core - Gui - LinguistTools - Network - Widgets - ) - - if(USE_DBUS) - find_package(Qt5 ${QT5_MINIMUM_VERSION} COMPONENTS DBus REQUIRED) - endif() - - if(ENABLE_TESTS) - find_package(Qt5 ${QT5_MINIMUM_VERSION} COMPONENTS Test REQUIRED) + if(BUNDLED_QT) + hunter_add_package(Qt COMPONENTS ${QT5_HUNTER_COMPONENTS}) endif() + find_package(Qt5 ${QT5_MINIMUM_VERSION} COMPONENTS ${QT5_COMPONENTS} REQUIRED) if(ENABLE_QRENCODE) pkg_check_modules(QRENCODE REQUIRED IMPORTED_TARGET libqrencode) endif() + + # Compatibility macros + if(Qt5Core_VERSION VERSION_LESS 5.15.0) + macro(qt_create_translation) + qt5_create_translation(${ARGN}) + endmacro() + + macro(qt_add_translation) + qt5_add_translation(${ARGN}) + endmacro() + endif() endif() if(ENABLE_UPNP) From 01437cb4cd8166d7357e9253f223ef34bcfa4971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 17:30:55 +0500 Subject: [PATCH 07/16] build: CMake: Don't assume that ./configure can be executed --- CMakeLists.txt | 3 ++- src/bdb53/CMakeLists.txt | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7f9408625..3eb6ef52d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,8 @@ find_package(Threads REQUIRED) if(SYSTEM_BDB) find_package(BerkeleyDB 5.3...<5.4 COMPONENTS CXX REQUIRED) else() - find_program(MAKE_EXE NAMES gmake nmake make) + find_program(SH_EXE NAMES sh bash REQUIRED) + find_program(MAKE_EXE NAMES gmake nmake make REQUIRED) endif() if(SYSTEM_LEVELDB) diff --git a/src/bdb53/CMakeLists.txt b/src/bdb53/CMakeLists.txt index 1c98273b73..5af5c845c7 100644 --- a/src/bdb53/CMakeLists.txt +++ b/src/bdb53/CMakeLists.txt @@ -1,7 +1,14 @@ include(ExternalProject) +set(LIBDB_DIST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist") +set(LIBDB_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/libdb_build") +set(libdb_cxx_library "${LIBDB_BUILD_DIR}/libdb_cxx.a") +set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) + + # Configure flags # =============== + set(BDB_FLAGS --disable-java --disable-jdbc @@ -13,9 +20,13 @@ if(ENABLE_PIE) --with-pic ) endif() -if(MINGW) +if(WIN32) + # configure script doesn't support DOS-style paths + cmake_path(SET relative_dist_dir "${LIBDB_DIST_DIR}") + cmake_path(RELATIVE_PATH relative_dist_dir BASE_DIRECTORY "${LIBDB_BUILD_DIR}") list(APPEND BDB_FLAGS --enable-mingw + --srcdir "${relative_dist_dir}" ) endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -40,14 +51,10 @@ set(MAKEOPTS "-j${N}" CACHE STRING "Options for the 'make' program") # External project # ================ -set(LIBDB_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/libdb_build) -set(libdb_cxx_library ${LIBDB_BUILD_DIR}/libdb_cxx.a) -set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) - ExternalProject_Add(BerkeleyDB_Project SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} BINARY_DIR ${LIBDB_BUILD_DIR} - CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/dist/configure ${BDB_FLAGS} + CONFIGURE_COMMAND ${SH_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/dist/configure ${BDB_FLAGS} BUILD_COMMAND COMMAND ${MAKE_EXE} ${MAKEOPTS} clean COMMAND ${MAKE_EXE} ${MAKEOPTS} libdb_cxx.a From 9ceab0145ac2dbcbe03c90eca9a4956d6baf907b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Thu, 30 Nov 2023 00:26:40 +0500 Subject: [PATCH 08/16] build: CMake: Ban MSVC compiler There are lots of build failures using it. Pulling newer Bitcoin code should help. --- CMakeLists.txt | 15 ++++++++++----- src/crypto/CMakeLists.txt | 12 +++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eb6ef52d0..75a021b8f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,17 +43,22 @@ set(COPYRIGHT_HOLDERS_FINAL "The Gridcoin developers") # ======================= set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded) - set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Remove '-DNDEBUG' from flags because we need asserts -string(REPLACE "NDEBUG" "_NDEBUG" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") -string(REPLACE "NDEBUG" "_NDEBUG" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") +if(MSVC) + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + message(FATAL_ERROR "It's not yet possible to build Gridcoin with MSVC") + endif() + set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded) + add_compile_options(/U NDEBUG) +else() + add_compile_options(-UNDEBUG) +endif() # Load CMake modules diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt index f7972902be..7f9811e744 100644 --- a/src/crypto/CMakeLists.txt +++ b/src/crypto/CMakeLists.txt @@ -22,21 +22,27 @@ if(ENABLE_SSE41) list(APPEND LIBGRIDCOIN_CRYPTO gridcoin_crypto_sse41) add_library(gridcoin_crypto_sse41 STATIC sha256_sse41.cpp) target_compile_definitions(gridcoin_crypto_sse41 PRIVATE ENABLE_SSE41) - target_compile_options(gridcoin_crypto_sse41 PRIVATE -msse4.1) + if(NOT MSVC) + target_compile_options(gridcoin_crypto_sse41 PRIVATE -msse4.1) + endif() endif() if(ENABLE_AVX2) list(APPEND LIBGRIDCOIN_CRYPTO gridcoin_crypto_avx2) add_library(gridcoin_crypto_avx2 STATIC sha256_avx2.cpp) target_compile_definitions(gridcoin_crypto_avx2 PRIVATE ENABLE_AVX2) - target_compile_options(gridcoin_crypto_avx2 PRIVATE -mavx -mavx2) + if(NOT MSVC) + target_compile_options(gridcoin_crypto_avx2 PRIVATE -mavx -mavx2) + endif() endif() if(ENABLE_X86_SHANI) list(APPEND LIBGRIDCOIN_CRYPTO gridcoin_crypto_x86_shani) add_library(gridcoin_crypto_x86_shani STATIC sha256_x86_shani.cpp) target_compile_definitions(gridcoin_crypto_x86_shani PRIVATE ENABLE_X86_SHANI) - target_compile_options(gridcoin_crypto_x86_shani PRIVATE -msse4 -msha) + if(NOT MSVC) + target_compile_options(gridcoin_crypto_x86_shani PRIVATE -msse4 -msha) + endif() endif() if(ENABLE_ARM_SHANI) From 6c57ebe942a4434ae82c4bb436d608210d17e9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sun, 3 Dec 2023 16:20:02 +0500 Subject: [PATCH 09/16] build: CMake: Fix build of *.rc files --- src/CMakeLists.txt | 3 +++ src/qt/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02dc647772..e949598fac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -257,6 +257,9 @@ if(ENABLE_DAEMON) if(WIN32) target_sources(gridcoinresearchd PRIVATE gridcoinresearchd-res.rc) + set_source_files_properties(gridcoinresearchd-res.rc PROPERTIES + COMPILE_DEFINITIONS WINDRES_PREPROC + ) endif() if(UNIX AND NOT APPLE) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 3302a30599..c47c1fa13f 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -99,6 +99,9 @@ add_library(gridcoinqt STATIC if(WIN32) target_sources(gridcoinqt PRIVATE res/gridcoinresearch.rc) + set_source_files_properties(res/gridcoinresearch.rc PROPERTIES + COMPILE_DEFINITIONS WINDRES_PREPROC + ) elseif(APPLE) target_sources(gridcoinqt PRIVATE macdockiconhandler.mm From 3886784aa9a3043861b1ccbf46010014ed04b468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sun, 3 Dec 2023 16:38:15 +0500 Subject: [PATCH 10/16] build: CMake: Link with Ws2_32 on Windows --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e949598fac..55a61b1415 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -228,6 +228,10 @@ target_link_libraries(gridcoin_util PUBLIC ) target_link_libraries(gridcoin_util PUBLIC ${LIBGRIDCOIN_CRYPTO}) +if(WIN32) + target_link_libraries(gridcoin_util PUBLIC wsock32 Ws2_32) +endif() + target_compile_definitions(gridcoin_util PUBLIC HAVE_CONFIG_H HAVE_BUILD_INFO From 5b36ce32bdaf489b5afb4578477df0a7bbbc7885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 27 Jan 2024 04:58:29 +0500 Subject: [PATCH 11/16] build: CMake: Use static secp256k1 (if bundled) --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55a61b1415..cc1778d82c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,10 +78,10 @@ else() endif() add_subdirectory(secp256k1 EXCLUDE_FROM_ALL) - target_include_directories(secp256k1 PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/secp256k1/include" + target_include_directories(secp256k1_static PUBLIC + $ ) - set(LIBSECP256K1 secp256k1) + set(LIBSECP256K1 secp256k1_static) endif() if(SYSTEM_UNIVALUE) From b6174350ab9c9c8ed21cf7fb812e1e01a36f2c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 27 Jan 2024 05:18:03 +0500 Subject: [PATCH 12/16] build: CMake: Add option for static runtime Enabled by default on Windows. --- CMakeLists.txt | 12 ++++++++++-- src/CMakeLists.txt | 2 +- src/qt/CMakeLists.txt | 1 + src/qt/test/CMakeLists.txt | 1 + src/test/CMakeLists.txt | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75a021b8f0..8c8ba57859 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,6 @@ if(MSVC) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") message(FATAL_ERROR "It's not yet possible to build Gridcoin with MSVC") endif() - set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded) add_compile_options(/U NDEBUG) else() add_compile_options(-UNDEBUG) @@ -85,6 +84,7 @@ option(ENABLE_GUI "Enable Qt-based GUI" OFF) option(ENABLE_DOCS "Build Doxygen documentation" OFF) option(ENABLE_TESTS "Build tests" OFF) option(LUPDATE "Update translation files" OFF) +option(STATIC_RUNTIME "Link runtime statically" ${WIN32}) # CPU-dependent options option(ENABLE_SSE41 "Build code that uses SSE4.1 intrinsics" ${HAS_SSE41}) @@ -245,12 +245,20 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIE}) # Set compiler flags -if (APPLE) +if(APPLE) add_compile_options(-Wno-error=deprecated-declarations) add_compile_options(-Wno-error=thread-safety-analysis) add_compile_options(-Wno-error=thread-safety-reference) endif() +if(STATIC_RUNTIME) + if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)\$") + list(APPEND RUNTIME_LIBS -static-libgcc -static-libstdc++) + elseif(MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() +endif() + # Set endianness if(CMAKE_CXX_BYTE_ORDER EQUAL BIG_ENDIAN) set(WORDS_BIGENDIAN 1) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc1778d82c..d13071850e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -257,7 +257,7 @@ endif() if(ENABLE_DAEMON) add_executable(gridcoinresearchd gridcoinresearchd.cpp) - target_link_libraries(gridcoinresearchd PUBLIC gridcoin_util) + target_link_libraries(gridcoinresearchd PUBLIC ${RUNTIME_LIBS} gridcoin_util) if(WIN32) target_sources(gridcoinresearchd PRIVATE gridcoinresearchd-res.rc) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index c47c1fa13f..14a7e45b77 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -176,6 +176,7 @@ add_dependencies(gridcoinqt gridcoinqt_l10n) add_executable(gridcoinresearch WIN32 MACOSX_BUNDLE bitcoin.cpp) target_link_libraries(gridcoinresearch PRIVATE + ${RUNTIME_LIBS} Qt5::Widgets gridcoin_util gridcoinqt diff --git a/src/qt/test/CMakeLists.txt b/src/qt/test/CMakeLists.txt index 4717e74597..f6ff90608d 100644 --- a/src/qt/test/CMakeLists.txt +++ b/src/qt/test/CMakeLists.txt @@ -8,6 +8,7 @@ set_target_properties(test_gridcoin-qt PROPERTIES ) target_link_libraries(test_gridcoin-qt PRIVATE + ${RUNTIME_LIBS} Qt5::Test Qt5::Widgets gridcoin_util diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 7bed59e789..1555b347ec 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -56,6 +56,7 @@ add_executable(test_gridcoin add_subdirectory(data) target_link_libraries(test_gridcoin PRIVATE + ${RUNTIME_LIBS} Boost::unit_test_framework gridcoin_util ) From 1376180b6acd2964cc60e12ac5080728de4499c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 27 Jan 2024 05:26:24 +0500 Subject: [PATCH 13/16] build: CMake: Add option to prefer static libs Enabled by default on Windows. --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c8ba57859..7d0b606562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ option(ENABLE_GUI "Enable Qt-based GUI" OFF) option(ENABLE_DOCS "Build Doxygen documentation" OFF) option(ENABLE_TESTS "Build tests" OFF) option(LUPDATE "Update translation files" OFF) +option(STATIC_LIBS "Prefer static variants of system libraries" ${WIN32}) option(STATIC_RUNTIME "Link runtime statically" ${WIN32}) # CPU-dependent options @@ -251,6 +252,11 @@ if(APPLE) add_compile_options(-Wno-error=thread-safety-reference) endif() +if(STATIC_LIBS) + set(CMAKE_LINK_SEARCH_START_STATIC ON) + set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}") +endif() + if(STATIC_RUNTIME) if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)\$") list(APPEND RUNTIME_LIBS -static-libgcc -static-libstdc++) From 407e9f28fd52a9fd48b055c7094f195c22a78a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 27 Jan 2024 06:17:31 +0500 Subject: [PATCH 14/16] build: CMake: Link with shlwapi on Windows --- src/qt/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 14a7e45b77..efeca4de5e 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -151,6 +151,8 @@ if(APPLE) "-framework ApplicationServices" "-framework AppKit" ) +elseif(WIN32) + target_link_libraries(gridcoinqt PUBLIC shlwapi) endif() target_compile_definitions(gridcoinqt PUBLIC HAVE_CONFIG_H) From e9f0dabbdc353989300dcc078e86686fd1ceaeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Wed, 29 Nov 2023 15:37:48 +0500 Subject: [PATCH 15/16] ci: Add CMake CI for MSYS2 --- .github/workflows/cmake-ci.yml | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/.github/workflows/cmake-ci.yml b/.github/workflows/cmake-ci.yml index dd34e2d624..2aa5545a7e 100644 --- a/.github/workflows/cmake-ci.yml +++ b/.github/workflows/cmake-ci.yml @@ -192,3 +192,87 @@ jobs: name: testlog-macos-${{matrix.tag}} path: ${{github.workspace}}/build/Testing/Temporary/LastTest.log retention-days: 7 + + test-msys2: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + env: + CCACHE_DIR: ${{github.workspace}}\ccache + CCACHE_MAXSIZE: 400M + CCACHE_COMPILERCHECK: content + strategy: + matrix: + tag: + - minimal + - no-asm + - gui-full + include: + - tag: no-asm + deps: null + options: -DUSE_ASM=OFF + - tag: gui-full + deps: >- + miniupnpc:p + qrencode:p + qt5-base:p + qt5-tools:p + options: >- + -DENABLE_GUI=ON + -DENABLE_QRENCODE=ON + -DENABLE_UPNP=ON + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup MSYS2 + uses: msys2/setup-msys2@v2 + with: + msystem: UCRT64 + update: true + install: >- + make + ninja + pacboy: >- + ${{matrix.deps}} + boost:p + ccache:p + cmake:p + curl:p + libzip:p + openssl:p + toolchain:p + - name: Configure + run: | + cmake -B ./build -G Ninja \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + ${{matrix.options}} \ + -DBUILD_SHARED_LIBS=OFF -DENABLE_TESTS=ON + - name: Restore cache + uses: actions/cache/restore@v3 + if: always() + with: + path: ${{env.CCACHE_DIR}} + key: ccache-msys2-${{matrix.tag}}-${{github.run_id}} + restore-keys: | + ccache-msys2-${{matrix.tag}}- + - name: Build + run: | + cmake --build ./build -v -j $NUMBER_OF_PROCESSORS + - name: Save cache + uses: actions/cache/save@v3 + if: always() + with: + path: ${{env.CCACHE_DIR}} + key: ccache-msys2-${{matrix.tag}}-${{github.run_id}} + - name: Run tests + run: | + ctest --test-dir ./build -j $NUMBER_OF_PROCESSORS + - name: Upload test logs + uses: actions/upload-artifact@v3 + if: always() + with: + name: testlog-msys-${{matrix.tag}} + path: ${{github.workspace}}\build\Testing\Temporary\LastTest.log + retention-days: 7 From 4856ee18ac6fa5523153a00f8dd36736d705c3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 27 Jan 2024 06:52:34 +0500 Subject: [PATCH 16/16] doc: Add MSYS2 build notes --- doc/README.md | 1 + doc/build-msys2.md | 53 ++++++++++++++++++++++++++++++++++++++++++++ doc/build-windows.md | 3 ++- doc/cmake-options.md | 4 ++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 doc/build-msys2.md diff --git a/doc/README.md b/doc/README.md index eaa6ad72bd..f6eab9e075 100644 --- a/doc/README.md +++ b/doc/README.md @@ -27,6 +27,7 @@ The following are developer notes on how to build Gridcoin on your native platfo - [OS X Build Notes](build-macos.md) - [Unix Build Notes](build-unix.md) - [Windows Build Notes](build-windows.md) +- [Windows (MSYS2) Build Notes](build-msys2.md) - [FreeBSD Build Notes](build-freebsd.md) - [OpenBSD Build Notes](build-openbsd.md) diff --git a/doc/build-msys2.md b/doc/build-msys2.md new file mode 100644 index 0000000000..d4c885a233 --- /dev/null +++ b/doc/build-msys2.md @@ -0,0 +1,53 @@ +Windows (MSYS2) Build Notes +=========================== + +This guide describes how to build gridcoinresearchd, command-line utilities, and GUI on Windows. + +Preparing the Build +------------------- + +First, install [MSYS2](https://www.msys2.org/). All commands below are supposed to be run in the **MSYS2 UCRT64** shell. + +Run the following to install the base dependencies for building: + +```bash +pacman -S make ninja pactoys +pacboy -S boost:p cmake:p curl:p libzip:p openssl:p toolchain:p +pacboy -S qrencode:p qt5-base:p qt5-tools:p # optional for the GUI +``` + +To Build +-------- + +### 1. Configuration + +To configure with gridcoinresearchd: + +```bash +mkdir build && cd build +cmake .. -DBUILD_SHARED_LIBS=OFF +``` + +To configure with GUI: + +```bash +mkdir build && cd build +cmake .. -DENABLE_GUI=ON -DBUILD_SHARED_LIBS=OFF +``` + +> [!NOTE] +> See also: [CMake Build Options](cmake-options.md) + +### 2. Compile + +```bash +cmake --build . # use "-j N" here for N parallel jobs +``` + +### 3. Test + +```bash +cmake .. -DENABLE_TESTS=ON +cmake --build . +ctest . +``` diff --git a/doc/build-windows.md b/doc/build-windows.md index 5f58bf1603..06e13b6943 100644 --- a/doc/build-windows.md +++ b/doc/build-windows.md @@ -1,7 +1,8 @@ WINDOWS BUILD NOTES ==================== -> This document is outdated. +> [!NOTE] +> See also: [Windows (MSYS2) Build Notes](build-msys2.md) Below are some notes on how to build Gridcoin for Windows. diff --git a/doc/cmake-options.md b/doc/cmake-options.md index 95cd8c4163..b38031aad7 100644 --- a/doc/cmake-options.md +++ b/doc/cmake-options.md @@ -23,6 +23,10 @@ ccmake . `cmake .. -DENABLE_PIE=ON -DUSE_ASM=OFF` +* Build a static binary: + + `cmake .. -DSTATIC_LIBS=ON -DSTATIC_RUNTIME=ON` + * Build tests and docs, run `lupdate`: `cmake .. -DENABLE_DOCS=ON -DENABLE_TESTS=ON -DLUPDATE=ON`