Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liftoff fix #57

Merged
merged 8 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ make
```

## Customize
Easily use this skeleton as a starting off point for your own custom project:
Easily use this skeleton as a starting off point.

### Start new project
```
# Clone hpp-skel locally

git clone git@github.com:mapbox/hpp-skel.git
cd hpp-skel/

Expand All @@ -60,13 +62,48 @@ cd hpp-skel/
#
# This will:
# - prompt you for the new name of your project and the new remote repo url
# - automatically rename your local hpp-skel directory to the name of your project
# - create a new branch called "hpp-skel-port"
# - add, commit, and push
# - automatically create a new directory for your new project repo
# - create a new branch called "hpp-skel-port" within your new repo directory
# - add, commit, and push that branch to your new repo

./scripts/liftoff.sh

```

### Add custom code
Once your project has ported hpp-skel, follow these steps to integrate your own code:

- Create a dir in `./include` to hold your custom code. See the example code within [`./include`](https://github.com/mapbox/hpp-skel/tree/master/include) for reference.
- Create a new file within your new directory, and add your custom method or class.
- Create a module header file (see [hello_world.hpp](https://github.com/mapbox/hpp-skel/blob/master/include/hello_world.hpp)), and `#include` your new method or class. Make sure this file matches the name of the directory you created in the first step above.
- Run `make` and see what surprises await on your new journey :boat:
- If it compiles succesfully, congrats :tada: If not, dont fret. Take a breath and read the error message.
- To start putting your header lib to work, setup a test to make sure it is working as expected.

### Setup tests
Since header-only libraries are _not_ normally compiled themselves, to test them you need to [#include](https://github.com/mapbox/cpp/blob/master/glossary.md#include) them in a `.cpp` file (aka a [translation unit](https://github.com/mapbox/cpp/blob/master/glossary.md#translation-unit)) to compile and run their code. We recommend using [Catch](https://github.com/catchorg/Catch2) to make writing this `.cpp` file easy.

- Create a file in `/test` directory, and add the following (be sure to update relevant lines with the name of the header you created above):
``` cpp
#include <your_header_here.hpp>
#define CATCH_CONFIG_MAIN
#include <catch.hpp>

TEST_CASE("test_my_header")
{
// Your test logic here
}
```
- Fill in the TEST_CASE with relevant [Catch](https://github.com/catchorg/Catch2) logic (see [test.cpp](https://github.com/mapbox/hpp-skel/blob/master/test/test.cpp) for examples).
- Tip: When calling your header method/class, make sure the namespace matches your header. For example
``` cpp
// "hello_world" is the namespace
// "exclaim" is the method

std::string value = hello_world::exclaim("hello");
```
- Run `make test` to compile and run your test

## Benchmarks
This skeleton uses [Google Benchmark](https://github.com/google/benchmark) to measure performance, and includes a [couple benchmark tests](https://github.com/mapbox/hpp-skel/blob/master/bench/run.cpp) to get you up and running quickly:
- `BM_exlaim()`: Pretty barebone, simply testing string creation
Expand Down
7 changes: 5 additions & 2 deletions scripts/liftoff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

set -eu

# First create new repo on GitHub
# First create new repo on GitHub and copy the SSH repo url
# Then run "./scripts/liftoff.sh" from within your local hpp-skel root directory
# and it will create your new local project repo side by side with hpp-skel directory

echo "What is the name of your new project? "
read name
echo "What is the remote repo url for your new project? "
read url

mv ../hpp-skel $name
mkdir ../$name
cp -R ../hpp-skel/. ../$name/
cd ../$name/
rm -rf .git
git init

Expand Down