
# TODO: create custom docker images for each of these environments
# to avoid re-downloading & installing dependencies each time

version: 2.0
jobs:
  "clang - build, test":
    docker:
      - image: ubuntu:16.04
        environment:
          CC: clang-6.0
          CXX: clang++-6.0
          CLANG_FORMAT: clang-format-6.0
          CTEST_OUTPUT_ON_FAILURE: 1
    steps:
      - checkout
      - run: apt-get update -qq
      - run: apt-get install -y software-properties-common
      # llvm apt details: https://apt.llvm.org
      - run: apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
      - run: apt-get update -qq
      - run: >
          apt-get install -y --allow-unauthenticated
          build-essential
          asciidoctor
          cmake
          libmbedtls-dev
          ninja-build
          clang-6.0
          clang-format-6.0
      - run: ./etc/format-check.sh
      - run: ./.circleci/build-and-test.sh

  "gcc - static":
    docker:
      - image: ubuntu:16.04
        environment:
          CC: gcc
          CXX: g++
          SHARED_LIBS: OFF
          CTEST_OUTPUT_ON_FAILURE: 1
    steps:
      - checkout
      - run: apt-get update -qq
      - run: apt-get install -y software-properties-common
      - run: add-apt-repository ppa:ubuntu-toolchain-r/test
      - run: apt-get update -qq
      - run: >
          apt-get install -y --allow-unauthenticated
          build-essential
          cmake
          libmbedtls-dev
          ninja-build
      - run: ./.circleci/build-and-test.sh

  "gcc - demos":
    docker:
      - image: ubuntu:16.04
        environment:
          CC: gcc
          CXX: g++
          CTEST_OUTPUT_ON_FAILURE: 1
    steps:
      - checkout
      - run: apt-get update -qq
      - run: apt-get install -y software-properties-common
      - run: add-apt-repository ppa:ubuntu-toolchain-r/test
      - run: apt-get update -qq
      - run: >
          apt-get install -y --allow-unauthenticated
          build-essential
          cmake
          libmbedtls-dev
          ninja-build
      - run: ./.circleci/run-cmake.sh
      - run: ninja -C build
      - run: ninja -C build install
      - run: ./.circleci/build-demos.sh

  "gcc - build, test, coverage":
    docker:
      - image: ubuntu:16.04
        environment:
          CC: gcc-8
          CXX: g++-8
          COVERAGE: "ON"
          GCOV: gcov-8
          CTEST_OUTPUT_ON_FAILURE: 1
    steps:
      - checkout
      - run: apt-get update -qq
      - run: apt-get install -y software-properties-common
      - run: add-apt-repository ppa:ubuntu-toolchain-r/test
      - run: apt-get update -qq
      - run: >
          apt-get install -y --allow-unauthenticated
          build-essential
          curl
          asciidoctor
          cmake
          libmbedtls-dev
          ninja-build
          gcc-8
          g++-8
      - run: ./.circleci/build-and-test.sh
      - run: ./etc/codecov.sh

workflows:
  version: 2
  build_and_test:
    jobs:
      - "clang - build, test"
      - "gcc - static"
      - "gcc - build, test, coverage"
      - "gcc - demos"

#notify:
#  webhooks:
#    # A list of hook hashes, containing the url field
#    # gitter hook
#    - url: ${GITTER_WEBHOOK}

