From e0dd942875bd72b9af15c90960bf76c3166061f3 Mon Sep 17 00:00:00 2001 From: crypto-ape <43807588+crypto-ape@users.noreply.github.com> Date: Thu, 4 Apr 2019 17:36:04 +0200 Subject: [PATCH] Update build system for MinGW --- CMakeLists.txt | 100 +++++++++++------------------------------ include/fc/variant.hpp | 2 +- src/variant.cpp | 2 +- 3 files changed, 29 insertions(+), 75 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d28877..01fe9d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # Defines fc library target. PROJECT( fc ) -CMAKE_MINIMUM_REQUIRED( VERSION 3.1 ) +CMAKE_MINIMUM_REQUIRED( VERSION 3.2 ) set( CMAKE_CXX_STANDARD 14 ) SET( CMAKE_CXX_STANDARD_REQUIRED ON ) @@ -22,6 +22,10 @@ INCLUDE(GetGitRevisionDescription) INCLUDE(CheckLibraryExists) INCLUDE(CheckLibcxxAtomic) +if (APPLE) + INCLUDE(Legacy) +endif (APPLE) + get_git_head_revision(GIT_REFSPEC FC_GIT_REVISION_SHA) get_git_unix_timestamp(FC_GIT_REVISION_UNIX_TIMESTAMP) @@ -39,7 +43,7 @@ endif() SET (ORIGINAL_LIB_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) SET(BOOST_COMPONENTS) -LIST(APPEND BOOST_COMPONENTS thread date_time filesystem system program_options chrono unit_test_framework context iostreams regex) +LIST(APPEND BOOST_COMPONENTS coroutine thread date_time filesystem system program_options chrono unit_test_framework context iostreams regex) # boost::endian is also required, but FindBoost can't handle header-only libs SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) @@ -98,17 +102,7 @@ endif ( MSVC ) # End configure secp256k1-zkp # Configure editline -if ( MSVC ) -# # autoconf won't work here, hard code the defines -# set( EDITLINE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline" ) -# -# file( GLOB EDITLINE_SOURCES "${EDITLINE_DIR}/src/editline.c" ) -# add_library( editline ${EDITLINE_SOURCES} ) -# -# target_include_directories( editline PRIVATE "${EDITLINE_DIR}" PUBLIC "${EDITLINE_DIR}/include" ) -# -# set_target_properties( editline PROPERTIES COMPILE_DEFINITIONS LINKER_LANGUAGE C ) -else ( MSVC ) +if ( NOT WIN32 ) include(ExternalProject) if ( MINGW ) # Editline is not avalible in MINGW @@ -120,7 +114,7 @@ else ( MSVC ) BUILD_COMMAND make INSTALL_COMMAND true BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/vendor/editline/src/project_editline-build/src/.libs/libeditline.a - ) + ) ExternalProject_Add_Step(project_editline autogen WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline/autogen.sh @@ -133,7 +127,7 @@ else ( MSVC ) add_dependencies(editline project_editline) install( FILES ${binary_dir}/src/.libs/libeditline${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION lib/cryptonomex ) endif ( MINGW ) -endif ( MSVC ) +endif ( NOT WIN32 ) # End configure editline IF( WIN32 ) @@ -142,30 +136,21 @@ IF( WIN32 ) set( RPCRT4 rpcrt4 ) #boost - SET(BOOST_ROOT $ENV{BOOST_ROOT}) -# set(Boost_USE_DEBUG_PYTHON ON) + if ($ENV{BOOST_ROOT}) + SET(BOOST_ROOT $ENV{BOOST_ROOT}) + endif() + + set(Boost_USE_DEBUG_PYTHON ON) set(Boost_USE_MULTITHREADED ON) set(BOOST_ALL_DYN_LINK OFF) # force dynamic linking for all libraries - FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) - # For Boost 1.53 on windows, coroutine was not in BOOST_LIBRARYDIR and do not need it to build, but if boost versin >= 1.54, find coroutine otherwise will cause link errors - IF(NOT "${Boost_VERSION}" MATCHES "1.53(.*)") - SET(BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES}) - FIND_PACKAGE(Boost 1.54 REQUIRED COMPONENTS coroutine) - LIST(APPEND BOOST_COMPONENTS coroutine) - SET(Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES}) - ENDIF() + LIST(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 crypt32 mswsock userenv) - LIST(APPEND PLATFORM_SPECIFIC_LIBS wsock32.lib ws2_32.lib userenv.lib) # iphlpapi.lib ELSE(WIN32) MESSAGE(STATUS "Configuring fc to build on Unix/Apple") - LIST(APPEND BOOST_COMPONENTS coroutine) - - FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so") IF(NOT APPLE) @@ -175,9 +160,10 @@ ELSE(WIN32) ENDIF(NOT APPLE) ENDIF(WIN32) +FIND_PACKAGE(Boost 1.57 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) -IF(NOT "$ENV{OPENSSL_ROOT_DIR}" STREQUAL "") +IF($ENV{OPENSSL_ROOT_DIR}) set(OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT_DIR} ) set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include) message(STATUS "Setting up OpenSSL root and include vars to ${OPENSSL_ROOT_DIR}, ${OPENSSL_INCLUDE_DIR}") @@ -283,12 +269,11 @@ setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC ) install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include ) # begin editline stuff -if(NOT (MSVC OR MINGW)) - target_compile_definitions (fc PRIVATE HAVE_EDITLINE) - set(editline_libraries editline) -endif(NOT (MSVC OR MINGW)) if(WIN32) target_compile_definitions( fc PRIVATE _CRT_NONSTDC_NO_DEPRECATE ) +elseif(WIN32) + target_compile_definitions (fc PRIVATE HAVE_EDITLINE) + set(editline_libraries editline) endif(WIN32) # end editline stuff @@ -383,9 +368,11 @@ target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${OPENSSL_LIBRARIES} ${Z ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${editline_libraries} secp256k1 ${CMAKE_REQUIRED_LIBRARIES} ) -if(MSVC) - set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) -endif(MSVC) +if(WIN32 AND MSVC) + set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) +elseif(WIN32 AND MINGW) + set_source_files_properties( src/network/http/websocket.cpp PROPERTIES LINK_FLAGS "-mbig-obj" ) +endif() IF(NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY MATCHES "\\.(a|lib)$") @@ -400,18 +387,10 @@ include_directories( vendor/websocketpp ) add_subdirectory(tests) -if(WIN32) +if(MSVC) # add addtional import library on windows platform target_link_libraries( fc PUBLIC crypt32.lib) - # now generate a list of the DLLs we're using to use during the install process - include (ParseLibraryList) - PARSE_LIBRARY_LIST(${Boost_LIBRARIES} - FOUND parseOk - DEBUG Boost_LIBRARIES_DEBUG - OPT Boost_LIBRARIES_RELEASE - GENERAL Boost_LIBRARIES_GENERAL) - #Variable will hold list of .pdb files generated for libraries the 'fc' module is linked to set(INTERFACE_LINK_PDB_RELEASE) @@ -480,31 +459,6 @@ if(WIN32) set_property(TARGET fc PROPERTY SHARED_LIBRARIES_DEBUG ${SHARED_LIBRARIES_DEBUG}) set_property(TARGET fc PROPERTY SHARED_LIBRARIES_RELEASE ${SHARED_LIBRARIES_RELEASE}) -endif(WIN32) - -SET(OPENSSL_CONF_TARGET ) -IF(DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) - SET (OPENSSL_CONF_TARGET ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) -ELSE() - SET (OPENSSL_CONF_TARGET ${CMAKE_CURRENT_BINARY_DIR}) -ENDIF() - - IF(WIN32) - IF("${OPENSSL_ROOT_DIR}" STREQUAL "") - get_filename_component(OPENSSL_ROOT_DIR "${OPENSSL_INCLUDE_DIR}/.." REALPATH) - ENDIF() - IF("${OPENSSL_CONF_SOURCE}" STREQUAL "") - SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/ssl/openssl.cnf") - IF(MINGW) - SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/openssl.cnf") - ENDIF(MINGW) - ENDIF() - SET(POST_BUILD_STEP_COMMANDS ${POST_BUILD_STEP_COMMANDS} - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENSSL_CONF_SOURCE}" "${OPENSSL_CONF_TARGET}/openssl.cnf") - ENDIF(WIN32) - -ADD_CUSTOM_COMMAND(TARGET fc POST_BUILD ${POST_BUILD_STEP_COMMANDS} - COMMENT "Copying OpenSSL/ssl/openssl.cnf into target directory." -) +endif(MSVC) MESSAGE(STATUS "Finished fc module configuration...") diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index 2e08740..5f1ce5b 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -148,7 +148,7 @@ namespace fc #ifdef __APPLE__ void to_variant( size_t s, variant& v, uint32_t max_depth = 1 ); - #elif !defined(_MSC_VER) + #elif !defined(_WIN32) void to_variant( long long int s, variant& v, uint32_t max_depth = 1 ); void to_variant( unsigned long long int s, variant& v, uint32_t max_depth = 1 ); #endif diff --git a/src/variant.cpp b/src/variant.cpp index 4e52ec9..3d24e28 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -673,7 +673,7 @@ void from_variant( const variant& var, std::vector& vo, uint32_t max_depth } #ifdef __APPLE__ -#elif !defined(_MSC_VER) +#elif !defined(_WIN32) void to_variant( long long int s, variant& v, uint32_t max_depth ) { v = variant( int64_t(s) ); } void to_variant( unsigned long long int s, variant& v, uint32_t max_depth ) { v = variant( uint64_t(s)); } #endif