Skip to content

Commit 47139b8

Browse files
committed
Merge branch 'feature_mac' into dev
2 parents f461b27 + ed4d22c commit 47139b8

35 files changed

+8667
-994
lines changed

.gitignore

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,26 @@
3535
.vscode
3636
*.dSYM
3737
.idea
38-
38+
.DS_store
3939
cmake-build-debug
4040
build
41-
41+
*-build
42+
demo/openapi_cpp_test/Debug/
43+
demo/openapi_cpp_test/Release/
44+
demo/openapi_cpp_test/myeasylog.log
45+
output/Debug/openapi-cpp-sdk.exp
46+
output/Debug/openapi-cpp-sdk.ilk
47+
output/Debug/openapi-cpp-sdk.pdb
48+
output/Debug/openapi_cpp_test.ilk
49+
output/Debug/openapi_cpp_test.pdb
50+
output/Release/openapi-cpp-sdk.exp
51+
output/Release/openapi-cpp-sdk.pdb
52+
output/Release/openapi_cpp_test.iobj
53+
output/Release/openapi_cpp_test.ipdb
54+
output/Release/openapi_cpp_test.pdb
55+
/output/Release/openapi-cpp-sdk.ipdb
56+
/output/Release/openapi-cpp-sdk.iobj
57+
58+
Debug/
59+
Release/
60+
*.log

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

CMakeLists.txt

100755100644
Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ project(tigerapi VERSION ${PROJECT_VERSION})
1616

1717
# Configure required libraries ...
1818
if(UNIX) # Darwing or Linux
19-
19+
2020
find_package(Boost REQUIRED COMPONENTS system thread log program_options chrono)
2121
find_package(Threads REQUIRED)
2222

@@ -31,7 +31,7 @@ if(UNIX) # Darwing or Linux
3131
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
3232
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/*)
3333
# Prefer the latest (make the latest one first)
34-
list(REVERSE OPENSSL_ROOT_DIR)
34+
list(REVERSE OPENSSL_ROOT_DIR)
3535

3636
find_package(OpenSSL 1.1 REQUIRED)
3737
set(OPENSSL_VERSION "1.1.1q")
@@ -42,42 +42,8 @@ if(UNIX) # Darwing or Linux
4242
set(OPENSSL_VERSION "1.0.1")
4343
endif()
4444

45-
elseif(WIN32) # Windows systems including Win64.
46-
#set(CMAKE_PREFIX_PATH "D:/projects/vcpkg/packages/")
47-
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/projects/boost_1_81_0")
48-
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/projects/boost_1_81_0/lib")
49-
FIND_PACKAGE(Boost)
50-
IF (Boost_FOUND)
51-
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
52-
ADD_DEFINITIONS( "-DHAS_BOOST" )
53-
ENDIF()
54-
55-
#find_package(Boost REQUIRED COMPONENTS system thread log program_options chrono)
56-
#find_package(Threads REQUIRED)
57-
58-
59-
file(GLOB OPENSSL_ROOT_DIR D:/projects/vcpkg/packages/openssl_x86-windows/*)
60-
# Prefer the latest (make the latest one first)
61-
list(REVERSE OPENSSL_ROOT_DIR)
62-
find_package(OpenSSL REQUIRED)
63-
64-
#file(GLOB cpprestsdk_DIR D:/projects/vcpkg/packages/cpprestsdk_x86-windows/share/*)
65-
#list(REVERSE cpprestsdk_DIR)
66-
# find_package(cpprestsdk CONFIG REQUIRED)
67-
# cpprest
68-
#find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
69-
#find_library(CPPREST_LIBRARY NAMES cpprest)
70-
71-
72-
73-
#file(GLOB ZLIB_ROOT D:/projects/vcpkg/packages/zlib_x86-windows/*)
74-
#(REVERSE ZLIB_ROOT)
75-
#find_package(ZLIB REQUIRED)
76-
77-
#set(CMAKE_PREFIX_PATH "D:/projects/vcpkg/packages/brotli_x86-windows/share/unofficial-brotli")
78-
#file(GLOB unofficial-brotli_DIR D:/projects/vcpkg/packages/brotli_x86-windows/*)
79-
#list(REVERSE unofficial-brotli_DIR)
80-
#find_package(unofficial-brotli CONFIG REQUIRED)
45+
elseif(WIN32)
46+
message(FATAL_ERROR "-- please compile via Visual Studio ")
8147
else()
8248
message(FATAL_ERROR "-- Unsupported platform sorry! :( ")
8349
endif()
@@ -94,15 +60,17 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
9460

9561
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -DBOOST_LOG_DYN_LINK")
9662

97-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
98-
add_compile_options(/D BOOST_LOG_DYN_LINK /MT)
9963
endif()
10064

10165
# Project construction ...
10266
# src files ...
103-
add_executable(${PROJECT_NAME} src/main.cpp src/base64.h
67+
add_library(${PROJECT_NAME} src/common/base64.h
10468
src/tiger_client.cpp include/tigerapi/tiger_client.h include/tigerapi/constants.h
105-
include/tigerapi/utils.h src/utils.cpp include/tigerapi/service_types.h include/tigerapi/quote_client.h src/quote_client.cpp src/trade_client.cpp include/tigerapi/model.h src/order_util.cpp include/tigerapi/order_util.h src/contract_util.cpp include/tigerapi/contract_util.h include/tigerapi/client_config.h include/tigerapi/log.h src/common/sign_util.h)
69+
include/tigerapi/utils.h src/utils.cpp include/tigerapi/service_types.h include/tigerapi/quote_client.h
70+
src/quote_client.cpp src/trade_client.cpp include/tigerapi/model.h src/order_util.cpp
71+
include/tigerapi/order_util.h src/contract_util.cpp include/tigerapi/contract_util.h
72+
include/tigerapi/client_config.h src/common/sign_util.h
73+
include/common/easylogging++.h src/common/easylogging++.cc)
10674

10775
# headers search paths ...
10876
#set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
@@ -114,10 +82,6 @@ if(APPLE)
11482
set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
11583

11684
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${CPPREST_LIBRARY} ${ZIP_LIBRARY})
117-
elseif(WIN32)
118-
set(ZIP_LIBRARY "D:/projects/vcpkg/packages/zlib_x86-windows/zlib_x86-windows/lib/zlib.lib")
119-
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
120-
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY})
12185
else()
12286
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
12387
set(LIBRARIES_SEARCH_PATHS ${CPPREST_LIBRARY} ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY})
@@ -141,7 +105,8 @@ else()
141105

142106
endif()
143107

144-
#set(CMAKE_INSTALL_PREFIX "./")
108+
109+
145110

146111
install(DIRECTORY include/
147112
DESTINATION "include"

README.md

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
brew install boost
1111
```
1212

13-
安装方式二:源码安装
13+
安装方式二:源码安装
1414
1. 下载源码到任意路径: https://www.boost.org/users/history/version_1_81_0.html,
15-
以 /usr/local/ 为例
15+
以 /usr/local/ 为例
1616
```shell
1717
cd /usr/local/
1818
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.bz2
@@ -47,26 +47,42 @@ make install
4747
[参考文档](https://github.com/Microsoft/cpprestsdk/wiki/Getting-Started-Tutorial)
4848
直接通过包管理软件安装的 cpprestsdk 可能不是最新版本, 可能会有未知问题
4949
50-
### 编译安装 tigerapi sdk
50+
### 编译 tigerapi sdk
51+
若使用编译好的sdk,此步骤可跳过
52+
准备工作:根据系统环境调整 CMakeLists.txt 的相关路径
53+
54+
1. 进入源码目录
55+
2. 创建编译目录
56+
```
57+
mkdir build
58+
cd build
59+
```
60+
3. 编译
61+
```
62+
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
63+
make -j 6
64+
make install
65+
```
66+
67+
### 安装 tigerapi sdk
68+
将头文件放入头文件路径, 如 /usr/local/include
69+
将库文件放入库文件路径, 如 /usr/local/lib/
70+
71+
72+
### 验证测试
73+
编译运行demo项目
74+
5175
5276
5377
## Windows
5478
依赖:Visual Stodio C++ 开发环境 https://visualstudio.microsoft.com/zh-hans/
55-
下载安装Visual Stodio Installer,勾选 "使用C++的桌面开发"
79+
下载安装Visual Stodio Installer,勾选 "使用C++的桌面开发"
80+
81+
使用[vcpkg](https://vcpkg.io/en/getting-started.html)
82+
5683
5784
### 安装 boost
5885
[参考文档](https://www.boost.org/doc/libs/1_81_0/more/getting_started/windows.html)
59-
60-
- 方式一:使用源码安装
61-
说明,对于Windows使用Cygwin或WSL的,参考Linux的步骤
62-
1. 下载 https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.zip
63-
2. 解压到任意目录, 如 D:\boost_1_81_0
64-
3. 编译
65-
```
66-
bootstrap.bat
67-
.\b2
68-
```
69-
- 方式二:使用[vcpkg](https://vcpkg.io/en/getting-started.html)
7086
```
7187
vcpkg install boost
7288
```
@@ -76,30 +92,12 @@ vcpkg install boost
7692
vcpkg install openssl
7793
```
7894
79-
### 编译安装 cpprestsdk
80-
81-
- 方式一:源码安装
82-
1. `git clone https://github.com/Microsoft/cpprestsdk.git`
83-
2. `vcpkg install --triplet x64-windows zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli`
84-
3. 编译
85-
```
86-
cd cpprestsdk
87-
88-
cpprestsdk> mkdir build.x64
89-
cpprestsdk> cd build.x64
90-
cpprestsdk/build.x64> cmake ../Release -A x64 -DCMAKE_TOOLCHAIN_FILE=/REPLACE_THIS_WITH_PATH_TO/vcpkg/scripts/buildsystems/vcpkg.cmake
91-
```
92-
93-
94-
- 方式二:使用vcpkg
95-
95+
### 安装 cpprestsdk
9696
```
9797
PS> vcpkg install cpprestsdk cpprestsdk:x64-windows
9898
```
9999
100-
101-
### 编译 tigerapi sdk
102-
100+
### 安装 tigerapi sdk
103101
104102
105103
@@ -110,7 +108,7 @@ dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicudata.70.dylib
110108
Referenced from: /usr/local/opt/boost/lib/libboost_log-mt.dylib
111109
Reason: image not found
112110
```
113-
Fix:
111+
Fix:
114112
```
115113
cd /usr/local/opt/icu4c/lib
116114
ln -s libicudata.dylib libicudata.70.dylib

demo/CMakeLists.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
4+
project(openapi_cpp_test)
5+
6+
7+
# Configure required libraries ...
8+
if(UNIX) # Darwing or Linux
9+
10+
find_package(Boost REQUIRED COMPONENTS system thread log program_options chrono)
11+
find_package(Threads REQUIRED)
12+
13+
# cpprest
14+
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
15+
find_library(CPPREST_LIBRARY NAMES cpprest)
16+
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
17+
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
18+
19+
# tigerapi
20+
find_path(TIGERAPI_INCLUDE_DIR NAMES common/easylogging++.h tigerapi/client_config.h )
21+
find_library(TIGERAPI_LIBRARY NAMES libtigerapi.a)
22+
23+
if(APPLE)
24+
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
25+
# file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*)
26+
file(GLOB OPENSSL_ROOT_DIR /usr/local/opt/openssl/*)
27+
# Prefer the latest (make the latest one first)
28+
list(REVERSE OPENSSL_ROOT_DIR)
29+
30+
find_package(OpenSSL 1.1 REQUIRED)
31+
set(OPENSSL_VERSION "1.1.1q")
32+
33+
34+
else()
35+
find_package(OpenSSL 1.0.1 REQUIRED)
36+
set(OPENSSL_VERSION "1.0.1")
37+
endif()
38+
39+
elseif(WIN32) # Windows systems including Win64.
40+
message(FATAL_ERROR "-- please compile by visual studio")
41+
else()
42+
message(FATAL_ERROR "-- Unsupported platform sorry! :( ")
43+
endif()
44+
45+
# Configure compiler options ...
46+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
47+
48+
message("-- configuring clang options")
49+
set(CMAKE_CXX_FLAGS "-arch x86_64 -std=c++11 -stdlib=libc++ -DBOOST_LOG_DYN_LINK -Wno-deprecated-declarations")
50+
51+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
52+
53+
message("-- configuring gcc options")
54+
55+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -DBOOST_LOG_DYN_LINK")
56+
endif()
57+
58+
# Project construction ...
59+
# src files ...
60+
add_executable(${PROJECT_NAME} openapi_cpp_test/openapi_cpp_test.cpp)
61+
62+
# headers search paths ...
63+
set(HEADER_SEARCH_PATHS ${CPPREST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${TIGERAPI_INCLUDE_DIR})
64+
65+
# library search paths ...
66+
if(APPLE)
67+
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
68+
set(ZIP_LIBRARY "/usr/local/Cellar/zlib/1.2.12/lib/libz.dylib")
69+
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY} ${CPPREST_LIBRARY} ${TIGERAPI_LIBRARY})
70+
else()
71+
set(OPENSSL_LIBS "${OPENSSL_LIBRARIES}")
72+
set(LIBRARIES_SEARCH_PATHS ${OPENSSL_LIBS} ${Boost_LIBRARIES} ${ZIP_LIBRARY} ${CPPREST_LIBRARY} ${TIGERAPI_LIBRARY})
73+
endif()
74+
75+
message(LIBRARIES_SEARCH_PATHS " ${LIBRARIES_SEARCH_PATHS}")
76+
77+
include_directories(${HEADER_SEARCH_PATHS})
78+
if (APPLE)
79+
target_link_libraries(${PROJECT_NAME} "-framework CoreFoundation")
80+
target_link_libraries(${PROJECT_NAME} "-framework Security")
81+
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
82+
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-W1, -F/Library/Frameworks ")
83+
else()
84+
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
85+
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
86+
87+
endif()

0 commit comments

Comments
 (0)