simple Makefile with dependency files

This commit is contained in:
j3d1 2021-02-23 22:54:24 +01:00
parent d0f67430d8
commit bee43f9297
9 changed files with 18013 additions and 1 deletions

View file

@ -1,2 +1,2 @@
# coockecutter-make-cpp # cookiecutter-make-cpp

5
cookiecutter.json Normal file
View file

@ -0,0 +1,5 @@
{
"project_name": "project_name",
"app_name": "app_name",
"description": "the soul is the prison of the body"
}

132
{{cookiecutter.project_name}}/.gitignore vendored Normal file
View file

@ -0,0 +1,132 @@
# ---> C++
# 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
# ---> Archives
# It's better to unpack these files and commit the raw source because
# git has its own built in compression methods.
*.7z
*.jar
*.rar
*.zip
*.gz
*.bzip
*.bz2
*.xz
*.lzma
*.cab
#packing-only formats
*.iso
*.tar
#package management formats
*.dmg
*.xpi
*.gem
*.egg
*.deb
*.rpm
*.msi
*.msm
*.msp
# ---> C
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
modules.order
Module.symvers
Mkfile.old
dkms.conf
# ---> Linux
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
build/

View file

@ -0,0 +1,57 @@
CC = gcc
CXX = g++
LD = g++
CXXFLAGS := -std=gnu++20 -Wall -Werror -Wpointer-arith -Wfatal-errors
CXXFLAGS += -flto -O3
#CXXFLAGS += -ggdb3
CFLAGS = -Wall -Werror -Wpointer-arith -Wfatal-errors
ifdef LINK_MOSTLY_STATIC
LDFLAGS := -static-libstdc++ -Wl,-Bstatic -lboost_program_options
LDFLAGS += -Wl,-Bdynamic -lpthread -ldl
LDFLAGS += -Wl,--exclude-libs,ALL
else
LDFLAGS = -lboost_program_options
endif
BUILDDIR = build
OBJECTS =
DEPS := $(OBJECTS:.o=.d) $(BUILDDIR)/{{cookiecutter.app_name}}.d
all: $(BUILDDIR)/{{cookiecutter.app_name}}
$(BUILDDIR)/{{cookiecutter.app_name}}: $(OBJECTS) $(BUILDDIR)/{{cookiecutter.app_name}}.o
@mkdir -p $(dir $@)
@echo link $@
@$(LD) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
$(BUILDDIR)/%.o: src/%.cpp Makefile
@mkdir -p $(dir $@)
@echo compile $@
@$(CXX) $(CXXFLAGS) -MQ $@ -MM -MF $(patsubst %.o,%.d,$@) $<
@$(CXX) $(CXXFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: src/%.c Makefile
@mkdir -p $(dir $@)
@echo compile $@
@$(CC) $(CFLAGS) -MQ $@ -MM -MF $(patsubst %.o,%.d,$@) $<
@$(CC) $(CFLAGS) -c $< -o $@
install: $(BUILDDIR)/{{cookiecutter.app_name}}
install -m 0755 $^ $(DESTDIR)/usr/bin
clean:
rm -r build/
-include $(DEPS)

View file

@ -0,0 +1,78 @@
//
// Created by jedi on 06.02.21.
//
#pragma once
#if __has_include(<source_location>)
#include <source_location>
using std::source_location;
#elif __has_include(<experimental/source_location>)
#include <experimental/source_location>
using std::experimental::source_location;
#else
#error "<source_location> not found"
#endif
/*
template<typename ERROR = std::runtime_error>
inline void
throw_with_pos(const std::string &message = "", const source_location &location = source_location::current()) {
std::stringstream ss;
ss << location.function_name() << " in "
<< location.file_name() << ':'
<< location.line() << ' '
<< message;
throw ERROR(ss.str());
}*/
#include <type_traits>
template<typename...>
struct is_empty : std::false_type {
};
template<typename T, template<T...> class Z, T... Is>
struct is_empty<T, Z<Is...>> : std::true_type {
};
template<typename T, template<T...> class Z, T First, T... Rest>
struct is_empty<T, Z<First, Rest...>> : std::false_type {
};
template<typename...>
struct Z;
template<typename ERROR = std::runtime_error, typename... T>
struct throw_with_pos {
explicit throw_with_pos(std::string_view message = "", T &&... pack,
source_location loc = source_location::current()) {
std::stringstream ss;
ss << loc.function_name() << " in "
<< loc.file_name() << ':'
<< loc.line() << ' '
<< message;
if(!is_empty<Z<T...>>::value)
((ss << std::forward<T>(pack)), ...);
throw ERROR(ss.str());
}
explicit throw_with_pos(const source_location& loc, T &&... pack) {
std::stringstream ss;
ss << loc.function_name() << " in "
<< loc.file_name() << ':'
<< loc.line() << ' ';
if(!is_empty<Z<T...>>::value)
((ss << std::forward<T>(pack)), ...);
throw ERROR(ss.str());
}
};
template<typename ERROR = std::runtime_error, typename... T>
throw_with_pos(std::string_view, T &&...m) -> throw_with_pos<ERROR, T...>;
template<typename ERROR = std::runtime_error, typename... T>
throw_with_pos(const source_location&, T &&...m) -> throw_with_pos<ERROR, T...>;

View file

@ -0,0 +1,14 @@
/**
* {{ cookiecutter.description }}
* @file {{ cookiecutter.app_name }}.cpp
*/
/**
* The starting point of the program
* @param argc the number of arguments
* @param argv the argument array
*/
int main(int argc, char **argv)
{
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
//
// Created by jedi on 1/18/19.
//
#define CATCH_CONFIG_MAIN
#include "test.h"

View file

@ -0,0 +1,13 @@
//
// Created by jedi on 1/23/19.
//
#ifndef TETRA_COMMON_TEST_H
#define TETRA_COMMON_TEST_H
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include "catch.hpp"
using namespace Catch::Matchers;
#endif //TETRA_COMMON_TEST_H