From afbf31f9a32461456908626faa0632cc2687220c Mon Sep 17 00:00:00 2001 From: Anatol Sevastsyan Date: Sat, 25 May 2024 09:37:55 +0300 Subject: [PATCH] Fixed C++20 and macos build (#1976) * added BEAM_CPP_20_STANDARD option * WIP * wip --- 3rdparty/libbitcoin/src/chain/transaction.cpp | 2 +- CMakeLists.txt | 17 ++++++++++++++--- keykeeper/CMakeLists.txt | 6 +++++- utility/CMakeLists.txt | 2 +- wallet/client/CMakeLists.txt | 4 ++-- .../extensions/broadcast_gateway/CMakeLists.txt | 2 +- .../client/extensions/dex_board/CMakeLists.txt | 2 +- wallet/client/extensions/export/CMakeLists.txt | 2 +- .../extensions/news_channels/CMakeLists.txt | 2 +- .../extensions/notifications/CMakeLists.txt | 2 +- .../extensions/offers_board/CMakeLists.txt | 2 +- wallet/core/CMakeLists.txt | 2 +- wallet/core/common.cpp | 4 ++-- wallet/core/common.h | 4 ++-- wasmclient/CMakeLists.txt | 6 +++++- 15 files changed, 39 insertions(+), 20 deletions(-) diff --git a/3rdparty/libbitcoin/src/chain/transaction.cpp b/3rdparty/libbitcoin/src/chain/transaction.cpp index 6763fe327..4cc3e42f1 100644 --- a/3rdparty/libbitcoin/src/chain/transaction.cpp +++ b/3rdparty/libbitcoin/src/chain/transaction.cpp @@ -738,7 +738,7 @@ bool transaction::all_inputs_final() const bool transaction::is_final(size_t block_height, uint32_t block_time) const { - const auto max_locktime = [=, this]() + const auto max_locktime = [=]() { return locktime_ < locktime_threshold ? safe_unsigned(block_height) : block_time; diff --git a/CMakeLists.txt b/CMakeLists.txt index 2437f7427..a421628c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,8 +109,6 @@ target_include_directories(beam INTERFACE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/3rdparty) -target_compile_features(beam INTERFACE cxx_std_20) - file(WRITE ${PROJECT_SOURCE_DIR}/beam_version.gen "${PROJECT_VERSION}") add_definitions(-DBEAM_LIB_VERSION="${BEAM_VERSION}") @@ -121,7 +119,20 @@ endif() include(AddTest) -set(CMAKE_CXX_STANDARD 20) +option(BEAM_CPP_20_STANDARD "Build wallet with C++20 standard" OFF) +message("BEAM_CPP_20_STANDARD is ${BEAM_CPP_20_STANDARD}") + + +if (BEAM_CPP_20_STANDARD) + set(CMAKE_CXX_STANDARD 20) + set(BEAM_INTERFACE_STANDARD, cxx_std_20) +else() + set(CMAKE_CXX_STANDARD 17) + set(BEAM_INTERFACE_STANDARD, cxx_std_17) +endif() + +target_compile_features(beam INTERFACE ${BEAM_INTERFACE_STANDARD}) + set(CMAKE_CXX_STANDARD_REQUIRED ON) set(BEAM_USE_AVX FALSE) diff --git a/keykeeper/CMakeLists.txt b/keykeeper/CMakeLists.txt index 4bdacd8af..e7c4f06b2 100644 --- a/keykeeper/CMakeLists.txt +++ b/keykeeper/CMakeLists.txt @@ -4,7 +4,11 @@ cmake_minimum_required(VERSION 3.13) set(TARGET_NAME wasm-key-keeper) if(EMSCRIPTEN) - set(CMAKE_CXX_STANDARD 20) + if (BEAM_CPP_20_STANDARD) + set(CMAKE_CXX_STANDARD 20) + else() + set(CMAKE_CXX_STANDARD 17) + endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index 74c68c538..595a597ff 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -54,7 +54,7 @@ if (MSVC) endif() add_library(utility STATIC ${UTILITY_SRC} ${IO_SRC}) -target_compile_features(utility PUBLIC cxx_std_20) +target_compile_features(utility PUBLIC ${BEAM_INTERFACE_STANDARD}) if (NOT EMSCRIPTEN) add_library(cli STATIC ${CLI_SRC}) diff --git a/wallet/client/CMakeLists.txt b/wallet/client/CMakeLists.txt index f6d5d7e32..0982ece8d 100644 --- a/wallet/client/CMakeLists.txt +++ b/wallet/client/CMakeLists.txt @@ -33,8 +33,8 @@ target_link_libraries(wallet_client_no_ipfs PRIVATE http ) -target_compile_features(wallet_client PUBLIC cxx_std_20) -target_compile_features(wallet_client_no_ipfs PUBLIC cxx_std_20) +target_compile_features(wallet_client PUBLIC ${BEAM_INTERFACE_STANDARD}) +target_compile_features(wallet_client_no_ipfs PUBLIC ${BEAM_INTERFACE_STANDARD}) add_subdirectory(extensions) diff --git a/wallet/client/extensions/broadcast_gateway/CMakeLists.txt b/wallet/client/extensions/broadcast_gateway/CMakeLists.txt index 34ee8ba06..0e9e16dcb 100644 --- a/wallet/client/extensions/broadcast_gateway/CMakeLists.txt +++ b/wallet/client/extensions/broadcast_gateway/CMakeLists.txt @@ -18,5 +18,5 @@ target_link_libraries(broadcast_gateway wallet_core ) -target_compile_features(broadcast_gateway PUBLIC cxx_std_20) +target_compile_features(broadcast_gateway PUBLIC ${BEAM_INTERFACE_STANDARD}) diff --git a/wallet/client/extensions/dex_board/CMakeLists.txt b/wallet/client/extensions/dex_board/CMakeLists.txt index c9a69d59c..c1b1a4ab2 100644 --- a/wallet/client/extensions/dex_board/CMakeLists.txt +++ b/wallet/client/extensions/dex_board/CMakeLists.txt @@ -16,5 +16,5 @@ target_link_libraries(dex_board wallet ) -target_compile_features(dex_board PUBLIC cxx_std_20) +target_compile_features(dex_board PUBLIC ${BEAM_INTERFACE_STANDARD}) diff --git a/wallet/client/extensions/export/CMakeLists.txt b/wallet/client/extensions/export/CMakeLists.txt index cc3f44138..7ac4e22d1 100644 --- a/wallet/client/extensions/export/CMakeLists.txt +++ b/wallet/client/extensions/export/CMakeLists.txt @@ -21,5 +21,5 @@ if(BEAM_ATOMIC_SWAP_SUPPORT) target_compile_definitions(export PUBLIC BEAM_ATOMIC_SWAP_SUPPORT) endif() -target_compile_features(export PUBLIC cxx_std_20) +target_compile_features(export PUBLIC ${BEAM_INTERFACE_STANDARD}) diff --git a/wallet/client/extensions/news_channels/CMakeLists.txt b/wallet/client/extensions/news_channels/CMakeLists.txt index 3751390ce..f11d3edd3 100644 --- a/wallet/client/extensions/news_channels/CMakeLists.txt +++ b/wallet/client/extensions/news_channels/CMakeLists.txt @@ -24,5 +24,5 @@ target_link_libraries(news_channels wallet_core ) -target_compile_features(news_channels PUBLIC cxx_std_20) +target_compile_features(news_channels PUBLIC ${BEAM_INTERFACE_STANDARD}) diff --git a/wallet/client/extensions/notifications/CMakeLists.txt b/wallet/client/extensions/notifications/CMakeLists.txt index f19e2849d..2bd1fa397 100644 --- a/wallet/client/extensions/notifications/CMakeLists.txt +++ b/wallet/client/extensions/notifications/CMakeLists.txt @@ -17,5 +17,5 @@ target_link_libraries(notifications wallet_core ) -target_compile_features(notifications PUBLIC cxx_std_20) +target_compile_features(notifications PUBLIC ${BEAM_INTERFACE_STANDARD}) diff --git a/wallet/client/extensions/offers_board/CMakeLists.txt b/wallet/client/extensions/offers_board/CMakeLists.txt index 5faa01ab5..239801bbe 100644 --- a/wallet/client/extensions/offers_board/CMakeLists.txt +++ b/wallet/client/extensions/offers_board/CMakeLists.txt @@ -22,5 +22,5 @@ target_link_libraries(swap_offers_board wallet ) -target_compile_features(swap_offers_board PUBLIC cxx_std_20) +target_compile_features(swap_offers_board PUBLIC ${BEAM_INTERFACE_STANDARD}) diff --git a/wallet/core/CMakeLists.txt b/wallet/core/CMakeLists.txt index 6c14251af..637230d8e 100644 --- a/wallet/core/CMakeLists.txt +++ b/wallet/core/CMakeLists.txt @@ -46,7 +46,7 @@ target_link_libraries(wallet_core sqlite ) -target_compile_features(wallet_core PUBLIC cxx_std_20) +target_compile_features(wallet_core PUBLIC ${BEAM_INTERFACE_STANDARD}) if (NOT ANDROID AND NOT IOS) diff --git a/wallet/core/common.cpp b/wallet/core/common.cpp index 65ba5d27f..6ee2bdc12 100644 --- a/wallet/core/common.cpp +++ b/wallet/core/common.cpp @@ -444,13 +444,13 @@ namespace beam::wallet } - bool TxParameters::operator==(const TxParameters& other) + bool TxParameters::operator==(const TxParameters& other) const { return m_ID == other.m_ID && m_Parameters == other.m_Parameters; } - bool TxParameters::operator!=(const TxParameters& other) + bool TxParameters::operator!=(const TxParameters& other) const { return !(*this == other); } diff --git a/wallet/core/common.h b/wallet/core/common.h index 25dd12826..92504dce1 100644 --- a/wallet/core/common.h +++ b/wallet/core/common.h @@ -441,8 +441,8 @@ namespace beam::wallet public: TxParameters(const boost::optional& txID = {}); - bool operator==(const TxParameters& other); - bool operator!=(const TxParameters& other); + bool operator==(const TxParameters& other) const; + bool operator!=(const TxParameters& other) const; const boost::optional& GetTxID() const; diff --git a/wasmclient/CMakeLists.txt b/wasmclient/CMakeLists.txt index f02519308..e647ee749 100644 --- a/wasmclient/CMakeLists.txt +++ b/wasmclient/CMakeLists.txt @@ -4,7 +4,11 @@ cmake_minimum_required(VERSION 3.13) set(TARGET_NAME wasm-client) if(EMSCRIPTEN) - set(CMAKE_CXX_STANDARD 20) + if (BEAM_CPP_20_STANDARD) + set(CMAKE_CXX_STANDARD 20) + else() + set(CMAKE_CXX_STANDARD 17) + endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-value \ -pthread \