Skip to content

Commit

Permalink
Update Windows build script and documents
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Oct 15, 2021
1 parent 87745f2 commit 4adbc8b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 136 deletions.
8 changes: 7 additions & 1 deletion README-EmbeddedSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Cross Build

* OS: `Ubuntu 14.04 LTS, 64 Bits`
* OS: `Ubuntu 20.04 LTS, 64 Bits`

```
apt-get update
Expand All @@ -14,6 +14,12 @@ apt-get install -y build-essential cmake git wget libssl-dev
wget http://downloads.openwrt.org.cn/PandoraBox/PandoraBox-Toolchain-ralink-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
tar zxvf PandoraBox-Toolchain-ralink-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
#
# cross build openssl
#
TODO: finish this.
Please complete this step yourself.
#
# cross build libevent
#
Expand Down
142 changes: 22 additions & 120 deletions README-Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,42 @@ Download binary distributions from https://cmake.org/download/ and install.
Add ```CmakeInstallDirectory\bin``` to ```PATH``` environment variable.


### libevent
### vcpkg

Libevent [release-2.1.12-stable](https://github.com/libevent/libevent/releases/tag/release-2.1.12-stable) is recommended because the earlier versions have a deadlock issue: [btcpool#75](https://github.com/btccom/btcpool/issues/75).
See https://github.com/microsoft/vcpkg for more details.

```cmd
wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar xf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
# fix missing files
cd WIN32-Code
wget https://raw.githubusercontent.com/libevent/libevent/master/WIN32-Code/getopt_long.c https://raw.githubusercontent.com/libevent/libevent/master/WIN32-Code/getopt.h https://raw.githubusercontent.com/libevent/libevent/master/WIN32-Code/getopt.c
cd ..
md build && cd build
cmake -DCMAKE_INSTALL_PREFIX="%appdata%\lib\libevent" -DEVENT__LIBRARY_TYPE=STATIC -DEVENT__DISABLE_OPENSSL=ON -A x64 ..
start libevent.sln
```
git clone https://github.com/microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
Then build the ```INSTALL``` project in Visual Studio, it will be installed to ```%appdata%\lib\glog```.

Use ```-DEVENT__DISABLE_OPENSSL=ON``` to avoid finding ```openssl```.


### Glog

Glog [0.3.5](https://github.com/google/glog/releases/tag/v0.3.5) is recommended.

Glog ```0.3.4``` has an issue for VS2015 or later that duplicate definition ```snprintf``` at src/windows/port.cc, comment needed. Even that, the test case crashed with an exception.
.\vcpkg\vcpkg.exe install openssl:x86-windows-static
.\vcpkg\vcpkg.exe install glog:x86-windows-static
.\vcpkg\vcpkg.exe install libevent[core,openssl,thread]:x86-windows-static
```cmd
wget https://github.com/google/glog/archive/v0.3.5.tar.gz
tar xf v0.3.5.tar.gz
cd glog-0.3.5
md build && cd build
cmake -DCMAKE_INSTALL_PREFIX="%appdata%\lib\glog" -A x64 ..
start google-glog.sln
.\vcpkg\vcpkg.exe install openssl:x64-windows-static
.\vcpkg\vcpkg.exe install glog:x64-windows-static
.\vcpkg\vcpkg.exe install libevent[core,openssl,thread]:x64-windows-static
```

Then build the ```INSTALL``` project in Visual Studio, it will be installed to ```%appdata%\lib\glog```.


### btcagent

You can build it with cmake and Visual Studio:

```cmd
git clone https://github.com/btccom/btcagent.git
cd btcagent
md build && cd build
cmake -DLIBEVENT_ROOT_DIR="%appdata%\lib\libevent" -DGLOG_ROOT_DIR="%appdata%\lib\glog" -A x64 ..
start PoolAgent.sln
# change to your vcpkg dir
set VCPKG_ROOT_DIR=C:/Users/user/source/repos/vcpkg
.\make.bat win32
.\make.bat win64
```

Then build ```ALL_BUILD``` project in Visual Studio. ```build\Debug\btcagent.exe``` is the final product, it static linked with libevent. But by default, it dynamic linked with VC++ runtime library. You must install ```Visual C++ Redistributable for Visual Studio 20xx``` at another computers.
Then build ```ALL_BUILD``` project in Visual Studio.

#### btcagent cmake options

There are ```btcagent``` specific Cmake variables (the values being the default):

Expand All @@ -83,87 +64,7 @@ POOLAGENT__USE_GLOG:BOOL=OFF
POOLAGENT__GLOG_TO_STDOUT:BOOL=OFF
```

## Static linking with VC++ runtime library

For static linking with VC++ runtime library, we use ```/MT``` in the project's ```Property Pages``` > ```C/C++``` > ```Code Generation``` > ```Runtime Library``` property instead of ```/MD``` by default. Using ```/MTd``` instead of ```/MDd``` for debug build.

All librarys the project reliant must linked with ```/MT``` or ```/MTd```, else some symbols will lost at the final linking.


### libevent & GLog

You can add there codes to the end of ```CMakeLists.txt``` that modify the default ```/MD``` & ```/MDd``` property to ```/MT``` & ```/MTd```:

```cmake
###
# static linking VC++ runtime library
###
macro(set_linking_vclib CompilerFlag LinkFlag)
string(REPLACE "/MDd" "" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MD" "" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MTd" "" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MT" "" ${CompilerFlag} "${${CompilerFlag}}")
set(${CompilerFlag} "${${CompilerFlag}} ${LinkFlag}")
message("${CompilerFlag}=${${CompilerFlag}}")
endmacro()
message("-- Static linking VC++ runtime library (/MT)")
set_linking_vclib(CMAKE_CXX_FLAGS_DEBUG "/MTd")
set_linking_vclib(CMAKE_C_FLAGS_DEBUG "/MTd")
set_linking_vclib(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd")
set_linking_vclib(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd")
set_linking_vclib(CMAKE_CXX_FLAGS_RELEASE "/MT")
set_linking_vclib(CMAKE_C_FLAGS_RELEASE "/MT")
set_linking_vclib(CMAKE_CXX_FLAGS_MINSIZEREL "/MT")
set_linking_vclib(CMAKE_C_FLAGS_MINSIZEREL "/MT")
```

Then build as normal.


### btcagent

Use ```-DPOOLAGENT__STATIC_LINKING_VC_LIB=ON``` with cmake command:

```cmd
md build && cd build
cmake -DPOOLAGENT__STATIC_LINKING_VC_LIB=ON -DLIBEVENT_ROOT_DIR="%appdata%\lib\libevent" -DGLOG_ROOT_DIR="%appdata%\lib\glog" -A x64 ..
start PoolAgent.sln
```

## Support Windows XP

Simply add an arg ```-T v140_xp``` to Cmake if build with Visual Studio.

```cmd
cmake -A win32 -T v141_xp ..
```

Libevent and GLog need the arg too.

### libevent

XP has not ```inet_ntop()``` and ```inet_pton()``` so must disable them or a "endpoint not found" will trigger when running.

Edit ```CMakeLists.txt``` and comment the two lines:

```cmake
#CHECK_FUNCTION_EXISTS_EX(inet_ntop EVENT__HAVE_INET_NTOP)
#CHECK_FUNCTION_EXISTS_EX(inet_pton EVENT__HAVE_INET_PTON)
```

And rebuild with clear build dir.

## 32bit or 64bit

```cmd
# 32bit
cmake -A win32 ..
# 64bit
cmake -A x64 ..
```
See [make.bat](make.bat) for usage.

## Configure & Run

Expand All @@ -172,6 +73,7 @@ config json file example:
{
"agent_listen_ip": "0.0.0.0",
"agent_listen_port": 3333,
"pool_use_tls": false,
"pools": [
["us.ss.btc.com", 1800, "kevin"],
["us.ss.btc.com", 1800, "kevin"]
Expand Down
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BtcAgent是定制的高效的专用矿池代理系统。其采用了自定义[

## 安装

* 操作系统: `Ubuntu 14.04 LTS, 64 Bits`
* 操作系统: `Ubuntu 20.04 LTS, 64 Bits`
* 嵌入式平台编译请参考:[嵌入式平台交叉编译](README-EmbeddedSystem.md)

```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Note:

## Install

* OS: `Ubuntu 14.04 LTS, 64 Bits`
* OS: `Ubuntu 20.04 LTS, 64 Bits`
* if you want build on Embedded System like open-wrt/dd-wrt/PandoraBox, please see: [build for Embedded System](README-EmbeddedSystem.md)

```
Expand Down
27 changes: 14 additions & 13 deletions make.bat
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
@echo off
cd %~dp0

if "%VCPKG_ROOT_DIR%"=="" set "VCPKG_ROOT_DIR=../../vcpkg"

:select_action
if "%1" == "" goto usage
if /i %1 == win64 goto make_win64
if /i %1 == xp goto make_xp
if /i %1 == win32 goto make_win32
if /i %1 == test goto make_test
if /i %1 == clean goto make_clean
goto usage

:usage
echo Usage:
echo set LIBEVENT_ROOT_DIR="%appdata%\lib\libevent"
echo set GLOG_ROOT_DIR="%appdata%\lib\glog"
echo set VCPKG_ROOT_DIR="C:/Users/user/source/repos/vcpkg"
echo make win64
echo make xp
echo make win32
echo make test
echo make clean
goto :eof

:make_win64
md build.win64
cd build.win64
cmake -DLIBEVENT_ROOT_DIR="%LIBEVENT_ROOT_DIR%" -DGLOG_ROOT_DIR="%GLOG_ROOT_DIR%" -DPOOLAGENT__STATIC_LINKING_VC_LIB=ON -DPOOLAGENT__USE_GLOG=ON -DPOOLAGENT__GLOG_TO_STDOUT=ON -A x64 ..
cmake -DCMAKE_BUILD_TYPE=Release "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT_DIR%/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static -DPOOLAGENT__STATIC_LINKING_VC_LIB=ON -DPOOLAGENT__GLOG_TO_STDOUT=ON ..
start PoolAgent.sln
cd ..
goto :eof

:make_xp
md build.xp
cd build.xp
cmake -DLIBEVENT_ROOT_DIR="%LIBEVENT_ROOT_DIR%" -DGLOG_ROOT_DIR="%GLOG_ROOT_DIR%" -DPOOLAGENT__STATIC_LINKING_VC_LIB=ON -DPOOLAGENT__USE_GLOG=ON -DPOOLAGENT__GLOG_TO_STDOUT=ON -A x86 -T v141_xp ..
:make_win32
md build.win32
cd build.win32
cmake -DCMAKE_BUILD_TYPE=Release "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT_DIR%/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static -A Win32 -DPOOLAGENT__STATIC_LINKING_VC_LIB=ON -DPOOLAGENT__GLOG_TO_STDOUT=ON ..
start PoolAgent.sln
cd ..
goto :eof

:make_test
echo ------ test.win64
build.win64\Release\unittest
echo ------ test.xp
build.xp\Release\unittest
echo ------ test.win32
build.win32\Release\unittest
goto :eof

:make_clean
echo ------ remove build.win64
rd /s /q build.win64
echo ------ remove build.xp
rd /s /q build.xp
echo ------ remove build.win32
rd /s /q build.win32
goto :eof

0 comments on commit 4adbc8b

Please sign in to comment.