Skip to content

Commit

Permalink
[master] ZIL-4812: support compilation on Mac (Zilliqa#3020)
Browse files Browse the repository at this point in the history
* ZIL-4812:
  1. Remove flag enabling duplicate targets (not supported in Xcode).
  2. Remove incorrect CMake variables used to depend on websocketpp.

* ZIL-4812: use the same CMAKE_BUILD_TYPE in our cmake scripts that
          compile dependencies in submodules.

* ZIL-4812:
  1. Suppress some warnings on AppleClang.
  2. Don't include unsupported headers when compiling on Mac.
  3. Temporarily leave an empty implementation in 2 functions displaying
     memory information.

* ZIL-4812: some fixes of unnecessary / incorrct flags & target in
          CMakeLists.txt

* ZIL-4812: fix compilation error when appending to a Json::arrayValue

* ZIL-4812:
  1. Fix some dependencies & include paths.
  2. Protection against multiple inclusion of LLVMExtraTools.cmake
  3. Workaround against an issue related to protobuf when compiled by
     vcpkg on x64-osx-dynamic.
  4. Some CMakeLists.txt cleanup.
  • Loading branch information
yaron-zilliqa authored Sep 22, 2022
1 parent 29be3bb commit 10bce36
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 100 deletions.
111 changes: 50 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,35 @@ project(Zilliqa)
# detect operating system
message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system")

# Workaround: there's a bug related to protobuf 3.9.1 on vcpkg when compiled with
# x64-osx-dynamic (see https://github.com/microsoft/vcpkg/issues/8421).
# This is a simple workaround against this issue.
if (APPLE)
file(CREATE_LINK
${CMAKE_BINARY_DIR}/vcpkg_installed/x64-osx-dynamic/lib
${CMAKE_BINARY_DIR}/vcpkg_installed/x64-osx-dynamic/tools/lib
SYMBOLIC)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#
# check dependencies
#
find_package(Libevent REQUIRED)
find_package(jsoncpp REQUIRED)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

if(NOT TARGET jsonrpc-project)
include(InstallJsonrpccpp)
endif()

include(InstallG3log)
find_package(g3logger CONFIG REQUIRED)

include(InstallCryptoUtils)

include(ProjectSecp256k1)

find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)

find_package(websocketpp REQUIRED)
find_package(leveldb REQUIRED)
#TODO: upgrade to OpenSSL 1.1.1a
find_package(OpenSSL REQUIRED)

include(InstallSchnorr)
include_directories(${SCHNORR_INCLUDE_DIR}/include)
include(FindProtobuf)
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf REQUIRED)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

find_package(PythonLibs REQUIRED)

Expand All @@ -49,59 +50,38 @@ list(GET PY_VERSION_LIST 2 PY_VERSION_PATCH)

set(PY_VERSION "${PY_VERSION_MAJOR}${PY_VERSION_MINOR}")


find_package(Boost COMPONENTS python-py${PY_VERSION} QUIET)
find_package(Boost COMPONENTS python${PY_VERSION} QUIET)
find_package(Boost COMPONENTS python3-py${PY_VERSION} QUIET)



if(Boost_PYTHON-PY${PY_VERSION}_FOUND)

set(PY_COMP_SUFFIX "python-py${PY_VERSION}")

set(PY_COMP_SUFFIX "python-py${PY_VERSION}")
elseif(Boost_PYTHON${PY_VERSION}_FOUND)

set(PY_COMP_SUFFIX "python${PY_VERSION}")

set(PY_COMP_SUFFIX "python${PY_VERSION}")
elseif(Boost_PYTHON3-PY${PY_VERSION}_FOUND)

set(PY_COMP_SUFFIX "python3-py${PY_VERSION}")

set(PY_COMP_SUFFIX "python3-py${PY_VERSION}")
else()

message(FATAL_ERROR "Could not find boost python")

message(FATAL_ERROR "Could not find boost python")
endif()

message(STATUS "Python suffix: ${PY_COMP_SUFFIX}")


message(STATUS "Python Version: ${PY_VERSION_MAJOR}.${PY_VERSION_MINOR}")

find_package(Boost COMPONENTS filesystem system unit_test_framework program_options ${PY_COMP_SUFFIX} REQUIRED)

find_program(HOMEBREW NAMES brew PATH /usr/local/bin)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND HOMEBREW)
execute_process(
#TODO: upgrade to OpenSSL 1.1.1a
COMMAND ${HOMEBREW} --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
#TODO: upgrade to OpenSSL 1.1.1a
# include(InstallOpenSSL)
# set(OPENSSL_USE_STATIC_LIBS TRUE)
# set(OPENSSL_ROOT_DIR ${CMAKE_BINARY_DIR}/openssl)
if(NOT TARGET jsonrpc-project)
include(InstallJsonrpccpp)
endif()

#TODO: upgrade to OpenSSL 1.1.1a
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
include(InstallG3log)
find_package(g3logger CONFIG REQUIRED)

find_package(leveldb REQUIRED)
include(InstallCryptoUtils)
include(ProjectSecp256k1)
include(InstallSchnorr)

include_directories(${SCHNORR_INCLUDE_DIR}/include)
include_directories(${OPENSSL_INCLUDE_DIR})

if(OPENCL_MINE AND CUDA_MINE)
message(FATAL_ERROR "Cannot support OpenCL (OPENCL_MINE=ON) and CUDA (CUDA=ON) at the same time")
Expand Down Expand Up @@ -229,17 +209,10 @@ if(SJ_TEST_SJ_MISSING_MBTXNS)
add_definitions(-DSJ_TEST_SJ_MISSING_MBTXNS)
endif()

include(FindProtobuf)
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIR})

include_directories(${CMAKE_SOURCE_DIR}/src/depends/cryptoutils/include/)

include_directories(${G3LOG_INCLUDE_DIR})

include_directories(${WEBSOCKETPP_INCLUDE_DIR})

# export compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -267,6 +240,10 @@ add_compile_options(-Werror)
add_compile_options(-pedantic)
add_compile_options(-Wextra)

if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
add_compile_options(-Wno-unused-parameter)
endif()

if (THREAD_SANITIZER AND ADDRESS_SANITIZER)
message(FATAL_ERROR "Cannot use ThreadSanitizer (THREAD_SANITIZER=ON) and AddressSanitizer (ADDRESS_SANITIZER=ON) at the same time")
endif()
Expand Down Expand Up @@ -300,7 +277,19 @@ if (LIBFUZZER_SANITIZER)
message(STATUS "Libfuzzer with address and undefined behavior sanitizer enabled")
endif()

set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)
# FIXME: This following
#
# add_custom_target(ctest COMMAND ${CMAKE_CTEST_COMMAND})
#
# needs to be fixed. The same chunk of CMake code (as below:
# if (ENABLE_COVERAGE AND CMAKE_COMPILER_IS_GNUCXX) ....
# exists here, in cryptoutils & Schnorr.
#
# Once fixed, the following if-case for allowing duplciate targets
# (which isn't supported in Xcode) can be removed.
if (NOT ${CMAKE_GENERATOR} STREQUAL "Xcode")
set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)
endif()
if (ENABLE_COVERAGE AND CMAKE_COMPILER_IS_GNUCXX)
if (NOT TESTS)
message(FATAL_ERROR "TESTS is not ON")
Expand Down
1 change: 1 addition & 0 deletions cmake/InstallG3log.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ execute_process(
COMMAND ${CMAKE_COMMAND}
-H${G3LOG_SOURCE_DIR}
-B${G3LOG_BINARY_DIR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DUSE_DYNAMIC_LOGGING_LEVELS=ON
-DG3_SHARED_LIB=OFF
-DCMAKE_INSTALL_PREFIX=${G3LOG_INSTALL_DIR}
Expand Down
6 changes: 3 additions & 3 deletions cmake/InstallJsonrpccpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
set(JSONRPC_CXX_FLAGS "-Wno-deprecated")

set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# Build static lib but suitable to be included in a shared lib.
-DCMAKE_POSITION_INDEPENDENT_CODE=On
-DWITH_COVERAGE=Off
Expand All @@ -42,8 +42,8 @@ set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>

ExternalProject_Add(jsonrpc-project
PREFIX src/depends/jsonrpc
URL https://github.com/Zilliqa/libjson-rpc-cpp/archive/v1.3.0-time-patch.tar.gz
URL_HASH SHA256=cfa2051f24deeba73b92b8f2f7c198eeafb148f7d71e914bfa1a5a33e895f1c8
URL https://github.com/Zilliqa/libjson-rpc-cpp/archive/refs/tags/v1.3.0-time-patch-fix.tar.gz
URL_HASH SHA256=3315c508e6b8154e3c3f489f7f8826a9c4d697045ee101d80e443d759ac6e218
# On Windows it tries to install this dir. Create it to prevent failure.
PATCH_COMMAND cp ${CMAKE_SOURCE_DIR}/vcpkg.json <SOURCE_DIR> && cmake -E make_directory <SOURCE_DIR>/win32-deps/include
CMAKE_ARGS ${CMAKE_ARGS}
Expand Down
2 changes: 1 addition & 1 deletion cmake/InstallSchnorr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ execute_process(
-DCMAKE_INSTALL_PREFIX=${SCHNORR_INSTALL_DIR}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-Wno-dev
RESULT_VARIABLE SCHNORR_INSTALL_RET
OUTPUT_FILE ${SCHNORR_INSTALL_LOG}
Expand Down
2 changes: 2 additions & 0 deletions cmake/LLVMExtraTools.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Additional targets to perform clang-format/clang-tidy
# It requires clang-format/clang-tidy 7.0.0+

include_guard(GLOBAL)

# Get all project files
file(GLOB_RECURSE ALL_CXX_SOURCES
${CMAKE_SOURCE_DIR}/src/*.cpp
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,11 @@ add_custom_command(TARGET zilliqa
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:buildTxBlockHashesToNums> ${CMAKE_BINARY_DIR}/tests/Zilliqa)
target_include_directories(buildTxBlockHashesToNums PUBLIC ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(buildTxBlockHashesToNums PUBLIC "-Wl,--start-group" AccountData Persistence)

if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
target_link_libraries(buildTxBlockHashesToNums PUBLIC AccountData Persistence)
else()
# FIXME: "-Wl,--start-group" was apparently added as a hack for some circular dependency; this shouldn't
# really be required and resolved by fixing the (circular) dependencies.
target_link_libraries(buildTxBlockHashesToNums PUBLIC "-Wl,--start-group" AccountData Persistence)
endif()
2 changes: 1 addition & 1 deletion src/libData/AccountData/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_library(AccountData Account.cpp AccountStoreTemp.cpp AccountStoreBase.cpp AccountStoreSC.cpp AccountStoreTrie.cpp AccountStore.cpp AccountStoreAtomic.cpp Transaction.cpp LogEntry.cpp TransactionReceipt.cpp ScillaClient.cpp BloomFilter.cpp EvmClient.cpp EvmClient.h InvokeType.h AccountStoreSCEvm.cpp)
target_include_directories(AccountData PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_link_libraries (AccountData PUBLIC Server Block BlockHeader Message Trie Utils Persistence TraceableDB EthCrypto ${JSONCPP_LINK_TARGETS})
target_link_libraries (AccountData PUBLIC Server Block BlockHeader Message Trie Utils Persistence TraceableDB EthCrypto jsonrpc::client)
4 changes: 2 additions & 2 deletions src/libEth/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(Eth Eth.cpp)
target_include_directories(Eth PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
target_include_directories(Eth PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(Eth EthCrypto AccountData)

add_library(Filters
Expand All @@ -10,4 +10,4 @@ add_library(Filters
filters/APICache.cpp
)

target_link_libraries(Filters Utils ${JSONCPP_LINK_TARGETS})
target_link_libraries(Filters Utils jsonrpc::client)
15 changes: 7 additions & 8 deletions src/libMessage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER ZilliqaMessage.proto)

add_library (Message ${PROTO_HEADER} ${PROTO_SRC} Messenger.cpp MessengerAccountStoreBase.cpp MessengerAccountStoreTrie.cpp)
#target_compile_options(Message PRIVATE "-Wno-unused-variable")
#target_compile_options(Message PRIVATE "-Wno-unused-parameter")
add_library (MessageCommon STATIC ${PROTO_SRC})
target_link_libraries (MessageCommon PUBLIC protobuf::libprotobuf)

add_library (Message Messenger.cpp MessengerAccountStoreBase.cpp MessengerAccountStoreTrie.cpp)
get_target_property(MESSAGE_COMPILE_FLAGS Message COMPILE_OPTIONS )
message(STATUS "Message compile flags old = ${MESSAGE_COMPILE_FLAGS}")
list(REMOVE_ITEM MESSAGE_COMPILE_FLAGS -Wextra -Werror)
message(STATUS "Message compile flags new = ${MESSAGE_COMPILE_FLAGS}")
set_target_properties(Message PROPERTIES COMPILE_OPTIONS "${MESSAGE_COMPILE_FLAGS}")
target_include_directories (Message PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)
target_link_libraries (Message PUBLIC protobuf::libprotobuf AccountData Block BlockHeader MiningData Utils CoinbaseData)
target_link_libraries (Message PUBLIC MessageCommon AccountData Block BlockHeader MiningData CoinbaseData)

add_library (MessageSWInfo ${PROTO_HEADER} ${PROTO_SRC} MessengerSWInfo.cpp)
#target_compile_options(MessageSWInfo PRIVATE "-Wno-unused-variable")
#target_compile_options(MessageSWInfo PRIVATE "-Wno-unused-parameter")
add_library (MessageSWInfo MessengerSWInfo.cpp)
get_target_property(MESSAGESWINFO_COMPILE_FLAGS MessageSWInfo COMPILE_OPTIONS )
message(STATUS "MessageSWInfo compile flags old = ${MESSAGESWINFO_COMPILE_FLAGS}")
list(REMOVE_ITEM MESSAGESWINFO_COMPILE_FLAGS -Wextra -Werror)
message(STATUS "MessageSWInfo compile flags new = ${MESSAGESWINFO_COMPILE_FLAGS}")
set_target_properties(MessageSWInfo PROPERTIES COMPILE_OPTIONS "${MESSAGESWINFO_COMPILE_FLAGS}")
target_include_directories (MessageSWInfo PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)
target_link_libraries (MessageSWInfo PUBLIC protobuf::libprotobuf Utils)
target_link_libraries (MessageSWInfo PUBLIC MessageCommon)
2 changes: 2 additions & 0 deletions src/libPersistence/ContractStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "libUtils/DataConversion.h"
#include "libUtils/JsonUtils.h"

#ifndef __APPLE__
#include <bits/stdc++.h>
#endif
#include <boost/algorithm/string.hpp>

using namespace std;
Expand Down
14 changes: 13 additions & 1 deletion src/libPythonRunner/PythonRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#if defined(__APPLE__) && defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy"
#endif

#include "PythonRunner.h"

#if defined(__APPLE__) && defined(__clang__)
#pragma clang diagnostic pop
#endif

#include "libUtils/Logger.h"

using namespace boost::python;
Expand Down Expand Up @@ -148,4 +160,4 @@ boost::python::list PythonRunner::VectorToPyList(const vector<string>& str) {
L.append(s);
}
return L;
}
}
19 changes: 6 additions & 13 deletions src/libServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ add_library(Server Server.cpp ScillaIPCServer.cpp JSONConversion.cpp GetWorkServ
add_dependencies(Server jsonrpc-project)

target_include_directories(Server PUBLIC
${PROJECT_SOURCE_DIR}/src
${JSONRPC_INCLUDE_DIR}
${WEBSOCKETPP_INCLUDE_DIR})
${PROJECT_SOURCE_DIR}/src)

target_link_libraries (Server PUBLIC
AccountData
Validator
RemoteStorageDB
Eth
${JSONCPP_LINK_TARGETS}
${WEBSOCKETPP_LIB}
Utils
Constants
POW)
target_link_libraries (Server PUBLIC
jsonrpc::server
AccountData
Validator
Eth)

target_link_libraries (Server PRIVATE
CryptoUtils
Expand Down
2 changes: 1 addition & 1 deletion src/libServer/JSONConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Json::Value JSONConversion::convertBooleanVectorToJson(
Json::Value _json = Json::arrayValue;

for (const auto& i : B) {
_json.append(i);
_json.append(Json::Value(i));
}
return _json;
}
Expand Down
6 changes: 5 additions & 1 deletion src/libUtils/CommonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifdef __linux__
#include <malloc.h>
#endif
#include <chrono>
#include <mutex>

Expand All @@ -25,6 +27,7 @@
using namespace std;

void CommonUtils ::ReleaseSTLMemoryCache() {
#ifdef __linux__
LOG_MARKER();

static mutex relMemoryCacheMutex;
Expand All @@ -34,4 +37,5 @@ void CommonUtils ::ReleaseSTLMemoryCache() {
} else {
LOG_GENERAL(WARNING, "MemoryCache cleanup already in progress!");
}
}
#endif
}
Loading

0 comments on commit 10bce36

Please sign in to comment.