diff --git a/CMakeLists.txt b/CMakeLists.txt index 516a65b99..9325fcb01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,51 +1,37 @@ +# cmake global project(ethereum) cmake_minimum_required(VERSION 2.8.9) - set(CMAKE_AUTOMOC ON) - cmake_policy(SET CMP0015 NEW) -set(HEADLESS CACHE BOOL 0) -set(LANGUAGES CACHE BOOL 0) +# user defined, defaults +# Normally, set(...CACHE...) creates cache variables, but does not modify them. -if ("x${PARANOIA}" STREQUAL "x") - if ("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") - set(PARANOIA CACHE BOOL 1) - else () - set(PARANOIA CACHE BOOL 0) - endif () -endif () +set(HEADLESS OFF CACHE BOOL "Do not compile GUI (AlethZero)") +set(LANGUAGES OFF CACHE BOOL "Limit build to Serpent/LLL tools") +set(VMTRACE OFF CACHE BOOL "VM tracing and run-time checks (useful for cross-implementation VM debugging)") +set(PARANOIA OFF CACHE BOOL "Additional run-time checks") -if ("x${VMTRACE}" STREQUAL "x") - if ("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") - set(VMTRACE CACHE BOOL 1) - else () - set(VMTRACE CACHE BOOL 0) - endif () +if (LANGUAGES) + add_definitions(-DETH_LANGUAGES) endif () if (PARANOIA) - add_definitions(-DETH_PARANOIA) -else() - set(PARANOIA 0) + if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + add_definitions(-DETH_PARANOIA) + else () + message(FATAL_ERROR "Paranoia requires debug.") + endif () endif () if (VMTRACE) - add_definitions(-DETH_VMTRACE) -else() - set(VMTRACE 0) -endif () - -if (LANGUAGES) - add_definitions(-DETH_LANGUAGES) -else() - set(LANGUAGES 0) + if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + add_definitions(-DETH_VMTRACE) + else () + message(FATAL_ERROR "VM tracing requires debug.") + endif () endif () -if (NOT HEADLESS) - set(HEADLESS 0) -endif() - message("LANGUAGES: ${LANGUAGES}; VMTRACE: ${VMTRACE}; PARANOIA: ${PARANOIA}; HEADLESS: ${HEADLESS}") # Default TARGET_PLATFORM to "linux". @@ -58,13 +44,19 @@ if ("${TARGET_PLATFORM}" STREQUAL "linux") set(CMAKE_THREAD_LIBS_INIT pthread) endif () -# Initialize CXXFLAGS. +# Set default build type to Release w/debug info +# if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) +# set(CMAKE_BUILD_TYPE RelWithDebInfo) +# endif() + +# Initialize CXXFLAGS set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wno-unknown-pragmas -Wextra -DSHAREDLIB") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DETH_DEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG -DETH_RELEASE") set(CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG -DETH_RELEASE") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DETH_DEBUG") +# Windows if ("${TARGET_PLATFORM}" STREQUAL "w64") set(CMAKE_SYSTEM_NAME Windows) @@ -96,6 +88,7 @@ else () set(ETH_SHARED 1) endif() +# Set build platform; to be written to BuildInfo.h if (CMAKE_COMPILER_IS_MINGW) set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/mingw") elseif (CMAKE_COMPILER_IS_MSYS) @@ -104,16 +97,17 @@ elseif (CMAKE_COMPILER_IS_GNUCXX) set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/g++") elseif (CMAKE_COMPILER_IS_MSVC) set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/msvc") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/clang") else () set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/unknown") endif () - message("CXXFLAGS: ${CMAKE_CXX_FLAGS}") #add_definitions("-DETH_BUILD_TYPE=${ETH_BUILD_TYPE}") #add_definitions("-DETH_BUILD_PLATFORM=${ETH_BUILD_PLATFORM}") -# Compiler-specific C++11 activation. +# C++11 check and activation if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) @@ -133,51 +127,43 @@ if("${TARGET_PLATFORM}" STREQUAL "w64") set(CRYPTOPP_ID /usr/x86_64-w64-mingw32/include/cryptopp) else() # Look for available Crypto++ version and if it is >= 5.6.2 - find_path(CRYPTOPP_ID cryptlib.h + find_path(ID cryptlib.h ../cryptopp/src - ../../cryptopp/src) - if(CRYPTOPP_ID STREQUAL "CRYPTOPP_ID-NOTFOUND") - message("Trying system cryptopp...") - find_path(CRYPTOPP_ID cryptlib.h - /usr/include/cryptopp - /usr/include/crypto++ - /usr/local/include/cryptopp - /usr/local/include/crypto++ - /opt/local/include/cryptopp - /opt/local/include/crypto++ - ) - find_library(CRYPTOPP_LS NAMES cryptoppeth cryptopp - PATHS - /usr/lib - /usr/local/lib - /opt/local/lib - ) - else() - message("Local cryptopp OK.") - set(CRYPTOPP_LS ${CRYPTOPP_ID}/../target/build/release/libcryptopp.so) - endif() + ../../cryptopp/src + /usr/include/cryptopp + /usr/include/crypto++ + /usr/local/include/cryptopp + /usr/local/include/crypto++ + /opt/local/include/cryptopp + /opt/local/include/crypto++ + ) + find_library(LS NAMES cryptoppeth cryptopp + ../cryptopp/src/../target/build/release + ../../cryptopp/src/../target/build/release + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + ) - if (CRYPTOPP_LS STREQUAL "CRYPTOPP_LS-NOTFOUND") - message(FATAL_ERROR "Couldn't find Crypto++ version >= 5.6.2.") - else() - message(STATUS "Found Crypto++: ${CRYPTOPP_ID}, ${CRYPTOPP_LS}") - set(_CRYPTOPP_VERSION_HEADER ${CRYPTOPP_ID}/config.h) + if (ID AND LS) + message(STATUS "Found Crypto++: ${ID}, ${LS}") + set(_CRYPTOPP_VERSION_HEADER ${ID}/config.h) if(EXISTS ${_CRYPTOPP_VERSION_HEADER}) file(STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION REGEX "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$") string(REGEX REPLACE "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION ${_CRYPTOPP_VERSION}) if(${_CRYPTOPP_VERSION} LESS 562) - set(CRYPTOPP_ID CACHE FILEPATH "" FORCE) - set(CRYPTOPP_LS CACHE FILEPATH "" FORCE) - message(STATUS "Crypto++ version found is smaller than 5.6.2.") + message(FATAL_ERROR "Crypto++ version found is smaller than 5.6.2.") else() + set(CRYPTOPP_ID ${ID} CACHE FILEPATH "") + set(CRYPTOPP_LS ${LS} CACHE FILEPATH "") message(STATUS "Crypto++ found and version greater or equal to 5.6.2") endif() endif() + else() + message(STATUS "Crypto++ Not Found: ${CRYPTOPP_ID}, ${CRYPTOPP_LS}") endif() - # Not really worth caching. We want to reevaluate anyway. - mark_as_advanced(CRYPTOPP_ID CRYPTOPP_LS) - find_path( LEVELDB_ID leveldb/db.h /usr/include /usr/local/include @@ -310,40 +296,32 @@ else() endif() if(CRYPTOPP_ID) -include_directories(${CRYPTOPP_ID}) + include_directories(${CRYPTOPP_ID}) endif() if(PYTHON_ID) -include_directories(${PYTHON_ID}) + include_directories(${PYTHON_ID}) endif() if(MINIUPNPC_ID) -include_directories(${MINIUPNPC_ID}) + include_directories(${MINIUPNPC_ID}) endif() if(LEVELDB_ID) -include_directories(${LEVELDB_ID}) + include_directories(${LEVELDB_ID}) endif() if(READLINE_ID) -include_directories(${READLINE_ID}) + include_directories(${READLINE_ID}) endif() if(JSONRPC_ID) include_directories(${JSONRPC_ID}) endif() -# if (NOT APPLE) -# link_directories(${CRYPTOPP_LS}) -# link_directories(${LEVELDB_LS}) -# link_directories(${MINIUPNPC_LS}) -# link_directories(${PYTHON_LS}) -# link_directories(${READLINE_LS}) -# link_directories(${JSONRPC_LS}) -# endif() - # Generate header file containing useful build information add_custom_target(BuildInfo.h ALL COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/BuildInfo.sh ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BUILD_TYPE} ${ETH_BUILD_PLATFORM}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") link_directories(/usr/local/lib) include_directories(/usr/local/include) -endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +endif() add_subdirectory(libethential) add_subdirectory(libevmface) @@ -357,34 +335,40 @@ endif() add_subdirectory(lllc) add_subdirectory(sc) if (NOT LANGUAGES) -add_subdirectory(secp256k1) -add_subdirectory(libethcore) -add_subdirectory(libevm) -add_subdirectory(libethereum) -add_subdirectory(test) -add_subdirectory(eth) -if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") - add_subdirectory(exp) -endif () -if(NOT ("${TARGET_PLATFORM}" STREQUAL "w64")) - add_subdirectory(neth) -endif () -if(QTQML) -add_definitions(-DETH_QTQML) -endif() + add_subdirectory(secp256k1) + add_subdirectory(libethcore) + add_subdirectory(libevm) + add_subdirectory(libethereum) + add_subdirectory(test) + add_subdirectory(eth) + if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") + add_subdirectory(exp) + endif () + if(NOT ("${TARGET_PLATFORM}" STREQUAL "w64")) + add_subdirectory(neth) + endif () + if(QTQML) + add_definitions(-DETH_QTQML) + endif() -if(NOT HEADLESS) - add_subdirectory(libqethereum) - add_subdirectory(alethzero) -if(QTQML) - add_subdirectory(walleth) -endif() -endif() + if(NOT HEADLESS) + if ("${TARGET_PLATFORM}" STREQUAL "w64") + cmake_policy(SET CMP0020 NEW) + endif () + + add_subdirectory(libqethereum) + add_subdirectory(alethzero) + if(QTQML) + add_subdirectory(walleth) + endif() + endif() endif() +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(SRC_LIST BuildInfo.h) + enable_testing() add_test(NAME alltests WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test COMMAND testeth) -#unset(HEADLESS CACHE) #unset(TARGET_PLATFORM CACHE) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index 85346bccd..9551dd403 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -1,30 +1,18 @@ -cmake_policy(SET CMP0015 NEW) - -if ("${TARGET_PLATFORM}" STREQUAL "w64") - cmake_policy(SET CMP0020 NEW) -endif () - - set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. SRC_LIST) - include_directories(..) -# Find Qt5 for Apple and update src_list for windows if (APPLE) - # homebrew defaults to qt4 and installs qt5 as 'keg-only' - # which places it into /usr/local/opt insteadof /usr/local. - + # Add homebrew path for qt5 set(CMAKE_PREFIX_PATH /usr/local/opt/qt5) include_directories(/usr/local/opt/qt5/include /usr/local/include) elseif ("${TARGET_PLATFORM}" STREQUAL "w64") set(SRC_LIST ${SRC_LIST} ../windows/qt_plugin_import.cpp) include_directories(/usr/x86_64-w64-mingw32/include /usr/x86_64-w64-mingw32/include/QtCore /usr/x86_64-w64-mingw32/include/QtGui /usr/x86_64-w64-mingw32/include/QtQuick /usr/x86_64-w64-mingw32/include/QtQml /usr/x86_64-w64-mingw32/include/QtNetwork /usr/x86_64-w64-mingw32/include/QtWidgets /usr/x86_64-w64-mingw32/include/QtWebKit /usr/x86_64-w64-mingw32/include/QtWebKitWidgets) elseif (UNIX) - set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ";$ENV{QTDIR}/lib/cmake") + set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ";$ENV{QTDIR}/lib/cmake") endif () - find_package(Qt5Core REQUIRED) find_package(Qt5Gui REQUIRED) find_package(Qt5Quick REQUIRED) @@ -33,12 +21,12 @@ find_package(Qt5Network REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5WebKit REQUIRED) find_package(Qt5WebKitWidgets REQUIRED) + qt5_wrap_ui(ui_Main.h Main.ui) # Set name of binary and add_executable() if (APPLE) set(EXECUTEABLE AlethZero) - set(CMAKE_INSTALL_PREFIX ./) set(BIN_INSTALL_DIR ".") set(DOC_INSTALL_DIR ".") @@ -50,9 +38,14 @@ if (APPLE) set(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}") set(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}") set(MACOSX_BUNDLE_BUNDLE_NAME ${EXECUTEABLE}) + set(MACOSX_BUNDLE_ICON_FILE alethzero) include(BundleUtilities) - add_executable(${EXECUTEABLE} MACOSX_BUNDLE Main.ui ${SRC_LIST}) + add_executable(${EXECUTEABLE} MACOSX_BUNDLE alethzero.icns Main.ui ${SRC_LIST}) + set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in") + SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS) + SET_SOURCE_FILES_PROPERTIES(${MACOSX_BUNDLE_ICON_FILE}.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") + else () set(EXECUTEABLE alethzero) add_executable(${EXECUTEABLE} Main.ui ${SRC_LIST}) @@ -62,36 +55,29 @@ qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets) target_link_libraries(${EXECUTEABLE} qethereum ethereum evm ethcore secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface ethential) if (APPLE) - set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in") - - SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS) - - # This is a workaround for when the build-type defaults to Debug, and when a multi-config generator like xcode is used, where the type - # will not be set but defaults to release. - set(generator_lowercase "${CMAKE_GENERATOR}") - string(TOLOWER "${CMAKE_GENERATOR}" generator_lowercase) - if ("${generator_lowercase}" STREQUAL "xcode") - # TODO: Not sure how to resolve this. Possibly \${TARGET_BUILD_DIR} - set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}/Debug") + # First have qt5 install plugins and frameworks + add_custom_command(TARGET ${EXECUTEABLE} POST_BUILD + COMMAND /usr/local/opt/qt5/bin/macdeployqt ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTEABLE}.app + WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + + # This tool and next will inspect linked libraries in order to determine which dependencies are required + if (${CMAKE_CFG_INTDIR} STREQUAL ".") + set(APP_BUNDLE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${EXECUTEABLE}.app") else () - set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}") + set(APP_BUNDLE_PATH "${CMAKE_CURRENT_BINARY_DIR}/\$ENV{CONFIGURATION}/${EXECUTEABLE}.app") endif () - - set(APPS ${binary_build_dir}/${EXECUTEABLE}.app) - - # This tool and the next will automatically looked at the linked libraries in order to determine what dependencies are required. Thus, target_link_libaries only needs to add ethereum and secp256k1 (above) install(CODE " include(BundleUtilities) set(BU_CHMOD_BUNDLE_ITEMS 1) - fixup_bundle(\"${APPS}\" \"${BUNDLELIBS}\" \"../libqethereum ../libethereum ../secp256k1\") + fixup_bundle(\"${APP_BUNDLE_PATH}\" \"${BUNDLELIBS}\" \"../libqethereum ../libethereum ../secp256k1\") " COMPONENT RUNTIME ) - - add_custom_target(addframeworks ALL - COMMAND /usr/local/opt/qt5/bin/macdeployqt ${binary_build_dir}/${EXECUTEABLE}.app - WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - DEPENDS ${PROJECT_NAME} - ) - + # Cleanup duplicate libs from macdeployqt + install(CODE " + file(GLOB LINGER_RM \"${APP_BUNDLE_PATH}/Contents/Frameworks/*.dylib\") + if (LINGER_RM) + file(REMOVE \${LINGER_RM}) + endif () + ") elseif ("${TARGET_PLATFORM}" STREQUAL "w64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-keep-inline-dllexport -static-libgcc -static-libstdc++ -static") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,-subsystem,windows -mthreads -L/usr/x86_64-w64-mingw32/plugins/platforms") diff --git a/libqethereum/CMakeLists.txt b/libqethereum/CMakeLists.txt index 51d602f94..f9be5751f 100644 --- a/libqethereum/CMakeLists.txt +++ b/libqethereum/CMakeLists.txt @@ -79,18 +79,11 @@ if (APPLE) set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}") endif () - set(APPS ${binary_build_dir}/${EXECUTABLE}.app) - - # This tool and the next will automatically looked at the linked libraries in order to determine what dependencies are required. Thus, target_link_libaries only needs to add ethereum and secp256k1 (above) - install(CODE " - include(BundleUtilities) - set(BU_CHMOD_BUNDLE_ITEMS 1) - fixup_bundle(\"${APPS}\" \"${BUNDLELIBS}\" \"../libethereum ../secp256k1\") - " COMPONENT RUNTIME ) + set(APPS ${binary_build_dir}/${EXECUTABLE}) if (${ADDFRAMEWORKS}) add_custom_target(addframeworks ALL - COMMAND /usr/local/opt/qt5/bin/macdeployqt ${binary_build_dir}/${EXECUTABLE}.app + COMMAND /usr/local/opt/qt5/bin/macdeployqt ${binary_build_dir}/${EXECUTABLE} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} DEPENDS ${PROJECT_NAME} ) diff --git a/secp256k1/CMakeLists.txt b/secp256k1/CMakeLists.txt index 23bccfa43..9b017f15f 100644 --- a/secp256k1/CMakeLists.txt +++ b/secp256k1/CMakeLists.txt @@ -5,7 +5,6 @@ set(CMAKE_ASM_COMPILER "yasm") set(EXECUTABLE secp256k1) file(GLOB HEADERS "*.h") -#aux_source_directory(. SRC_LIST) if ("${TARGET_PLATFORM}" STREQUAL "w64") add_custom_command( @@ -23,10 +22,10 @@ if ("${TARGET_PLATFORM}" STREQUAL "w64") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -DUSE_FIELD_5X52 -DUSE_FIELD_5X52_ASM -DUSE_NUM_GMP -DUSE_FIELD_INV_NUM") elseif(APPLE) - # set(CMAKE_INSTALL_PREFIX ../lib) if(ETH_STATIC) add_library(${EXECUTABLE} STATIC ${EXECUTABLE}.c field_5x52_asm.asm) else() + find_library(GMP_LS gmp /usr/local/lib) add_library(${EXECUTABLE} SHARED ${EXECUTABLE}.c field_5x52_asm.asm) endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DUSE_FIELD_GMP -DUSE_NUM_GMP -DUSE_FIELD_INV_NUM") @@ -39,7 +38,11 @@ else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DUSE_FIELD_GMP -DUSE_NUM_GMP -DUSE_FIELD_INV_NUM") endif() -target_link_libraries(${EXECUTABLE} gmp) +if (NOT GMP_LS) + set(GMP_LS gmp) +endif () + +target_link_libraries(${EXECUTABLE} ${GMP_LS}) install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )