Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake build #56

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.14)

project(binacpp)

set(LIBCURL_DIR "lib/libcurl-7.56.0")
set(LIBWS_DIR "lib/libwebsockets-2.4.0")
set(CMAKE_VERBOSE_MAKEFILE ON)

include_directories(${LIBCURL_DIR}/include)
include_directories(${LIBWS_DIR}/include)

link_directories(${LIBCURL_DIR}/lib)
link_directories(${LIBWS_DIR}/lib)

include(FetchContent)

FetchContent_Declare(
jsoncpp
GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp.git
GIT_TAG 1.8.4
CONFIGURE_COMMAND "-DBUILD_SHARED_LIB=OFF"
)

FetchContent_MakeAvailable(jsoncpp)

include_directories(${jsoncpp_SOURCE_DIR}/include)

add_subdirectory(example)
add_subdirectory(src)
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,22 @@ and -L<lib path> and -l<libname> for linker to link against shared libraries.
libbinacpp_dir=../lib/libbinacpp
libbinacpp_include=${libbinacpp_dir}/include
libbinacpp_lib=${libbinacpp_dir}/lib
#### Build Instructions
To build binacpp shared library

mkdir build
cmake ..
make -j 4
cd src
make install


.
Then compile like this:


g++ -I$(libcurl_include) -I$(jsoncpp_include) -I$(libwebsockets_include) -I$(libbinacpp_include) \
example.cpp \
-L$(libcurl_lib) \
-L$(libwebsockets_lib) \
-L$(libbinacpp_lib) \
-lcurl -lcrypto -lwebsockets -lbinacpp -o example




To build examples

cd build/examples
make -j 4


And export LD\_LIBRARY\_PATH and run like this:

libcurl_dir=../lib/libcurl-7.56.0
Expand Down
20 changes: 20 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(LIBBINACPP_DIR "${CMAKE_SOURCE_DIR}/lib/libbinacpp")
include_directories(${LIBBINACPP_DIR}/include)
link_directories(${LIBBINACPP_DIR}/lib)

file(GLOB EXAMPLES "*.cpp")
file(GLOB SCRIPTS "*.sh")

foreach(SCRIPT ${SCRIPTS})
configure_file(${SCRIPT} ${CMAKE_BINARY_DIR}/example COPYONLY)
endforeach()

set(ITER 0)
foreach(EXAMPLE ${EXAMPLES})
get_filename_component(TARGET_NAME ${EXAMPLE} NAME_WE)
message("Build executable - ${TARGET_NAME}")
add_executable(${TARGET_NAME} ${EXAMPLE})
add_dependencies(${TARGET_NAME} binacpp)
target_link_libraries(${TARGET_NAME} curl jsoncpp_lib_static crypto websockets binacpp)
math(EXPR ITER "${ITER} + 1")
endforeach()
36 changes: 0 additions & 36 deletions example/Makefile

This file was deleted.

10 changes: 5 additions & 5 deletions example/example_depthCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using namespace std;

map < string, map <double,double> > depthCache;
int lastUpdateId;
unsigned long lastUpdateId;

//------------------------------
void print_depthCache() {
Expand Down Expand Up @@ -45,9 +45,9 @@ void print_depthCache() {
int ws_depth_onData( Json::Value &json_result ) {

int i;

int new_updateId = json_result["u"].asInt();

unsigned long new_updateId = json_result["u"].asUInt64();

if ( new_updateId > lastUpdateId ) {

for ( i = 0 ; i < json_result["b"].size() ; i++ ) {
Expand Down Expand Up @@ -95,8 +95,8 @@ int main() {
BinaCPP::get_depth( symbol.c_str(), 20, result ) ;

// Initialize the lastUpdateId
lastUpdateId = result["lastUpdateId"].asInt();
lastUpdateId = result["lastUpdateId"].asUInt64();

for ( int i = 0 ; i < result["asks"].size(); i++ ) {

double price = atof( result["asks"][i][0].asString().c_str() );
Expand Down
Loading