diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..567609b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.travis.yml b/.travis.yml index c50b1933..50c48f3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,14 +7,6 @@ compiler: os: - linux -before_script: - - wget -q -O - http://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.gz | tar -xz - - cd boost_1_64_0 && ./bootstrap.sh --with-libraries=coroutine,context,chrono,system,thread,regex,filesystem - - ./b2 --ignore-site-config && cd .. - - mkdir build - - cd build - - cmake -DBOOST_ROOT=`pwd`/../boost_1_64_0 .. - addons: apt: sources: @@ -26,13 +18,19 @@ addons: - lcov script: - - $CXX --version - - make - - make test - - if [ "$CXX" == "g++-5" ]; then whereis gcov-5; fi - - if [ "$CXX" == "g++-5" ]; then make coverage VERBOSE=1; bash <(curl -s https://codecov.io/bash) -X gcov; fi - + - mkdir build && cd build + - conan install .. --build missing + - cmake .. && make VERBOSE=1 && ctest + - if [ "$CXX" == "g++-5" ]; then lcov --directory . --capture --output-file coverage.info --gcov-tool gcov-5; fi + - if [ "$CXX" == "g++-5" ]; then lcov --remove coverage.info '/*.conan/*' '/usr/*' '/*/t/*' --output-file coverage.info.cleaned; fi + - if [ "$CXX" == "g++-5" ]; then rm coverage.info; fi + - if [ "$CXX" == "g++-5" ]; then bash <(curl -s https://codecov.io/bash) -X gcov ; fi install: - - if [ "$CXX" = "g++" ]; then export CXX="g++-5"; export CC="gcc-5"; fi - - if [ "$CXX" = "clang++" ]; then export CXX="clang++"; fi + - if [ "$CXX" == "g++" ]; then export CXX="g++-5"; export CC="gcc-5"; export CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"; export CXXFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"; fi + - if [ "$CXX" == "clang++" ]; then export CXX="clang++"; fi + - sudo apt-get update -qq + - pip install --user conan + - conan remote add conan-community https://api.bintray.com/conan/conan-community/conan + - conan user + diff --git a/CMakeLists.txt b/CMakeLists.txt index fa8fdff7..546fb50c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.0) project (bredis) +find_package (Threads) + set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -10,18 +12,8 @@ enable_testing() add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) #add_definitions(-DBREDIS_DEBUG) -find_package( - Boost - COMPONENTS - chrono - coroutine - context - filesystem - regex - system - thread - REQUIRED -) +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") @@ -58,85 +50,15 @@ if(CMAKE_COMPILER_IS_GNUCXX) ) endif() -include_directories(${bredis_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS}) -MESSAGE(STATUS "boost inc: " ${Boost_INCLUDE_DIRS}) -MESSAGE(STATUS "boost libs: " ${Boost_LIBRARIES}) - -add_library(catch_lib t/tests-main.cpp) - -if(WIN32) - set(Boost_USE_MULTITHREADED ON) - set(LINK_DEPENDENCIES ${Boost_LIBRARIES} catch_lib) - add_definitions(-DBOOST_ALL_DYN_LINK -DBOOST_THREAD_USE_LIB -D_WIN32_WINNT=0x0501) -else() - set(LINK_DEPENDENCIES pthread ${Boost_LIBRARIES} catch_lib) -endif() +include_directories(${bredis_SOURCE_DIR}/include) +#include_directories(${bredis_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS}) +#MESSAGE(STATUS "boost inc: " ${Boost_INCLUDE_DIRS}) +#MESSAGE(STATUS "boost libs: " ${Boost_LIBRARIES}) +# ASIO maintenance is lagging behind the rest of boost, see +# https://github.com/chriskohlhoff/asio/pull/200 for one of the proposed patches. +set(DISABLE_COROUTINES true) +add_subdirectory(t) add_subdirectory(examples) -add_executable(t-05-protocol t/05-protocol.cpp) -target_link_libraries(t-05-protocol ${LINK_DEPENDENCIES}) -add_test("t-05-protocol" t-05-protocol) - -add_executable(t-06-fragmented-buffer t/06-fragmented-buffer.cpp) -target_link_libraries(t-06-fragmented-buffer ${LINK_DEPENDENCIES}) -add_test("t-06-fragmented-buffer" t-06-fragmented-buffer) - -add_executable(t-07-extract t/07-extract.cpp) -target_link_libraries(t-07-extract ${LINK_DEPENDENCIES}) -add_test("t-07-extract" t-07-extract) - -add_executable(t-08-markers t/08-markers.cpp) -target_link_libraries(t-08-markers ${LINK_DEPENDENCIES}) -add_test("t-07-extract" t-08-markers) - -add_executable(t-10-ping t/10-ping.cpp) -target_link_libraries(t-10-ping ${LINK_DEPENDENCIES}) -add_test("t-10-ping" t-10-ping) - -add_executable(t-11-multi-ping t/11-multi-ping.cpp) -target_link_libraries(t-11-multi-ping ${LINK_DEPENDENCIES}) -add_test("t-11-multi-ping" t-11-multi-ping) - -add_executable(t-12-basic-types t/12-basic-types.cpp) -target_link_libraries(t-12-basic-types ${LINK_DEPENDENCIES}) -add_test("t-12-basic-types" t-12-basic-types) - -add_executable(t-13-protol-error t/13-protol-error.cpp) -target_link_libraries(t-13-protol-error ${LINK_DEPENDENCIES}) -add_test("t-13-protol-error" t-13-protol-error) - -if(NOT WIN32) -add_executable(t-14-uds t/14-uds.cpp) -target_link_libraries(t-14-uds ${LINK_DEPENDENCIES}) -add_test("t-14-uds" t-14-uds) -endif() - -add_executable(t-15-cancellation t/15-cancellation.cpp) -target_link_libraries(t-15-cancellation ${LINK_DEPENDENCIES}) -add_test("t-15-cancellation" t-15-cancellation) - -add_executable(t-16-close-connection t/16-close-connection.cpp) -target_link_libraries(t-16-close-connection ${LINK_DEPENDENCIES}) -add_test("t-16-close-connection" t-16-close-connection) - -add_executable(t-17-sync t/17-sync.cpp) -target_link_libraries(t-17-sync ${LINK_DEPENDENCIES}) -add_test("t-17-sync" t-17-sync) - -add_executable(t-18-subscription t/18-subscription.cpp) -target_link_libraries(t-18-subscription ${LINK_DEPENDENCIES}) -add_test("t-18-subscription" t-18-subscription) - -add_executable(t-19-transaction t/19-transaction.cpp) -target_link_libraries(t-19-transaction ${LINK_DEPENDENCIES}) -add_test("t-19-transaction" t-19-transaction) - -add_executable(t-20-promise t/20-promise.cpp) -target_link_libraries(t-20-promise ${LINK_DEPENDENCIES}) -add_test("t-20-promise" t-20-promise) - -add_executable(t-21-coroutine t/21-coroutine.cpp) -target_link_libraries(t-21-coroutine ${LINK_DEPENDENCIES}) -add_test("t-21-coroutine" t-21-coroutine) diff --git a/appveyor.yml b/appveyor.yml index c34c86e9..1001f469 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,21 +8,23 @@ platform: # enable rdp #init: -# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - +# - ps: "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))" #on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) +# - ps: "$blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))" -environment: - BOOST_ROOT: "C:\\Libraries\\boost_1_64_0" +#environment: +# BOOST_ROOT: "C:\\Libraries\\boost_1_64_0" # BOOST_LIBRARYDIR: "C:\\Libraries\\boost_1_64_0\\lib32-msvc-15.0" before_build: - cmake --version - - echo %BOOST_ROOT% - - dir "C:\Libraries" - - dir "%BOOST_ROOT%" + #- echo %BOOST_ROOT% + #- dir "C:\Libraries" + #- dir "%BOOST_ROOT%" + - cmd: set PATH=%PATH%;%PYTHON%/Scripts/ + - cmd: pip.exe install conan + - cmd: conan --version - ps: wget 'https://github.com/MSOpenTech/redis/releases/download/win-3.0.504/Redis-x64-3.0.504.zip' -OutFile "Redis-x64-3.0.504.zip" - '@ECHO redis downloaded deployed' - dir @@ -31,15 +33,21 @@ before_build: # redis - set PATH=%APPVEYOR_BUILD_FOLDER%;%PATH% # boost - - set PATH=%BOOST_ROOT%\lib64-msvc-14.1;%PATH% + # - set PATH=%BOOST_ROOT%\lib64-msvc-14.1;%PATH% - echo %PATH% build_script: - - cmake -G "Visual Studio 15 2017 Win64" -H. -B_builds -DBOOST_ROOT="%BOOST_ROOT%" -# -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" - - cmake --build _builds + - cmd: mkdir build + - cmd: cd build + - cmd: conan install .. --build missing -o boost:shared=True -o boost:without_filesystem=False + - cmd: cmake ../ -G "Visual Studio 15 2017 Win64" + - cmd: cmake --build . --config Release test_script: - - ps: cd _builds - - ctest -VV -C "%CONFIG%" +# - ps: cd builds + - dir + # copy boost dlls into bin folder + - conan imports .. + - cmd: cp ../redis-server.exe bin + - ctest -VV -C "%CONFIG%" diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000..b2b90bfa --- /dev/null +++ b/conanfile.py @@ -0,0 +1,70 @@ +from conans import ConanFile, CMake, tools + + +class BredisConan(ConanFile): + name = "bredis" + version = "0.05" + license = "" + url = "https://github.com/basiliscos/cpp-bredis" + description = "MIT" + settings = "os", "compiler", "build_type", "arch" + + requires = "boost/1.66.0@conan/stable" + default_options = ( + "boost:shared=True", + "boost:header_only=False", + "boost:without_math=True", + "boost:without_wave=True", + "boost:without_container=True", + "boost:without_exception=True", + "boost:without_graph=True", + "boost:without_iostreams=True", + "boost:without_locale=True", + "boost:without_log=True", + "boost:without_program_options=True", + "boost:without_random=True", + "boost:without_regex=True", + "boost:without_mpi=True", + "boost:without_serialization=True", + "boost:without_signals=True", + "boost:without_coroutine=False", + "boost:without_fiber=True", + "boost:without_context=False", + "boost:without_timer=True", + "boost:without_thread=False", + "boost:without_chrono=True", + "boost:without_date_time=True", + "boost:without_atomic=True", + "boost:without_filesystem=True", + "boost:without_system=True", + "boost:without_graph_parallel=True", + "boost:without_python=True", + "boost:without_stacktrace=True", + "boost:without_test=True", + "boost:without_type_erasure=True", + ) + + exports_sources = "include/*", "CMakeLists.txt", "examples/speed_test_async_multi.cpp" + no_copy_source = True + + generators = "cmake" + exports = "CMakeLists.txt", "include*", "examples*", "t*" + + # this is not building a library, just tests + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + cmake.test() + def package(self): + self.copy("*.hpp", dst="include", src="include") + self.copy("*.ipp", dst="include", src="include") + + def package_id(self): + self.info.header_only() + + def imports(self): + self.copy("*.dll", src="bin", dst="bin", ignore_case=True) + + #def package_info(self): + # self.cpp_info.libs = ["cpp-bredis"] diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 55aeb09d..f8ca45b4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,8 +1,16 @@ -add_executable(stream-parse stream-parse.cpp) -target_link_libraries(stream-parse ${Boost_LIBRARIES}) +if(WIN32) + set(Boost_USE_MULTITHREADED ON) + set(LINK_DEPENDENCIES ${Boost_LIBRARIES} catch_lib) + add_definitions(-DBOOST_ALL_DYN_LINK -DBOOST_THREAD_USE_LIB -D_WIN32_WINNT=0x0501) +endif() + +if(NOT DISABLE_COROUTINES) + add_executable(stream-parse stream-parse.cpp) + target_link_libraries(stream-parse ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +endif() add_executable(synch-subscription synch-subscription.cpp) -target_link_libraries(synch-subscription ${Boost_LIBRARIES}) +target_link_libraries(synch-subscription ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) add_executable(speed_test_async_multi speed_test_async_multi.cpp) -target_link_libraries(speed_test_async_multi ${Boost_LIBRARIES}) +target_link_libraries(speed_test_async_multi ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt new file mode 100644 index 00000000..9a859e44 --- /dev/null +++ b/t/CMakeLists.txt @@ -0,0 +1,79 @@ +add_library(catch_lib tests-main.cpp) + +if(WIN32) + set(Boost_USE_MULTITHREADED ON) + set(LINK_DEPENDENCIES ${CONAN_LIBS} catch_lib) + add_definitions(-DBOOST_ALL_DYN_LINK -DBOOST_THREAD_USE_LIB -D_WIN32_WINNT=0x0501) +else() + set(LINK_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT} ${CONAN_LIBS} catch_lib) +endif() + +MESSAGE(STATUS "RUNTIME_OUTPUT_DIRECTORY: " ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + +add_executable(t-05-protocol 05-protocol.cpp) +target_link_libraries(t-05-protocol ${LINK_DEPENDENCIES}) +add_test("t-05-protocol" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-05-protocol") + +add_executable(t-06-fragmented-buffer 06-fragmented-buffer.cpp) +target_link_libraries(t-06-fragmented-buffer ${LINK_DEPENDENCIES}) +add_test("t-06-fragmented-buffer" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-06-fragmented-buffer") + +add_executable(t-07-extract 07-extract.cpp) +target_link_libraries(t-07-extract ${LINK_DEPENDENCIES}) +add_test("t-07-extract" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-07-extract") + +add_executable(t-08-markers 08-markers.cpp) +target_link_libraries(t-08-markers ${LINK_DEPENDENCIES}) +add_test("t-07-extract" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-08-markers") + +add_executable(t-10-ping 10-ping.cpp) +target_link_libraries(t-10-ping ${LINK_DEPENDENCIES}) +add_test("t-10-ping" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-10-ping") + +add_executable(t-11-multi-ping 11-multi-ping.cpp) +target_link_libraries(t-11-multi-ping ${LINK_DEPENDENCIES}) +add_test("t-11-multi-ping" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-11-multi-ping") + +add_executable(t-12-basic-types 12-basic-types.cpp) +target_link_libraries(t-12-basic-types ${LINK_DEPENDENCIES}) +add_test("t-12-basic-types" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-12-basic-types") + +add_executable(t-13-protol-error 13-protol-error.cpp) +target_link_libraries(t-13-protol-error ${LINK_DEPENDENCIES}) +add_test("t-13-protol-error" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-13-protol-error") + +if(NOT WIN32) + add_executable(t-14-uds 14-uds.cpp) + target_link_libraries(t-14-uds ${LINK_DEPENDENCIES}) + add_test("t-14-uds" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-14-uds") +endif() + +add_executable(t-15-cancellation 15-cancellation.cpp) +target_link_libraries(t-15-cancellation ${LINK_DEPENDENCIES}) +add_test("t-15-cancellation" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-15-cancellation") + +add_executable(t-16-close-connection 16-close-connection.cpp) +target_link_libraries(t-16-close-connection ${LINK_DEPENDENCIES}) +add_test("t-16-close-connection" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-16-close-connection") + +add_executable(t-17-sync 17-sync.cpp) +target_link_libraries(t-17-sync ${LINK_DEPENDENCIES}) +add_test("t-17-sync" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-17-sync") + +add_executable(t-18-subscription 18-subscription.cpp) +target_link_libraries(t-18-subscription ${LINK_DEPENDENCIES}) +add_test("t-18-subscription" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-18-subscription") + +add_executable(t-19-transaction 19-transaction.cpp) +target_link_libraries(t-19-transaction ${LINK_DEPENDENCIES}) +add_test("t-19-transaction" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-19-transaction") + +add_executable(t-20-promise 20-promise.cpp) +target_link_libraries(t-20-promise ${LINK_DEPENDENCIES}) +add_test("t-20-promise" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-20-promise") + +if(NOT DISABLE_COROUTINES) + add_executable(t-21-coroutine 21-coroutine.cpp) + target_link_libraries(t-21-coroutine ${LINK_DEPENDENCIES}) + add_test("t-21-coroutine" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/t-21-coroutine") +endif()