Initial setup of stick C++ project, with Bazel and Catch2.

This commit is contained in:
Martin Sosic 2018-09-29 10:49:22 +02:00
parent 8e412a161f
commit 7620f4c21c
14 changed files with 14048 additions and 0 deletions

35
stic/.gitignore vendored Normal file
View File

@ -0,0 +1,35 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Bazel files/folders.
bazel-*

View File

@ -2,3 +2,22 @@ STIC
====
![stick](./stick.png)
## Setup
### Bazel
We are using Bazel as our build system, so make sure to install bazel globally on your machine.
## Building
We are using Bazel build system.
Everything is defined in BUILD files (+ one WORKSPACE file).
Learn more about Bazel to know how to build spepcific targets, locate produced binaries and so on.
For your convenience, there is `run-stick-cli` script that builds and runs `stick-cli` binary for you.
## Tests
We are using Catch2 testing framework.
While you can use Bazel to run specific tests, there is `run-all-tests` script to easily build and run all tests.

0
stic/WORKSPACE Normal file
View File

3
stic/run-stick-cli Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
bazel build //src:stick-cli && bazel-bin/src/stick-cli

3
stic/run-tests Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
bazel build //test:all-tests && bazel-bin/test/all-tests

16
stic/src/BUILD Normal file
View File

@ -0,0 +1,16 @@
cc_library(
name = "hello-world",
srcs = ["hello-world.cpp"],
hdrs = ["hello-world.hpp"],
visibility = [
"//test:__pkg__"
]
)
cc_binary(
name = "stick-cli",
srcs = ["cli.cpp"],
deps = [
":hello-world"
]
)

7
stic/src/cli.cpp Normal file
View File

@ -0,0 +1,7 @@
#include <iostream>
#include "./hello-world.hpp"
int main () {
std::cout << sayHi() << std::endl;
}

5
stic/src/hello-world.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "./hello-world.hpp"
std::string sayHi() {
return "Hello world!";
}

5
stic/src/hello-world.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <string>
std::string sayHi();

19
stic/test/BUILD Normal file
View File

@ -0,0 +1,19 @@
cc_library(
name = "catch-main",
srcs = ["main.cpp"],
copts = ["-Ivendor/catch2/"],
deps = [
"//vendor/catch2:catch2"
]
)
cc_test(
name = "all-tests",
srcs = glob(["**/*.test.cpp"]),
copts = ["-Ivendor/catch2/", "-Isrc/"],
deps = [
"catch-main",
"//vendor/catch2:catch2",
"//src:hello-world"
]
)

View File

@ -0,0 +1,7 @@
#include "catch.hpp"
#include "hello-world.hpp"
TEST_CASE("Returns hello world.") {
REQUIRE(sayHi() == "Hello world!");
}

2
stic/test/main.cpp Normal file
View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

5
stic/vendor/catch2/BUILD vendored Normal file
View File

@ -0,0 +1,5 @@
cc_library(
name = "catch2",
hdrs = ["catch.hpp"],
visibility = ["//test:__pkg__"]
)

13922
stic/vendor/catch2/catch.hpp vendored Normal file

File diff suppressed because it is too large Load Diff