diff --git a/cpp/.dockerignore b/cpp/.dockerignore new file mode 100644 index 00000000..b220145d --- /dev/null +++ b/cpp/.dockerignore @@ -0,0 +1,5 @@ +README.md +*.txt +src/ +include/ +*.sh \ No newline at end of file diff --git a/cpp/Dockerfile b/cpp/Dockerfile new file mode 100644 index 00000000..84e186c4 --- /dev/null +++ b/cpp/Dockerfile @@ -0,0 +1,17 @@ +FROM debian:buster + +LABEL maintainer = "Michele Adduci " \ + license = "MIT" \ + description = "Development Enviroment for C++" + +RUN DEBIAN_FRONTEND=noninteractive \ + && echo "### Installing C++ tools" \ + && apt-get update \ + && apt-get -y install build-essential cmake \ + && echo "### Cleaning up" \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir -p /project + +WORKDIR /project diff --git a/cpp/README.md b/cpp/README.md index fdf9dc2a..cbe87261 100644 --- a/cpp/README.md +++ b/cpp/README.md @@ -1,5 +1,4 @@ -CMake Setup -========== +# CMake Setup This is a simple bootstrap project for C++ using [**CMake**](https://cmake.org/download/) and [**doctest**](https://github.com/onqtam/doctest) @@ -7,8 +6,8 @@ You can edit the CMakeLists.txt file to set the targeted C++ Standard (Default i ### Requirements -* C++ Compiler with possibily support to modern standards (e.g. gcc >= 5, clang >= 3.8, Visual Studio >= 2013) -* CMake +- C++ Compiler with possibily support to modern standards (e.g. gcc >= 5, clang >= 3.8, Visual Studio >= 2013) +- CMake ### Unix-Like Setup @@ -16,7 +15,7 @@ To run the project, just open a terminal (on Linux/Mac) and run the following co ``` cd /path/to/this/project -mkdir build && cd build +mkdir -p build && cd build cmake .. ``` @@ -31,4 +30,16 @@ make test If you have Visual Studio, just launch the CMake Gui tool and select the project source folder and a build directory and which version of Visual Studio you want to target. -After pressing the *Generate* button, you can open the Visual Studio *.sln file generated in the build directory you have previously selected. +After pressing the _Generate_ button, you can open the Visual Studio \*.sln file generated in the build directory you have previously selected. + +### Docker + +If you have Docker installed on your machine (Linux/Mac/Windows with WSL), you can start a docker container by using the script: + +`docker_up.sh` + +The script will build a docker image with all the requirements (gcc compiler, cmake, make) and will run the docker container with a bash prompt in the `/project` folder. + +Once you're done with coding, typing `exit` in the shell will stop and automatically remove the docker container (not the image). + +The script `build.sh` contains the steps described in the [Unix-Like Setup](#Unix-Like-Setup) diff --git a/cpp/build.sh b/cpp/build.sh new file mode 100755 index 00000000..fd323b14 --- /dev/null +++ b/cpp/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +mkdir -p build && cd build +cmake .. +make +make test \ No newline at end of file diff --git a/cpp/docker_up.sh b/cpp/docker_up.sh new file mode 100755 index 00000000..3cc8d90b --- /dev/null +++ b/cpp/docker_up.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e + +# Build image +docker build -t cppdev . +# Run with bash +docker run --rm -it -v $(pwd):/project/ cppdev