This commit is contained in:
MrBesen 2020-09-20 13:20:34 +02:00
commit 156baf0136
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
11 changed files with 274 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
*.bin
*.out
build/
*.exe
.gdb_history
*.so
*.bmp
*.d
test
.vscode/settings.json
%NAME%
%NAME%_strip

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "Log"]
path = Log
url = https://git.mrbesen.de/mrbesen/Log.git

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/src/",
"${workspaceFolder}/Log/",
"${workspaceFolder}/src/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

50
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,50 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "test Debuggen (gdb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make test",
"miDebuggerPath": "/usr/bin/gdb"
},
{
"name": "Debuggen (gdb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/%NAME%",
"args": ["-s"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make all",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}

45
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,45 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make all",
"type": "shell",
"command": "make -j all",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"label": "make clean",
"type": "shell",
"command": "make clean",
"problemMatcher": []
},
{
"label": "leak check",
"type": "shell",
"command": "/usr/bin/valgrind --leak-check=full ${workspaceFolder}/%NAME% -s",
"problemMatcher": [],
"dependsOn": "make all"
},
{
"label": "leak check ALL",
"type": "shell",
"command": "/usr/bin/valgrind --leak-check=full --show-leak-kinds=all ${workspaceFolder}/%NAME% -s",
"problemMatcher": [],
"dependsOn": "make all"
},
{
"label": "make test",
"type": "shell",
"command": "make -j test",
"problemMatcher": ["$gcc"],
}
]
}

1
Log Submodule

@ -0,0 +1 @@
Subproject commit 7ad305641a674b0aa39a4bfc08794bbbca389f87

75
Makefile Normal file
View File

@ -0,0 +1,75 @@
# Author Yannis Gerlach
# Hochschule Osnabrück
# 29.04.2020
# `make clean all` nicht mit -j verwenden! -> race condition im make file
# statdessen: `make clean; make all -j` verwenden
NAME = %NAME%
NAMETEST = test
CFLAGS = -std=c++17 -O2 -g -pipe -Wall -Wextra -Wno-unused-parameter -Wpedantic -rdynamic -msse2 -mavx2 #-march=native -Wall
CXX = g++
SRCF = src/
BUILDDIR = build/
TESTF = tests/
DEPF = $(BUILDDIR)deps/
LOGF = ./Log/
LOGO = $(LOGF)Log.o
INCLUDES = -I$(LOGF) -Iminiaudio/
LDFLAGS = -lGL -lglfw -lfreeimage -lGLEW -lassimp -lpthread -lm -ldl
SRCFILES = $(shell find $(SRCF) -name "*.cpp")
OBJFILES = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(patsubst %.cpp, %.o, $(SRCFILES))) $(LOGO)
DEPFILES = $(wildcard $(DEPF)*.d)
SOURCEDIRS = $(shell find $(SRCF) -type d -printf "%p/\n")
BUILDDIRS = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(SOURCEDIRS))
OBJFILESTEST = $(filter-out $(BUILDDIR)main.o, $(OBJFILES))
INCLUDES += $(addprefix -I, $(SOURCEDIRS))
all: $(NAME) runtest
$(NAME): $(BUILDDIRS) $(DEPF) $(OBJFILES)
@echo "Linking $@"
@$(CXX) $(CFLAGS) -o $@ $(filter %.o, $^) $(LDFLAGS)
$(BUILDDIR)%.o: $(SRCF)%.cpp
@echo "Compiling: $@"
@$(CXX) $(CFLAGS) $(INCLUDES) $< -MM -MT $@ > $(DEPF)$(subst /,_,$*).d
@$(CXX) -c -o $@ $(CFLAGS) $(INCLUDES) $<
$(NAME)_strip: $(NAME)
@echo "Strip $<"
@strip -o $@ $<
%/:
mkdir -p $@
clean-depends:
$(RM) -r $(DEPF)
$(LOGO):
$(MAKE) -C $(LOGF) all
clean:
$(RM) -r $(NAME) $(BUILDDIR) $(NAMETEST) $(NAME)_strip shader/debug/
$(MAKE) -C $(LOGF) $@
$(NAMETEST): $(BUILDDIRS) $(DEPF) $(TESTF)*.cpp $(OBJFILESTEST)
@echo "Compiling tests"
@$(CXX) -o $@ $(filter %.o, $^) $(filter %.cpp, $^) $(CFLAGS) -I$(SRCF) $(INCLUDES) $(LDFLAGS)
runtest: $(NAMETEST)
@echo "Running tests"
./$<
# fix assets :
# find assets/ -name '*.*' -exec sh -c 'a=$(echo "$0" | sed -r "s/([^.]*)\$/\L\1/"); [ "$a" != "$0" ] && mv "$0" "$a" ' {} \;
.PHONY: clean all $(NAMETEST) clean-depends runtest
include $(DEPFILES)

12
init.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# init all files in this repo and then delete this one
if [ "$#" -ne "1" ]; then
echo "usage: $0 <projekt name>"
exit 1
fi
find . -type f -exec sed -i "s#%NAME%#${1}#g" {} +
rm -i "$0"

16
src/main.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "Log.h"
int main(int argc, const char** argv) {
Log::init();
Log::setConsoleLogLevel(Log::Level::TRACE);
Log::addLogfile("log.txt", Log::Level::TRACE);
#if __unix__
Log::setColoredOutput(true);
#endif
Log::info("Hello, World!");
Log::stop();
return 0;
}

26
tests/main.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include "test.h"
//tests
test_t tests[] = {NULL};
int main(int argc, char** argv) {
test_t* current = tests;
int failcount = 0;
int testcount = 0;
for(; *current; current++) {
testcount++;
printf("\033[1mRunning test number: %d ", testcount);
if((*current)()) {
printf("\033[1;92msucceeded\033[0;1m!\n");
} else {
printf("\033[1;91mfailed\033[0;1m\n");
failcount++;
}
}
printf("\033[1;93m%d\033[0;1m/%d failed\n", failcount, testcount);
return failcount > 0;
}

11
tests/test.h Normal file
View File

@ -0,0 +1,11 @@
#define TESTFAILED 0
#define TESTGOOD 1
#include <iostream>
#define TESTDATA "./tests/data/"
#define ASSERT(BED, ERR) if(!(BED)) { std::cout << __FILE__ << ":" << __LINE__ << " " << ERR << std::endl; return TESTFAILED; }
// #define ASSERT(BED) ASSERT(BED, "")
typedef int (*test_t)();