From 6907a756233cb15bf1a17957ef303f71ff77a77c Mon Sep 17 00:00:00 2001 From: Eric Lombrozo Date: Mon, 10 Feb 2014 05:29:47 -0800 Subject: [PATCH] cmake can now build to linux and windows. Use -DTARGET_PLATFORM= --- CMakeLists.txt | 118 ++++++++++++++++++++++------------- alethzero/CMakeLists.txt | 26 +++++++- eth/CMakeLists.txt | 25 ++++++-- libethereum/CMakeLists.txt | 26 ++++++-- test/CMakeLists.txt | 25 ++++++-- windows/qt_plugin_import.cpp | 4 ++ 6 files changed, 162 insertions(+), 62 deletions(-) create mode 100644 windows/qt_plugin_import.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bf8611f9e..5c58e57e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,31 @@ elseif (CMAKE_COMPILER_IS_MSVC) else () set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/unknown") endif () + +set(TARGET_PLATFORM CACHE STRING "linux") +if (${TARGET_PLATFORM} STREQUAL "w64") + set(CMAKE_SYSTEM_NAME Windows) + + set(CMAKE_CXX_LIBRARY_ARCHITECTURE x86_64-w64-mingw32) + set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) + set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) + set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + set(CMAKE_AR x86_64-w64-mingw32-ar) + set(CMAKE_RANLIB x86_64-w64-mingw32-ranlib) + + set(CMAKE_EXECUTABLE_SUFFIX .exe) + + set(CMAKE_FIND_ROOT_PATH + /usr/x86_64-w64-mingw32 + ) + + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + + set(CMAKE_INSTALL_PREFIX /usr/x86_64-w64-mingw32) +endif() + # Initialize CXXFLAGS. set(CMAKE_CXX_FLAGS "-Wall -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") @@ -44,55 +69,58 @@ else () message(FATAL_ERROR "Your C++ compiler does not support C++11.") endif () -# Look for available Crypto++ version and if it is >= 5.6.2 -find_path(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(LS NAMES cryptoppeth cryptopp - PATHS - /usr/lib - /usr/local/lib - /opt/local/lib - ) +if (${TARGET_PLATFORM} STREQUAL "w64") +else () + # Look for available Crypto++ version and if it is >= 5.6.2 + find_path(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(LS NAMES cryptoppeth cryptopp + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + ) -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) - message(STATUS "System Crypto++ version found is smaller than 5.6.2.") - else() - set(CRYPTOPP_INCLUDE_DIR ${ID} CACHE FILEPATH "" FORCE) - set(CRYPTOPP_LIBRARIES ${LS} CACHE FILEPATH "" FORCE) - set(CRYPTOPP_FOUND TRUE) - message(STATUS "System Crypto++ found and version greater or equal to 5.6.2") - endif() - endif() -endif() + 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) + message(STATUS "System Crypto++ version found is smaller than 5.6.2.") + else() + set(CRYPTOPP_INCLUDE_DIR ${ID} CACHE FILEPATH "" FORCE) + set(CRYPTOPP_LIBRARIES ${LS} CACHE FILEPATH "" FORCE) + set(CRYPTOPP_FOUND TRUE) + message(STATUS "System Crypto++ found and version greater or equal to 5.6.2") + endif() + endif() + endif() -if(NOT CRYPTOPP_FOUND) - set(CRYPTOPP_INCLUDE_DIR "../cryptopp562" CACHE FILEPATH "" FORCE) - find_library(LSLOC NAMES cryptoppeth cryptopp - PATHS ../cryptopp562 - NO_DEFAULT_PATH - ) - set(CRYPTOPP_LIBRARIES ${LSLOC} CACHE FILEPATH "" FORCE) - message(STATUS "System Crypto++ not found, broken or too old. We use ${LSLOC}") -endif() + if(NOT CRYPTOPP_FOUND) + set(CRYPTOPP_INCLUDE_DIR "../cryptopp562" CACHE FILEPATH "" FORCE) + find_library(LSLOC NAMES cryptoppeth cryptopp + PATHS ../cryptopp562 + NO_DEFAULT_PATH + ) + set(CRYPTOPP_LIBRARIES ${LSLOC} CACHE FILEPATH "" FORCE) + message(STATUS "System Crypto++ not found, broken or too old. We use ${LSLOC}") + endif() -# Not really worth caching. We want to reevaluate anyway. -mark_as_advanced(CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARIES) + # Not really worth caching. We want to reevaluate anyway. + mark_as_advanced(CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARIES) -# Always "found", given last block. -include_directories(${CRYPTOPP_INCLUDE_DIR}) -link_directories(${CRYPTOPP_LIBRARIES}) + # Always "found", given last block. + include_directories(${CRYPTOPP_INCLUDE_DIR}) + link_directories(${CRYPTOPP_LIBRARIES}) +endif () if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") link_directories(/usr/local/lib) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index c7009f9e5..30a3f6941 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_policy(SET CMP0015 NEW) +cmake_policy(SET CMP0020 NEW) set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. SRC_LIST) @@ -15,12 +16,35 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") include_directories(/usr/local/Cellar/qt5/5.2.0/include /usr/local/include) endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (${TARGET_PLATFORM} STREQUAL "w64") + set(SRC_LIST ${SRC_LIST} ../windows/qt_plugin_import.cpp) +else () +endif () + find_package(Qt5Widgets REQUIRED) add_executable(alethzero Main.ui ${SRC_LIST}) qt5_wrap_ui(ui_Main.h Main.ui) -qt5_use_modules(alethzero Widgets Network ) target_link_libraries(alethzero ethereum) +if (${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") + target_link_libraries(alethzero gcc) + target_link_libraries(alethzero mingw32 qtmain mswsock iphlpapi qwindows shlwapi Qt5PlatformSupport gdi32 comdlg32 oleaut32 imm32 winmm ole32 uuid ws2_32) + target_link_libraries(alethzero boost_system-mt-s) + target_link_libraries(alethzero boost_filesystem-mt-s) + target_link_libraries(alethzero boost_thread_win32-mt-s) + target_link_libraries(alethzero Qt5PlatformSupport) + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) +else () + target_link_libraries(alethzero boost_system) + target_link_libraries(alethzero boost_filesystem) + find_package(Threads REQUIRED) + target_link_libraries(alethzero ${CMAKE_THREAD_LIBS_INIT}) +endif () + +qt5_use_modules(alethzero Core Gui Widgets Network) + install( TARGETS alethzero RUNTIME DESTINATION bin ) diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index 6213c6576..7cbc9a8b0 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -7,7 +7,26 @@ link_directories(../libethereum) add_executable(eth ${SRC_LIST}) -find_package(Threads REQUIRED) +if (${TARGET_PLATFORM} STREQUAL "w64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + target_link_libraries(eth gcc) + target_link_libraries(eth gdi32) + target_link_libraries(eth ws2_32) + target_link_libraries(eth mswsock) + target_link_libraries(eth shlwapi) + target_link_libraries(eth iphlpapi) + target_link_libraries(eth cryptopp) + target_link_libraries(eth boost_system-mt-s) + target_link_libraries(eth boost_filesystem-mt-s) + target_link_libraries(eth boost_thread_win32-mt-s) + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) +else () + target_link_libraries(eth ${CRYPTOPP_LIBRARIES}) + target_link_libraries(eth boost_system) + target_link_libraries(eth boost_filesystem) + find_package(Threads REQUIRED) + target_link_libraries(eth ${CMAKE_THREAD_LIBS_INIT}) +endif () if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") include_directories(/usr/local/include) @@ -16,11 +35,7 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") target_link_libraries(eth ethereum) target_link_libraries(eth miniupnpc) target_link_libraries(eth leveldb) -target_link_libraries(eth ${CRYPTOPP_LIBRARIES}) target_link_libraries(eth gmp) -target_link_libraries(eth boost_system) -target_link_libraries(eth boost_filesystem) -target_link_libraries(eth ${CMAKE_THREAD_LIBS_INIT}) install( TARGETS eth DESTINATION bin ) diff --git a/libethereum/CMakeLists.txt b/libethereum/CMakeLists.txt index 0675439b4..0c14981fe 100644 --- a/libethereum/CMakeLists.txt +++ b/libethereum/CMakeLists.txt @@ -1,21 +1,35 @@ cmake_policy(SET CMP0015 NEW) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") + aux_source_directory(. SRC_LIST) add_library(ethereum ${SRC_LIST}) file(GLOB HEADERS "*.h") -find_package(Threads REQUIRED) - include_directories(../secp256k1) target_link_libraries(ethereum secp256k1) target_link_libraries(ethereum miniupnpc) target_link_libraries(ethereum leveldb) -target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES}) target_link_libraries(ethereum gmp) -target_link_libraries(ethereum boost_system) -target_link_libraries(ethereum boost_filesystem) -target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT}) + +if(${TARGET_PLATFORM} STREQUAL "w64") + include_directories(/usr/x86_64-w64-mingw32/include/cryptopp) + target_link_libraries(ethereum cryptopp) + target_link_libraries(ethereum boost_system-mt-s) + target_link_libraries(ethereum boost_filesystem-mt-s) + target_link_libraries(ethereum boost_thread_win32-mt-s) + target_link_libraries(ethereum iphlpapi) + target_link_libraries(ethereum ws2_32) + target_link_libraries(ethereum mswsock) + target_link_libraries(ethereum shlwapi) +else () + target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES}) + target_link_libraries(ethereum boost_system) + target_link_libraries(ethereum boost_filesystem) + find_package(Threads REQUIRED) + target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT}) +endif () if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") include_directories(/usr/local/include) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a5581c131..c65b2e2c6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,26 @@ link_directories(../libethereum) add_executable(testeth ${SRC_LIST}) -find_package(Threads REQUIRED) +if (${TARGET_PLATFORM} STREQUAL "w64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + target_link_libraries(testeth gcc) + target_link_libraries(testeth gdi32) + target_link_libraries(testeth ws2_32) + target_link_libraries(testeth mswsock) + target_link_libraries(testeth shlwapi) + target_link_libraries(testeth iphlpapi) + target_link_libraries(testeth cryptopp) + target_link_libraries(testeth boost_system-mt-s) + target_link_libraries(testeth boost_filesystem-mt-s) + target_link_libraries(testeth boost_thread_win32-mt-s) + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) +else () + target_link_libraries(testeth ${CRYPTOPP_LIBRARIES}) + target_link_libraries(testeth boost_system) + target_link_libraries(testeth boost_filesystem) + find_package(Threads REQUIRED) + target_link_libraries(testeth ${CMAKE_THREAD_LIBS_INIT}) +endif () if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") include_directories(/usr/local/include) @@ -17,8 +36,4 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") target_link_libraries(testeth ethereum) target_link_libraries(testeth secp256k1) target_link_libraries(testeth miniupnpc) -target_link_libraries(testeth ${CRYPTOPP_LIBRARIES}) target_link_libraries(testeth gmp) -target_link_libraries(testeth boost_system) -target_link_libraries(testeth boost_filesystem) -target_link_libraries(testeth ${CMAKE_THREAD_LIBS_INIT}) diff --git a/windows/qt_plugin_import.cpp b/windows/qt_plugin_import.cpp new file mode 100644 index 000000000..39acb25c9 --- /dev/null +++ b/windows/qt_plugin_import.cpp @@ -0,0 +1,4 @@ +// This file is autogenerated by qmake. It imports static plugin classes for +// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS. variables. +#include +Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)