From e5c72cae836bda0deb98be547e3d15968804440a Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Wed, 25 Nov 2015 14:06:26 -0600 Subject: [PATCH 1/6] Fix CMake stuff for msys2 --- build/CMakeLists.txt | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index c910f8f6..46213363 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required ( VERSION 2.8.12 ) +# this addresses CMP0059 with CMake > 3.3 for PCH flags +cmake_policy( VERSION 2.8.12 ) project ( "i2pd" ) # configurale options @@ -46,7 +48,7 @@ set (LIBI2PD_SRC "${CMAKE_SOURCE_DIR}/api.cpp" ) -if (CMAKE_SYSTEM_NAME STREQUAL "Windows") +if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MSYS) list (APPEND LIBI2PD_SRC "${CMAKE_SOURCE_DIR}/I2PEndian.cpp") endif () @@ -75,7 +77,7 @@ set (DAEMON_SRC if (WITH_UPNP) add_definitions(-DUSE_UPNP) - if (NOT MSVC) + if (NOT MSVC AND NOT MSYS) set(DL_LIB ${CMAKE_DL_LIBS}) endif () endif () @@ -110,6 +112,7 @@ elseif (NOT MSVC) endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe") if (WITH_HARDENING) add_definitions( "-D_FORTIFY_SOURCE=2" ) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -Werror=format-security" ) @@ -132,7 +135,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") -elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") +elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MSYS) list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp") endif () @@ -153,7 +156,7 @@ endif() if (WITH_STATIC) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) - if (WIN32) + if (WIN32 OR MSYS) # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace # Note that you might need to rebuild Crypto++ foreach(flag_var @@ -173,7 +176,7 @@ if (WITH_STATIC) set( CMAKE_THREAD_LIBS_INIT "gcc_eh -Wl,-u,pthread_create,-u,pthread_once,-u,pthread_mutex_lock,-u,pthread_mutex_unlock,-u,pthread_join,-u,pthread_equal,-u,pthread_detach,-u,pthread_cond_wait,-u,pthread_cond_signal,-u,pthread_cond_destroy,-u,pthread_cond_broadcast,-u,pthread_cancel" ) endif () else() - if (NOT WIN32) + if (NOT WIN32 AND NOT MSYS) # TODO: Consider separate compilation for LIBI2PD_SRC for library. # No need in -fPIC overhead for binary if not interested in library # HINT: revert c266cff CMakeLists.txt: compilation speed up @@ -206,9 +209,10 @@ if (WITH_PCH) target_compile_options(i2pdclient PRIVATE -include stdafx.h) endif() target_link_libraries(libi2pd stdafx) - target_link_libraries(i2pdclient stdafx) endif() +target_link_libraries(i2pdclient libi2pd) + find_package ( Boost COMPONENTS system filesystem regex program_options date_time thread chrono REQUIRED ) if(NOT DEFINED Boost_INCLUDE_DIRS) message(SEND_ERROR "Boost is not found, or your boost version was bellow 1.46. Please download Boost!") @@ -294,7 +298,11 @@ if (WITH_BINARY) if(${LAST_Boost_LIBRARIES} MATCHES ".*pthread.*") list(REMOVE_AT Boost_LIBRARIES -1) endif() - target_link_libraries( "${PROJECT_NAME}" libi2pd i2pdclient ${DL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ) + + if (MSYS OR MINGW) + set (MINGW_EXTRA -lws2_32 -lmswsock -liphlpapi ) + endif () + target_link_libraries( "${PROJECT_NAME}" libi2pd i2pdclient ${DL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MINGW_EXTRA} ) install(TARGETS "${PROJECT_NAME}" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if (MSVC) From 76549d0a4a1b146c037de62ac2dbf7cfde006540 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Wed, 25 Nov 2015 14:14:26 -0600 Subject: [PATCH 2/6] Fix win32 resource compilation with msys squash! Fix win32 resource winres.h is missing for mingw --- Win32/Resource.rc | Bin 3294 -> 2602 bytes Win32/resource.h | Bin 904 -> 451 bytes Win32/winres.h | 6 ++++++ build/CMakeLists.txt | 8 +++++--- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 Win32/winres.h diff --git a/Win32/Resource.rc b/Win32/Resource.rc index a4fa890b129dafe6d1ed2497070a94f247581074..e8b77bef01dc1ac2e75324d75bcbfde476e782d3 100644 GIT binary patch literal 2602 zcmcImOK+n{5WZXTf2bvwM8jf?Glv{8U@r;*%NT1SMMAyMwtIye)U+oXX@2}xW6a>J zH?s$)4;EdouKMcb(FmScCd#_pNLaJ_Knifae1R?HR1isX5VS52BBM}ef>qKO4o0Kl z;D+(6IOG(x6W`cr!vQjKx?!Axy@*$d>qqI*v)w2Rp40gGX&MEw(!b(4x-%NVyz_V? z%00*(g_ZYh<%dp?xE@$tApeTsm2nKB_5X^lH8>qO0`d_WpMVE=d|R-32e%1lDu=Pe zRMvML1a*@swt?S{*~)M2**DBo93@M~OWh#2gC9Sj&s^EddFqA9-Ea`t;XJYD9;gqb z%>zIFLx(t-_6cc%slKTM+3pEsWlqzIZ0YUT`f8yKRY99GWc+X)J$mjZz@bd`YvEWj z!@;;ugyCT7&H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C(84UWx(9ca_`bBCaGkDEnM zSvNlZK#q2p#}+qZdzt&*szap>0wYYaMDPfnpD2ucZ?WR|J%Lj-b3egn)6Zx@4I>!* zg5mgq?PM3ud28i3i1$TV5hf(#wRojuS(v*`PGcf?dXU8-dl6}I%O#y!a{5-voED`sn6mFlviO8~;lY16+VR)%=?R@ig#miiz4|wzs?LyK=Yk=j4R%kk{+!KHI EFDV~;hX4Qo literal 904 zcmb7?-Acni5QWdR;5#hzQm|Hhf!gGv*rw7y^eWicNTpb48h;R9UHxX)(pGA)44c^* zX3w0NldsRZ>Uzf#^^_`7tZPoM#N;R8RCqO`phml^|ul*8G~0`I<*F zEbHgs9dS}li^&o-$Q@!0o$eEw=Ci?-}(0&#B4w2O4VR*_$G5x{jIP3LPTvu&tQ$C_Y~8f)!KTj^V=`l^I>a$k?V9cD{NKo?Nf&FLs;9qRjeJThhc|Jnikc#ww=vCR6~7J%#;h;-;KWkR}+1N diff --git a/Win32/winres.h b/Win32/winres.h new file mode 100644 index 00000000..e9afee91 --- /dev/null +++ b/Win32/winres.h @@ -0,0 +1,6 @@ +#ifndef WINRES_H__ +#define WINRES_H__ + +#include + +#endif diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 46213363..1a378cbf 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -104,9 +104,9 @@ include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11_SUPPORTED) CHECK_CXX_COMPILER_FLAG("-std=c++0x" CXX0X_SUPPORTED) if (CXX11_SUPPORTED) - add_definitions( "-std=c++11" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" ) elseif (CXX0X_SUPPORTED) # gcc 4.6 - add_definitions( "-std=c++0x" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x" ) elseif (NOT MSVC) message(SEND_ERROR "C++11 standart not seems to be supported by compiler. Too old version?") endif () @@ -138,10 +138,12 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MSYS) list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp") + list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Resource.rc") endif () if (WITH_AESNI) - add_definitions ( "-maes -DAESNI" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes" ) + add_definitions ( -DAESNI ) endif() # libraries From b2a6c1bc68ac75a02c7f208a6733fcd1e0dba1e9 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Wed, 25 Nov 2015 16:11:43 -0600 Subject: [PATCH 3/6] fixup! read Content-Length from http header MSVC++ complains on ssize_t --- I2PControl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/I2PControl.cpp b/I2PControl.cpp index d04b91d1..6f2c21ba 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -201,7 +201,7 @@ namespace client LogPrint (eLogError, "Malformed I2PControl request. HTTP header expected"); return; // TODO: } - ssize_t rem = contentLength + ss.tellg () - bytes_transferred; // more bytes to read + std::streamoff rem = contentLength + ss.tellg () - bytes_transferred; // more bytes to read if (rem > 0) { bytes_transferred = boost::asio::read (*socket, boost::asio::buffer (buf->data (), rem)); From ff356b1f21e13b59e3e02f0938ab8a68e207c659 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Wed, 25 Nov 2015 17:42:44 -0600 Subject: [PATCH 4/6] Use assembly language when building zlib for MSVC++ --- build/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 1a378cbf..5cd3b55d 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -240,6 +240,7 @@ if (NOT ZLIB_FOUND ) URL http://zlib.net/zlib-1.2.8.tar.gz PREFIX ${CMAKE_CURRENT_BINARY_DIR}/zlib CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= + -DAMD64=ON -DASM686=ON "-DCMAKE_ASM_MASM_FLAGS=/W0 /safeseh" ) if (WITH_PCH) add_dependencies( stdafx zlib-project ) From 759dfb28ce3d270ac5fa6d2ec2c709048535d9f3 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Tue, 1 Dec 2015 19:02:20 -0600 Subject: [PATCH 5/6] Increase PCH heap limit for MSVC --- build/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 5cd3b55d..0843f82b 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -191,21 +191,21 @@ if (WITH_PCH) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) add_library(stdafx STATIC "${CMAKE_SOURCE_DIR}/stdafx.cpp") if(MSVC) - target_compile_options(stdafx PRIVATE /Ycstdafx.h /Zm135) + target_compile_options(stdafx PRIVATE /Ycstdafx.h /Zm155) add_custom_command(TARGET stdafx POST_BUILD COMMAND xcopy /y stdafx.dir\\$\\*.pdb libi2pd.dir\\$\\ COMMAND xcopy /y stdafx.dir\\$\\*.pdb i2pdclient.dir\\$\\ COMMAND xcopy /y stdafx.dir\\$\\*.pdb i2pd.dir\\$\\ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) - target_compile_options(libi2pd PRIVATE /FIstdafx.h /Yustdafx.h /Zm135 "/Fp${CMAKE_BINARY_DIR}/stdafx.dir/$/stdafx.pch") - target_compile_options(i2pdclient PRIVATE /FIstdafx.h /Yustdafx.h /Zm135 "/Fp${CMAKE_BINARY_DIR}/stdafx.dir/$/stdafx.pch") + target_compile_options(libi2pd PRIVATE /FIstdafx.h /Yustdafx.h /Zm155 "/Fp${CMAKE_BINARY_DIR}/stdafx.dir/$/stdafx.pch") + target_compile_options(i2pdclient PRIVATE /FIstdafx.h /Yustdafx.h /Zm155 "/Fp${CMAKE_BINARY_DIR}/stdafx.dir/$/stdafx.pch") else() string(TOUPPER ${CMAKE_BUILD_TYPE} BTU) get_directory_property(DEFS DEFINITIONS) string(REPLACE " " ";" FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTU}} ${DEFS}") add_custom_command(TARGET stdafx PRE_BUILD - COMMAND ${CMAKE_CXX_COMPILER} ${FLAGS} -c ${CMAKE_CURRENT_SOURCE_DIR}/../stdafx.h + COMMAND ${CMAKE_CXX_COMPILER} ${FLAGS} -c ${CMAKE_CURRENT_SOURCE_DIR}/../stdafx.h -o ${CMAKE_BINARY_DIR}/stdafx.h.gch ) target_compile_options(libi2pd PRIVATE -include stdafx.h) target_compile_options(i2pdclient PRIVATE -include stdafx.h) @@ -286,7 +286,7 @@ if (WITH_BINARY) if (WITH_PCH) if (MSVC) - target_compile_options("${PROJECT_NAME}" PRIVATE /FIstdafx.h /Yustdafx.h /Zm135 "/Fp${CMAKE_BINARY_DIR}/stdafx.dir/$/stdafx.pch") + target_compile_options("${PROJECT_NAME}" PRIVATE /FIstdafx.h /Yustdafx.h /Zm155 "/Fp${CMAKE_BINARY_DIR}/stdafx.dir/$/stdafx.pch") else() target_compile_options("${PROJECT_NAME}" PRIVATE -include stdafx.h) endif() From 9d70851eb9e981c33f193d350eef3b2e3e0e8456 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Thu, 3 Dec 2015 23:23:26 -0600 Subject: [PATCH 6/6] Respect static for zlib with CMake --- build/CMakeLists.txt | 13 +++++++++++-- build/cmake-zlib-static.patch | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 build/cmake-zlib-static.patch diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 0843f82b..43d8348f 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -238,8 +238,12 @@ if (NOT ZLIB_FOUND ) include( ExternalProject ) ExternalProject_Add(zlib-project URL http://zlib.net/zlib-1.2.8.tar.gz + URL_MD5 44d667c142d7cda120332623eab69f40 PREFIX ${CMAKE_CURRENT_BINARY_DIR}/zlib + # patch on Windows might be found in C:/Program Files/Git/usr/bin + PATCH_COMMAND patch -p0 < ${CMAKE_CURRENT_SOURCE_DIR}/cmake-zlib-static.patch CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= + -DWITH_STATIC=${WITH_STATIC} -DAMD64=ON -DASM686=ON "-DCMAKE_ASM_MASM_FLAGS=/W0 /safeseh" ) if (WITH_PCH) @@ -249,9 +253,14 @@ if (NOT ZLIB_FOUND ) endif () # ExternalProject_Get_Property(zlib-project install_dir) set ( ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/zlib/include" CACHE FILEPATH "zlib include dir" FORCE) - set ( ZLIB_LIBRARY debug zlibd optimized zlib CACHE STRING "zlib libraries" FORCE) + if (NOT WITH_STATIC) + set ( ZLIB_LIBRARY debug zlibd optimized zlib CACHE STRING "zlib libraries" FORCE) + endif () +endif () +if (WITH_STATIC AND (MSVC OR MSYS)) + set ( ZLIB_LIBRARY debug zlibstaticd optimized zlibstatic CACHE STRING "zlib libraries" FORCE) endif () -link_directories("${CMAKE_CURRENT_BINARY_DIR}/zlib/lib") +link_directories(${CMAKE_CURRENT_BINARY_DIR}/zlib/lib ${ZLIB_ROOT}/lib) # load includes include_directories( ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) diff --git a/build/cmake-zlib-static.patch b/build/cmake-zlib-static.patch new file mode 100644 index 00000000..68f1400e --- /dev/null +++ b/build/cmake-zlib-static.patch @@ -0,0 +1,28 @@ +--- CMakeLists.txt.orig 2013-04-28 17:57:10.000000000 -0500 ++++ CMakeLists.txt 2015-12-03 12:53:52.371087900 -0600 +@@ -7,6 +7,7 @@ + + option(ASM686 "Enable building i686 assembly implementation") + option(AMD64 "Enable building amd64 assembly implementation") ++option(WITH_STATIC "Static runtime on Windows" OFF) + + set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") + set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") +@@ -66,6 +67,17 @@ + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + endif() + ++if(WITH_STATIC AND (MSVC OR MSYS)) ++ # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace ++ foreach(flag_var ++ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE ++ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) ++ if(${flag_var} MATCHES "/MD") ++ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") ++ endif(${flag_var} MATCHES "/MD") ++ endforeach(flag_var) ++endif() ++ + if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) + # If we're doing an out of source build and the user has a zconf.h + # in their source tree...