From cfbeaa8f9cc11112c74f2d40fb42076472666d5e Mon Sep 17 00:00:00 2001 From: Moritz Martinius Date: Thu, 1 Feb 2024 18:52:42 +0100 Subject: [PATCH] Initial commit --- .clang-format | 96 +++++++++++++++++++++++++++++++++++ .clang-format-include | 2 + .clang-tidy | 35 +++++++++++++ .gitignore | 12 +++++ .vscode/c_cpp_properties.json | 15 ++++++ .vscode/launch.json | 27 ++++++++++ .vscode/settings.json | 88 ++++++++++++++++++++++++++++++++ README.md | 0 meson.build | 34 +++++++++++++ src/main.cpp | 6 +++ src/meson.build | 3 ++ subprojects/gtest.wrap | 16 ++++++ tests/meson.build | 12 +++++ 13 files changed, 346 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-format-include create mode 100644 .clang-tidy create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 meson.build create mode 100644 src/main.cpp create mode 100644 src/meson.build create mode 100644 subprojects/gtest.wrap create mode 100644 tests/meson.build diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a043404 --- /dev/null +++ b/.clang-format @@ -0,0 +1,96 @@ +# Google C/C++ Code Style settings +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html + +Language: Cpp +BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignOperands: Align +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Inline +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterStruct: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 100 +CompactNamespaces: false +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +EmptyLineBeforeAccessModifier: LogicalBlock +FixNamespaceComments: true +IndentCaseLabels: true +IndentPPDirectives: None +IndentAccessModifiers: false +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Left +ReflowComments: false +SeparateDefinitionBlocks: Always +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++17 +TabWidth: 4 +UseTab: Never +QualifierAlignment: Left +SortIncludes: true +IncludeBlocks: Regroup +IncludeCategories: + # Classes own header is always priority 0 + # System C/C++ headers in <> with extension. + - Regex: '<([A-Za-z0-9.\Q/-_\E])+.h.*>' + Priority: 1 + # System Headers in <> without extension. + - Regex: '<([A-Za-z0-9.\Q/-_\E])+>' + Priority: 2 + # c Headers in "" with extension. + - Regex: '"([A-Za-z0-9.\Q/-_\E])+"' + Priority: 3 diff --git a/.clang-format-include b/.clang-format-include new file mode 100644 index 0000000..33b0a3a --- /dev/null +++ b/.clang-format-include @@ -0,0 +1,2 @@ +src/* +tests/* \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..63d1f0d --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,35 @@ +--- +Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type" +WarningsAsErrors: true +HeaderFilterRegex: "" +AnalyzeTemporaryDtors: false +FormatStyle: google +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: "L;LL;LU;LLU" + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: "0" + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: "1" + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: "1" + - key: google-readability-braces-around-statements.ShortStatementLines + value: "1" + - key: google-readability-function-size.StatementThreshold + value: "800" + - key: google-readability-namespace-comments.ShortNamespaceLines + value: "10" + - key: google-readability-namespace-comments.SpacesBeforeComments + value: "2" + - key: modernize-loop-convert.MaxCopySize + value: "16" + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: "NULL" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b3f0cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Folder +builddir/ +subprojects/* +.cache/ +coverageReport/ + +# Files +!subprojects/*.wrap +.vscode/* +!.vscode/c_cpp_properties.json +!.vscode/settings.json +!.vscode/launch.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..84aeb11 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "compilerPath": "/usr/bin/clang", + "cStandard": "c11", + "cppStandard": "c++17", + "compileCommands": "${workspaceFolder}/builddir/compile_commands.json", + "browse": { + "path": ["${workspaceFolder}"] + } + } + ], + "version": 4 +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..32b9b90 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Verwendet IntelliSense zum Ermitteln möglicher Attribute. + // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. + // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "ptprnt_debug", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/builddir/shmem", + "args": ["-t Hello"], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c86af4b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,88 @@ +{ + "clangd.arguments": ["-background-index", "-compile-commands-dir=builddir/"], + "editor.formatOnType": false, + "editor.formatOnSave": true, + "files.associations": { + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cfenv": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "source_location": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "shared_mutex": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp", + "csignal": "cpp", + "any": "cpp", + "regex": "cpp", + "future": "cpp", + "charconv": "cpp", + "*.ipp": "cpp" + }, + "clang-tidy.buildPath": "builddir/", + "clangd.onConfigChanged": "restart",] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..f1d00dc --- /dev/null +++ b/meson.build @@ -0,0 +1,34 @@ +project('shmem', 'cpp', + version: 'v0.1.0-'+run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip(), + license: 'GPLv3', + default_options : ['c_std=c11', 'cpp_std=c++17'] +) + +log_dep = dependency('spdlog') +fmt_dep = dependency('fmt') + +incdir = include_directories('src') + +subdir('src') + +executable( + 'shmem', + 'src/main.cpp', + install: true, + dependencies : [log_dep, fmt_dep], + include_directories: incdir, + sources: [srcs], + cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'], +) + + +### Unit tests + +# GTest +gtest_proj = subproject('gtest') +gtest_dep = gtest_proj.get_variable('gtest_main_dep') +if not gtest_dep.found() + error('MESON_SKIP_TEST: gtest not installed.') +endif + +subdir('tests') \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..f3519b7 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,6 @@ +#include + +int main (int, char**) { + spdlog::info("shmem version {}", PROJECT_VERSION); + return 0; +} \ No newline at end of file diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..743204a --- /dev/null +++ b/src/meson.build @@ -0,0 +1,3 @@ +srcs = [ + +] \ No newline at end of file diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap new file mode 100644 index 0000000..8c067ff --- /dev/null +++ b/subprojects/gtest.wrap @@ -0,0 +1,16 @@ +[wrap-file] +directory = googletest-1.14.0 +source_url = https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz +source_filename = gtest-1.14.0.tar.gz +source_hash = 8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7 +patch_filename = gtest_1.14.0-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.14.0-1/get_patch +patch_hash = 2e693c7d3f9370a7aa6dac802bada0874d3198ad4cfdf75647b818f691182b50 +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.14.0-1/gtest-1.14.0.tar.gz +wrapdb_version = 1.14.0-1 + +[provide] +gtest = gtest_dep +gtest_main = gtest_main_dep +gmock = gmock_dep +gmock_main = gmock_main_dep diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..2b4da13 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,12 @@ +tests = [ + ] + +foreach test : tests + test(test.get(0), + executable(test.get(1), + sources: test.get(2), + include_directories: incdir, + dependencies: [gtest_dep, usb_dep, log_dep, pangocairo_dep, cli11_dep] + ) + ) +endforeach \ No newline at end of file