-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Loic Reyreaud <[email protected]>
- Loading branch information
Loic Reyreaud
committed
Sep 3, 2018
1 parent
62ff00f
commit 743c140
Showing
7 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |