Skip to content

Commit

Permalink
Merge pull request #33 from banditcpp/docker
Browse files Browse the repository at this point in the history
More CI builds

This pull request adds more builds to AppVeyor and Travis CI.
Different compilers and different standards are tested.
The build environments for Travis CI are realized using Docker images.

A clang-format-4.0-based style check is added to the CI.
This is realized by exploiting undocumented Travis CI behavior, see
travis-ci/travis-ci#2646 (comment)

`cross_compile.sh` is removed and some new shell scripts are
added in a new `util/` directory.
  • Loading branch information
sbeyer committed Apr 12, 2017
2 parents ad1f812 + 581090b commit 97d89ee
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 88 deletions.
12 changes: 12 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
environment:
matrix:
- CXX_STANDARD: 98
- CXX_STANDARD: 03
- CXX_STANDARD: 11
- CXX_STANDARD: 14

build_script:
- cmake -G "Visual Studio 14" -DSNOWHOUSE_RUN_TESTS=0 -DSNOWHOUSE_CXX_STANDARD=C++%CXX_STANDARD%
- cmake --build .
test_script:
- bin\Debug\snowhouse-tests.exe
53 changes: 39 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
language: cpp
sudo: required

compiler:
- gcc
- clang
# language: none <- no language, please, but this is not possible, so it takes Ruby.

env:
- CPP11=OFF
- CPP11=ON
matrix:
include:
# Check if coding style is okay
- env: BUILD_TYPE=coding-style-check

services: docker

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y findutils

before_install:
- sudo add-apt-repository ppa:kubuntu-ppa/backports -y
- sudo apt-get update -qq
- sudo apt-get install -qq cmake=2.8.12.2-0ubuntu1~ubuntu12.04.1~ppa2
script:
- git ls-files '*.cpp' '*.h' |
xargs
docker run -v"$PWD":/media/ banditcpp/build-environments:clang-format-4.0
clang-format-4.0 -i &&
git diff &&
git diff-index --quiet HEAD

before_script:
- cmake -DSNOWHOUSE_IS_CPP11=${CPP11} .
services:
- docker

env:
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=gcc-4.4 CXX=g++-4.4
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=gcc-4.6 CXX=g++-4.6
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=03 CC=gcc-4.6 CXX=g++-4.6
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=clang CXX=clang++
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=03 CC=clang CXX=clang++
- DOCKER_TAG=snowhouse-minimum CXX_STANDARD=11 CC=clang CXX=clang++
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=gcc-4.8 CXX=g++-4.8
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=03 CC=gcc-4.8 CXX=g++-4.8
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.8 CXX=g++-4.8
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=gcc-4.9 CXX=g++-4.9
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.9 CXX=g++-4.9
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=clang-3.5 CXX=clang++-3.5
- DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=clang-3.5 CXX=clang++-3.5
- DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=gcc-6 CXX=g++-6
- DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=clang-3.9 CXX=clang++-3.9

script:
- make
- util/build-in-container.sh ${CXX_STANDARD} banditcpp/build-environments:${DOCKER_TAG}
41 changes: 22 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,43 @@ project(snowhouse)

option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" ON)
option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" ON)
option(SNOWHOUSE_IS_CPP11 "Whether to build this as a C++11 project" OFF)
set(SNOWHOUSE_CXX_STANDARD "C++03" CACHE STRING "The C++ standard the examples are compiled with")
set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++98" "C++03" "C++11" "C++14")

include_directories("${PROJECT_SOURCE_DIR}")

if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++98")
set(std_name "c++98")
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++03")
set(std_name "c++03")
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11")
set(std_name "c++11")
elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++14")
set(std_name "c++14")
else()
message(WARNING "C++ standard \"${SNOWHOUSE_CXX_STANDARD}\" not known, falling back to default")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP ")
if(DEFINED std_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:${std_name}")
endif()
else()
# Assume GCC-style arguments
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -Wall -W -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors")

if(SNOWHOUSE_IS_CPP11)
if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11" OR SNOWHOUSE_CXX_STANDARD STREQUAL "C++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdeprecated")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

if (CMAKE_HOST_APPLE AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if(DEFINED std_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${std_name}")
endif()
endif()

message(STATUS ${CMAKE_CXX_FLAGS})
message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}")

if (SNOWHOUSE_BUILD_TESTS)
FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp)
Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml

This file was deleted.

50 changes: 0 additions & 50 deletions cross_compile.sh

This file was deleted.

15 changes: 15 additions & 0 deletions util/build-in-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

if test "$#" -ne 2
then
echo "Usage: $0 (98|03|11|14) <docker image>" >&2
exit 2
fi

SRCDIR=/usr/src/snowhouse
docker run \
-v "$PWD":"$SRCDIR" \
-e "SRCDIR=$SRCDIR" \
-e "CC=$CC" \
-e "CXX=$CXX" \
"$2" "$SRCDIR"/util/build.sh "$1" "$2"
32 changes: 32 additions & 0 deletions util/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

test -n "$SRCDIR" || SRCDIR=.
test -n "$CC" || CC=cc
test -n "$CXX" || CXX=c++

cxxstandard="$1"
case "$cxxstandard" in
98|03|11|14)
;;
*)
echo "Usage: $0 (98|03|11|14) [image name]" >&2
exit 1
esac

image="$2"
test -n "$image" || image=default

buildpath="builds/$(basename "$image" | sed 's/^.*://')/$(basename "$CXX")/std$cxxstandard"

echo "Build settings:"
echo " * source directory: $SRCDIR"
echo " * C compiler: $CC"
echo " * C++ compiler: $CXX"
echo " * C++ standard: C++$cxxstandard"
echo " * image: $image"
echo " * build path: $buildpath"

mkdir -p "$SRCDIR/$buildpath"
cd "$SRCDIR/$buildpath"
cmake -D"SNOWHOUSE_CXX_STANDARD=C++$cxxstandard" "$SRCDIR" || exit
cmake --build . || exit
15 changes: 15 additions & 0 deletions util/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# Reformat all tracked files (run this from snowhouse git root directory,
# not from util!)

DEFAULT_FORMAT_TOOL=clang-format-4.0
test -n "$FORMATTER" || FORMATTER="$(command -v "$DEFAULT_FORMAT_TOOL")"

if test -z "$FORMATTER"
then
echo "Error: No '$DEFAULT_FORMAT_TOOL' executable found in PATH" >&2
echo "You can define your clang-format path by setting the FORMATTER variable" >&2
exit 2
fi

git ls-files '*.cpp' '*.h' | xargs "$FORMATTER" -i

0 comments on commit 97d89ee

Please sign in to comment.