Skip to content

Commit

Permalink
init: setup
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Reyreaud <[email protected]>
  • Loading branch information
Loic Reyreaud committed Sep 3, 2018
1 parent 62ff00f commit 743c140
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.11)
set(PROJ simple-cpp-setup)

# Set language
project(${PROJ} CXX)

# Generate a library containing everything. Only main should be left out for
# easy testing
add_library(${PROJ}_LIB
src/square.cpp
src/square.hpp
)
# Include in PUBLIC so that we don't have to duplicate the line for everything
# that will use the lib.
target_include_directories(${PROJ}_LIB PUBLIC src/)

# Our main program
add_executable(${PROJ}
src/main.cpp
)
target_link_libraries(${PROJ} PRIVATE ${PROJ}_LIB)

# Enable ctest
enable_testing()

# Our test program
add_executable(${PROJ}_test
tests/test.cpp
)
add_test(check ${PROJ}_test)
target_link_libraries(${PROJ}_test PRIVATE ${PROJ}_LIB)
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Simple C++ Setup.

This repository contains a very simple C++ setup using CMake to build, and CTest
to test it.


To build: `mkdir build && cd build && cmake .. && make`

To test: `cd build && ctest`

## But why ?

Because we prefer code over builds.

I've seen many people simply not knowing where to start. Or just writing
horribles makefiles (To be honest, nobody knows how to cleanly write a simple
makefile). So I made this simple setup to allows anyone to freely copy the setup
to start coding, and not start fighting with build systems.

Enjoy!
9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

#include "square.hpp"

int main()
{
std::cout << "Hello world!" << std::endl;
return my_square(0);
}
6 changes: 6 additions & 0 deletions src/square.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "square.hpp"

std::size_t my_square(long long int x)
{
return x * x;
}
5 changes: 5 additions & 0 deletions src/square.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <cstddef>

std::size_t my_square(long long int x);
11 changes: 11 additions & 0 deletions tests/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cassert>

#include "square.hpp"

int main()
{
assert(my_square(0) == 0);
assert(my_square(2) == 4);
assert(my_square(-2) == 4);
return 0;
}

0 comments on commit 743c140

Please sign in to comment.