|
:: future: need x86 and x64 of zlib. only useful if you have very well compressible data. |
|
:: git clone https://github.com/madler/zlib.git |
|
|
|
:: prereqs are the full (not light!) Win32 and Win64 OpenSSL versions at http://slproweb.com/products/Win32OpenSSL.html |
|
:: download both and install them (with `Copy the OpenSSL DLLs to:` option set to `The OpenSSL binaries (/bin) directory`) into: |
|
:: - C:\OpenSSL-Win32 |
|
:: - C:\OpenSSL-Win64 |
|
:: |
|
:: Downloads at time of writing: |
|
:: - http://slproweb.com/download/Win32OpenSSL-1_0_2j.exe |
|
:: - http://slproweb.com/download/Win64OpenSSL-1_0_2j.exe |
|
|
|
:: without OpenSSL, you will see these in the build logs and your sshlib2.dll will have limited algorithms: |
|
::-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found version "1.0.2h") |
|
::-- Could NOT find Libgcrypt (missing: LIBGCRYPT_LIBRARY LIBGCRYPT_INCLUDE_DIR) |
|
|
|
:: Possibly no need for the environment variables as when installed, OpenSSL is detected automagically: |
|
::-- Found OpenSSL: optimized;C:/OpenSSL-Win64/lib/ssleay32.lib;debug;C:/OpenSSL-Win64/lib/VC/ssleay32MDd.lib;optimized;C:/OpenSSL-Win64/lib/libeay32.lib;debug;C:/OpenSSL-Win64/lib/VC/libeay32MDd.lib (found version "1.0.2j") |
|
::-- Found OpenSSL: optimized;C:/OpenSSL-Win32/lib/ssleay32.lib;debug;C:/OpenSSL-Win32/lib/VC/ssleay32MDd.lib;optimized;C:/OpenSSL-Win32/lib/libeay32.lib;debug;C:/OpenSSL-Win32/lib/VC/libeay32MDd.lib (found version "1.0.2j") |
|
:: Although if we want static linking, we need the MTd and MT directories from OpenSSL |
|
|
|
:: despite a few days of work, this batch file still procudes a libssh2.dll that depends on the OpenSSL DLLs |
|
:: none of the tries to make stuff statically link the .lib files seem to work, though the VCRUNTIME140.DLL dependency is now gone. |
|
|
|
:: cmake options: https://github.com/libssh2/libssh2/blob/master/docs/INSTALL_CMAKE |
|
|
|
:: -D"ENABLE_ZLIB_COMPRESSION=ON" requires ZLIB_LIBRARY to be defined |
|
:: -D"CRYPTO_BACKEND=WinCNG" leaves out some ciphers (aes128-ctr, aes256-ctr, aes192-ctr) and MAC algorithms (hmac-ripemd160, hmac-ripemd160@openssh.com) |
|
:: so you really don't want WinCNG |
|
:: -D"CRYPTO_BACKEND=OpenSSL" needs LIBEAY*.DLL but includes more ciphers (aes128-ctr, aes256-ctr, aes192-ctr) and MAC algorithms (hmac-ripemd160, hmac-ripemd160@openssh.com) |
|
:: could not find out how to use Libgcrypt or mbedTLS as the libssh2 build instructions are very limited |
|
:: -D"BUILD_SHARED_LIBS=OFF" creates a .LIB; -D"BUILD_SHARED_LIBS=1" creates a .DLL |
|
:: -D"BUILD_TESTING=OFF" |
|
:: -D"BUILD_EXAMPLES=OFF" |
|
|
|
:: WinCNG support https://stackoverflow.com/questions/31550993/git-ssh-in-visual-studio-2015/37010403#37010403 |
|
|
|
|
|
:: since we need environment variables |
|
setlocal |
|
|
|
:: these require / slashes in the path names, not \ backslashes |
|
:: simple reason: unix based build tools do not like Windows based path delimiters. |
|
set OpenSSLWin32Directory=C:/OpenSSL-Win32 |
|
set OpenSSLWin64Directory=C:/OpenSSL-Win64 |
|
|
|
if not exist libssh2\nul goto :libssh2NotYetExists |
|
:: * Win9x and others doesn't like ``EXISTS libssh2'' so change it to ``EXISTS libssh2\nul''. |
|
|
|
echo Directory libssh2 already exists; bailing out. |
|
goto :end |
|
|
|
:libssh2NotYetExists |
|
|
|
if exist %OpenSSLWin32Directory%\nul goto :haveOpenSSLWin32 |
|
echo Directory %OpenSSLWin32Directory% does not exist; bailing out. |
|
goto :end |
|
|
|
:haveOpenSSLWin32 |
|
|
|
if exist %OpenSSLWin64Directory%\nul goto :haveOpenSSLWin64 |
|
echo Directory %OpenSSLWin64Directory% does not exist; bailing out. |
|
goto :end |
|
|
|
:haveOpenSSLWin64 |
|
|
|
:: https://github.com/TrinityCore/TrinityCore/issues/9355#issuecomment-14487233 |
|
:: In Cmake GUI, click "Advanced", find "OPENSSL_INCLUDE_DIR" and change it to C:/OpenSSL-WinXX/include. |
|
:: Find "OPENSSL_ROOT_DIR" and change it to C:/OpenSSL-WinXX". |
|
set Win32OPENSSL_ROOT_DIR=%OpenSSLWin32Directory% |
|
set Win32OPENSSL_INCLUDE_DIR=%Win32OPENSSL_ROOT_DIR%/include |
|
set Win32OPENSSL_LIBRARIES=%Win32OPENSSL_ROOT_DIR%/lib/VC/static |
|
set Win64OPENSSL_ROOT_DIR=%OpenSSLWin64Directory% |
|
set Win64OPENSSL_INCLUDE_DIR=%Win64OPENSSL_ROOT_DIR%/include |
|
set Win64OPENSSL_LIBRARIES=%Win64OPENSSL_ROOT_DIR%/lib/VC/static |
|
|
|
:: maybe extra variables are needed: |
|
:: - https://cmake.org/cmake/help/v3.0/module/FindOpenSSL.html |
|
:: - http://stackoverflow.com/questions/16248775/cmake-not-able-to-find-openssl/27506352#27506352 |
|
|
|
:main |
|
:: based on https://gist.github.com/jpluimers/2bf514d658488a7ddfc189b0677a3a57 |
|
|
|
git clone https://github.com/libssh2/libssh2.git |
|
|
|
if exist libssh2\nul goto :haveLibssh2 |
|
echo libssh2 does not exist; bailing out. |
|
goto :end |
|
|
|
:haveLibssh2 |
|
pushd libssh2 |
|
|
|
:: Try to force Static libraries (so VCRUNTIME140.DLL is not needed; hopefully this links libvcruntime.lib instead of vcruntime.lib) |
|
pushd cmake |
|
> c_flag_overrides.cmake type NUL |
|
>> c_flag_overrides.cmake echo if(MSVC) |
|
>> c_flag_overrides.cmake echo set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1") |
|
>> c_flag_overrides.cmake echo set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG") |
|
>> c_flag_overrides.cmake echo set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG") |
|
>> c_flag_overrides.cmake echo set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG") |
|
>> c_flag_overrides.cmake echo endif() |
|
|
|
> cxx_flag_overrides.cmake type NUL |
|
>> cxx_flag_overrides.cmake echo if(MSVC) |
|
>> cxx_flag_overrides.cmake echo set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1") |
|
>> cxx_flag_overrides.cmake echo set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG") |
|
>> cxx_flag_overrides.cmake echo set(CMAKE_CXX_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG") |
|
>> cxx_flag_overrides.cmake echo set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG") |
|
>> cxx_flag_overrides.cmake echo endif() |
|
|
|
> MSVCC_static_linking.cmake type NUL |
|
>> MSVCC_static_linking.cmake echo set(CMAKE_USER_MAKE_RULES_OVERRIDE |
|
>> MSVCC_static_linking.cmake echo ${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake) |
|
>> MSVCC_static_linking.cmake echo set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX |
|
>> MSVCC_static_linking.cmake echo ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake) |
|
|
|
>> max_warnings.cmake echo include(MSVCC_static_linking) |
|
popd |
|
|
|
:: the above trick with C*_FLAGS* doesn't work so go the PowerShell way of globally replacing the generated VC++ project files |
|
:: http://stackoverflow.com/questions/251557/escape-angle-brackets-in-a-windows-command-prompt |
|
> fix-vcxproj-files.ps1 type NUL |
|
>> fix-vcxproj-files.ps1 echo $projectFiles = Get-ChildItem . *.vcxproj -Recurse |
|
>> fix-vcxproj-files.ps1 echo foreach ($projectFile in $projectFiles) { |
|
>> fix-vcxproj-files.ps1 echo (Get-Content $projectFile.PSPath). |
|
>> fix-vcxproj-files.ps1 echo Replace('^<UseOfMfc^>false^</UseOfMfc^>', '^<UseOfMfc^>Static^</UseOfMfc^>'). |
|
>> fix-vcxproj-files.ps1 echo Replace('^<RuntimeLibrary^>MultiThreadedDebugDLL^</RuntimeLibrary^>', '^<RuntimeLibrary^>MultiThreadedDebug^</RuntimeLibrary^>'). |
|
>> fix-vcxproj-files.ps1 echo Replace('^<RuntimeLibrary^>MultiThreadedDLL^</RuntimeLibrary^>', '^<RuntimeLibrary^>MultiThreaded^</RuntimeLibrary^>') ^| |
|
>> fix-vcxproj-files.ps1 echo Set-Content $projectFile.PSPath |
|
>> fix-vcxproj-files.ps1 echo } |
|
:: maybe OPENSSL_MSVC_STATIC_RT works beter: try this in the future, maybe combined with OPENSSL_USE_STATIC_LIBS. See https://cmake.org/cmake/help/v3.5/module/FindOpenSSL.html |
|
|
|
mkdir buildWin64 |
|
pushd buildWin64 |
|
|
|
:: set OPENSSL_ROOT_DIR=%Win64OPENSSL_ROOT_DIR% |
|
:: set OPENSSL_INCLUDE_DIR=%Win64OPENSSL_INCLUDE_DIR% |
|
:: set OPENSSL_LIBRARIES=%Win64OPENSSL_LIBRARIES% |
|
|
|
:: Generate build for MSVS 2015 |
|
::cmake .. -G"Visual Studio 14 Win64" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"OPENSSL_ROOT_DIR=../../openssl" -D"OPENSSL_LIBRARIES=../../openssl/ssl" |
|
:: cmake .. -G"Visual Studio 14 Win64" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" |
|
:: with OpenSSL DLL: |
|
:: cmake .. -G"Visual Studio 14 Win64" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=OpenSSL" |
|
cmake .. -G"Visual Studio 14 Win64" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=OpenSSL" -D"OPENSSL_USE_STATIC_LIBS=TRUE" -D"OPENSSL_MSVC_STATIC_RT=TRUE" |
|
:: cmake .. -G"Visual Studio 14 Win64" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=OpenSSL" -D"OPENSSL_ROOT_DIR=%OPENSSL_ROOT_DIR%" -D"OPENSSL_LIBRARIES=%OPENSSL_LIBRARIES%" |
|
:: cmake .. -G"Visual Studio 14 Win64" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=WinCNG" |
|
|
|
:: needs to be after the above cmake as that one generates the vcxproj files |
|
powershell -file ..\fix-vcxproj-files.ps1 |
|
|
|
:: this fails bitching about v100 not being there: |
|
:: cmake --build . --config "Visual Studio 14 Win64" |
|
:: this just works: |
|
set Platform= |
|
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" |
|
call msbuild libssh2.sln /p:Configuration=Release /p:Platform=x64 |
|
:: to find out various build aspects (like imports from VCRUNTIME140 and oher DLLs) |
|
dumpbin /headers example\Release\libssh2.dll | find "machine" |
|
dumpbin /all example\Release\libssh2.dll > example\Release\libssh2.dll.dumpbin.txt |
|
tdump64 example\Release\libssh2.dll > example\Release\libssh2.dll.tdump.txt |
|
popd |
|
|
|
mkdir buildWin32 |
|
pushd buildWin32 |
|
|
|
:: set OPENSSL_ROOT_DIR=%Win32OPENSSL_ROOT_DIR% |
|
:: set OPENSSL_INCLUDE_DIR=%Win32OPENSSL_INCLUDE_DIR% |
|
:: set OPENSSL_LIBRARIES=%Win32OPENSSL_LIBRARIES% |
|
|
|
:: Generate build for MSVS 2015 |
|
:: cmake .. -G"Visual Studio 14" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"OPENSSL_ROOT_DIR=../../openssl" -D"OPENSSL_LIBRARIES=../../openssl/ssl" |
|
:: cmake .. -G"Visual Studio 14" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" |
|
:: with OpenSSL DLL: |
|
:: cmake .. -G"Visual Studio 14" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=OpenSSL" |
|
cmake .. -G"Visual Studio 14" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=OpenSSL" -D"OPENSSL_USE_STATIC_LIBS=TRUE" -D"OPENSSL_MSVC_STATIC_RT=TRUE" |
|
:: cmake .. -G"Visual Studio 14" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=OpenSSL" -D"OPENSSL_ROOT_DIR=%OPENSSL_ROOT_DIR%" -D"OPENSSL_LIBRARIES=%OPENSSL_LIBRARIES%" |
|
:: cmake .. -G"Visual Studio 14" -D"BUILD_SHARED_LIBS=1" -D"CMAKE_BUILD_TYPE=Release" -D"CRYPTO_BACKEND=WinCNG" |
|
|
|
:: needs to be after the above cmake as that one generates the vcxproj files |
|
powershell -file ..\fix-vcxproj-files.ps1 |
|
|
|
set Platform= |
|
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" |
|
call msbuild libssh2.sln /p:Configuration=Release /p:Platform=Win32 |
|
:: to find out various build aspects (like imports from VCRUNTIME140 and oher DLLs) |
|
dumpbin /headers example\Release\libssh2.dll | find "machine" |
|
dumpbin /all example\Release\libssh2.dll > example\Release\libssh2.dll.dumpbin.txt |
|
tdump example\Release\libssh2.dll > example\Release\libssh2.dll.tdump.txt |
|
popd |
|
|
|
popd |
|
|
|
:end |
|
endlocal |