diff options
-rw-r--r-- | .travis.yml | 88 | ||||
-rwxr-xr-x | .travis/install.sh | 24 | ||||
-rwxr-xr-x | .travis/run.sh | 13 | ||||
-rw-r--r-- | CMakeLists.txt | 23 | ||||
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | Dockerfile_test | 6 | ||||
-rw-r--r-- | appveyor.yml | 80 | ||||
-rw-r--r-- | build.py | 17 | ||||
-rw-r--r-- | conanfile.py | 61 | ||||
-rw-r--r-- | samples/echobot-conan/CMakeLists.txt | 9 | ||||
-rw-r--r-- | samples/echobot-conan/conanfile.py | 24 | ||||
-rw-r--r-- | samples/echobot-conan/example.cpp | 20 |
12 files changed, 355 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml index 37629fb..f4e6c94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,84 @@ -sudo: required +linux: &linux + os: linux + dist: xenial + language: python + python: "3.7" + services: + - docker +osx: &osx + os: osx + language: generic -services: - - docker +stages: + - unittest + - conan-linux + - conan-osx -script: - - docker build -t reo7sp/tgbot-cpp -f Dockerfile . - - docker build -t reo7sp/tgbot-cpp-test -f Dockerfile_test . - - docker run --rm reo7sp/tgbot-cpp-test +jobs: + include: + - <<: *linux + stage: unittest + name: unittest + sudo: required + script: + - docker build -t reo7sp/tgbot-cpp -f Dockerfile . + - docker build -t reo7sp/tgbot-cpp-test -f Dockerfile_test . + - docker run --rm reo7sp/tgbot-cpp-test + + - <<: *linux + stage: conan-linux + env: CONAN_GCC_VERSIONS=4.9 CONAN_DOCKER_IMAGE=conanio/gcc49 + - <<: *linux + stage: conan-linux + env: CONAN_GCC_VERSIONS=5 CONAN_DOCKER_IMAGE=conanio/gcc5 + - <<: *linux + stage: conan-linux + env: CONAN_GCC_VERSIONS=6 CONAN_DOCKER_IMAGE=conanio/gcc6 + - <<: *linux + stage: conan-linux + env: CONAN_GCC_VERSIONS=7 CONAN_DOCKER_IMAGE=conanio/gcc7 + - <<: *linux + stage: conan-linux + env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8 + + - <<: *linux + stage: conan-linux + env: CONAN_CLANG_VERSIONS=4.0 CONAN_DOCKER_IMAGE=conanio/clang40 + - <<: *linux + stage: conan-linux + env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50 + - <<: *linux + stage: conan-linux + env: CONAN_CLANG_VERSIONS=6.0 CONAN_DOCKER_IMAGE=conanio/clang60 + - <<: *linux + stage: conan-linux + env: CONAN_CLANG_VERSIONS=7.0 CONAN_DOCKER_IMAGE=conanio/clang7 CONAN_BUILD_POLICY=missing + - <<: *osx + stage: conan-osx + osx_image: xcode7.3 + env: CONAN_APPLE_CLANG_VERSIONS=7.3 CONAN_BUILD_POLICY=missing + - <<: *osx + stage: conan-osx + osx_image: xcode8.3 + env: CONAN_APPLE_CLANG_VERSIONS=8.1 CONAN_BUILD_POLICY=missing + - <<: *osx + stage: conan-osx + osx_image: xcode9 + env: CONAN_APPLE_CLANG_VERSIONS=9.0 + - <<: *osx + stage: conan-osx + osx_image: xcode9.4 + env: CONAN_APPLE_CLANG_VERSIONS=9.1 + - <<: *osx + stage: conan-osx + osx_image: xcode10 + env: CONAN_APPLE_CLANG_VERSIONS=10.0 + +install: + - chmod +x .travis/install.sh + - ./.travis/install.sh + +script: + - chmod +x .travis/run.sh + - ./.travis/run.sh diff --git a/.travis/install.sh b/.travis/install.sh new file mode 100755 index 0000000..657ecc1 --- /dev/null +++ b/.travis/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e +set -x + +if [[ "$(uname -s)" == 'Darwin' ]]; then + brew update || brew update + brew outdated pyenv || brew upgrade pyenv + brew install pyenv-virtualenv + brew install cmake || true + + if which pyenv > /dev/null; then + eval "$(pyenv init -)" + fi + + pyenv install 3.7.1 + pyenv virtualenv 3.7.1 conan + pyenv rehash + pyenv activate conan +fi + +pip install conan_package_tools +pip install conan +conan user diff --git a/.travis/run.sh b/.travis/run.sh new file mode 100755 index 0000000..0a3488e --- /dev/null +++ b/.travis/run.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e +set -x + +if [[ "$(uname -s)" == 'Darwin' ]]; then + if which pyenv > /dev/null; then + eval "$(pyenv init -)" + fi + pyenv activate conan +fi + +python build.py diff --git a/CMakeLists.txt b/CMakeLists.txt index c4f7195..290c91c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,24 @@ cmake_minimum_required(VERSION 2.8.4) project(TgBot) +if (${CONAN_EXPORTED}) + include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) + conan_basic_setup() +endif() + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + # options option(ENABLE_TESTS "Set to ON to enable building of tests" OFF) option(BUILD_SHARED_LIBS "Build tgbot-cpp shared/static library." OFF) # sources -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") +if(WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Do not activate all warnings in VS (too much output for Appveyor) +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") +endif() + include_directories(include) set(SRC_LIST src/Api.cpp @@ -28,6 +40,9 @@ set(SRC_LIST ## threads find_package(Threads REQUIRED) +# zlib +find_package(ZLIB REQUIRED) + ## openssl find_package(OpenSSL REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) @@ -50,6 +65,7 @@ include_directories(${Boost_INCLUDE_DIR}) set(LIB_LIST ${CMAKE_THREAD_LIBS_INIT} + ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES} @@ -59,7 +75,10 @@ set(LIB_LIST add_library(${PROJECT_NAME} ${SRC_LIST}) target_include_directories(${PROJECT_NAME} PUBLIC include) target_link_libraries(${PROJECT_NAME} ${LIB_LIST}) -install(TARGETS ${PROJECT_NAME} DESTINATION lib) +install(TARGETS ${PROJECT_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) install(DIRECTORY include/ DESTINATION include) # tests @@ -2,7 +2,7 @@ FROM debian:stretch MAINTAINER Oleg Morozenkov <a@reo7sp.ru> RUN apt-get -qq update && \ - apt-get -qq install -y g++ make binutils cmake libssl-dev libboost-system-dev libcurl4-openssl-dev + apt-get -qq install -y g++ make binutils cmake libssl-dev libboost-system-dev libcurl4-openssl-dev zlib1g-dev WORKDIR /usr/src/tgbot-cpp COPY include include diff --git a/Dockerfile_test b/Dockerfile_test index 8b16ae2..9ff0764 100644 --- a/Dockerfile_test +++ b/Dockerfile_test @@ -2,8 +2,10 @@ FROM ubuntu:14.04 MAINTAINER Oleg Morozenkov <a@reo7sp.ru> RUN apt-get -qq update && \ - apt-get -qq install -y g++ make binutils cmake libssl-dev libcurl4-openssl-dev \ - wget build-essential python-dev autotools-dev libicu-dev libbz2-dev + apt-get -qq install -y g++ make binutils cmake libssl-dev libcurl4-openssl-dev + +RUN apt-get -qq update && \ + apt-get -qq install -y wget build-essential python-dev autotools-dev libicu-dev libbz2-dev zlib1g-dev WORKDIR /usr/src/boost RUN wget -q -O boost_1_59_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download && \ diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..4d16413 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,80 @@ +build: false + + +environment: + PYTHON: "C:\\Python37" + VS150COMNTOOLS: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\Tools\\" + + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 12 + CONAN_ARCHS: x86 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MT + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 12 + CONAN_ARCHS: x86_64 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MT + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 12 + CONAN_ARCHS: x86 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MD + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 12 + CONAN_ARCHS: x86_64 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MD + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 14 + CONAN_ARCHS: x86 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MT + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 14 + CONAN_ARCHS: x86_64 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MT + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 14 + CONAN_ARCHS: x86 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MD + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + CONAN_VISUAL_VERSIONS: 14 + CONAN_ARCHS: x86_64 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MD + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CONAN_VISUAL_VERSIONS: 15 + CONAN_ARCHS: x86 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MT + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CONAN_VISUAL_VERSIONS: 15 + CONAN_ARCHS: x86_64 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MT + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CONAN_VISUAL_VERSIONS: 15 + CONAN_ARCHS: x86 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MD + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CONAN_VISUAL_VERSIONS: 15 + CONAN_ARCHS: x86_64 + CONAN_BUILD_TYPES: Release + CONAN_VISUAL_RUNTIMES: MD + +install: + - set PATH=%PATH%;%PYTHON%/Scripts/ + - pip.exe install conan --upgrade + - pip.exe install conan_package_tools + - conan user # It creates the conan data directory + +test_script: + - python build.py + diff --git a/build.py b/build.py new file mode 100644 index 0000000..18a873a --- /dev/null +++ b/build.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from cpt.packager import ConanMultiPackager + + +if __name__ == "__main__": + builder = ConanMultiPackager( + username="reo7sp", + login_username="reo7sp", + upload="https://api.bintray.com/conan/reo7sp/tgbot-cpp", + channel="ci", + stable_branch_pattern="release/*", + upload_only_when_stable=True, # Will only upload when the branch matches "release/*" + docker_32_images=True + ) + builder.add_common_builds() + builder.run() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..96c3d22 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,61 @@ + +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os + +from conans import ConanFile, CMake, tools + + +class TgbotConan(ConanFile): + name = "tgbot_cpp" + version = "b35438d" + description = "C++ library for Telegram bot API" + url = "https://github.com/reo7sp/tgbot-cpp" + homepage = "http://reo7sp.github.io/tgbot-cpp" + license = "MIT" + + exports_sources = ["LICENSE", ] + scm = {"type": "git", + "url": "auto", + "revision": "auto"} + + generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + options = {"fPIC": [True, False], + "shared": [True, False]} + default_options = {"fPIC": True, "shared": True} + + requires = ( + "boost/1.68.0@conan/stable", + "OpenSSL/1.0.2q@conan/stable", + "libcurl/7.61.1@bincrafters/stable" + ) + + def source(self): + boost_version = self.deps_cpp_info['boost'].version + tools.replace_in_file(os.path.join(self.source_folder, "CMakeLists.txt"), + "find_package(Boost 1.59.0 COMPONENTS system REQUIRED)", + "find_package(Boost {} COMPONENTS system REQUIRED)".format(boost_version)) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def _configure_cmake(self): + cmake = CMake(self) + cmake.definitions["ENABLE_TESTS"] = False + cmake.configure() + return cmake + + def build(self): + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy(pattern="LICENSE", dst="licenses") + cmake = self._configure_cmake() + cmake.install() + + def package_info(self): + self.cpp_info.libs = ['TgBot'] diff --git a/samples/echobot-conan/CMakeLists.txt b/samples/echobot-conan/CMakeLists.txt new file mode 100644 index 0000000..24d5422 --- /dev/null +++ b/samples/echobot-conan/CMakeLists.txt @@ -0,0 +1,9 @@ +project(PackageTest CXX) +cmake_minimum_required(VERSION 2.8.4) +set(CMAKE_CXX_STANDARD 11) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(example example.cpp) +target_link_libraries(example ${CONAN_LIBS}) diff --git a/samples/echobot-conan/conanfile.py b/samples/echobot-conan/conanfile.py new file mode 100644 index 0000000..732b9b8 --- /dev/null +++ b/samples/echobot-conan/conanfile.py @@ -0,0 +1,24 @@ + +import os +from conans import ConanFile, CMake, tools + + +class TestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + # Current dir is "echobot-conan/build/<build_id>" and CMakeLists.txt is in "echobot-conan" + cmake.configure() + cmake.build() + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") + self.copy("*.dylib*", dst="bin", src="lib") + self.copy('*.so*', dst='bin', src='lib') + + def test(self): + if not tools.cross_building(self.settings): + os.chdir("bin") + self.run(".%sexample" % os.sep) diff --git a/samples/echobot-conan/example.cpp b/samples/echobot-conan/example.cpp new file mode 100644 index 0000000..f1c2863 --- /dev/null +++ b/samples/echobot-conan/example.cpp @@ -0,0 +1,20 @@ +#include <tgbot/tgbot.h> + +using namespace std; +using namespace TgBot; + +bool sigintGot = false; + +int main() { + Bot bot("PLACE YOUR TOKEN HERE"); + bot.getEvents().onCommand("start", [&bot](Message::Ptr message) { + bot.getApi().sendMessage(message->chat->id, "Hi!"); + }); + bot.getEvents().onAnyMessage([&bot](Message::Ptr message) { + printf("User wrote %s\n", message->text.c_str()); + if (StringTools::startsWith(message->text, "/start")) { + return; + } + bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); + }); +} |