From 4aa57c5bd061e40a3158f6cbc03f1f96b99e714d Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Sun, 8 Jan 2023 18:41:40 +0100 Subject: [PATCH] setup --- .clang-format | 8 ++++++++ .clangd | 40 +++++++++++++++++++++++++++++++++++++++ README.md | 34 ++++++++++++++++++++++++++++++++- browser/main.cpp | 3 +++ browser/meson.build | 3 +++ meson.build | 43 ++++++++++++++++++++++++++++++++++++++++++ server/main.cpp | 3 +++ server/meson.build | 3 +++ subprojects/.gitignore | 3 +++ subprojects/fmt.wrap | 12 ++++++++++++ subprojects/sdl2.wrap | 12 ++++++++++++ 11 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 .clang-format create mode 100644 .clangd create mode 100644 browser/main.cpp create mode 100644 browser/meson.build create mode 100644 meson.build create mode 100644 server/main.cpp create mode 100644 server/meson.build create mode 100644 subprojects/.gitignore create mode 100644 subprojects/fmt.wrap create mode 100644 subprojects/sdl2.wrap diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..563073b --- /dev/null +++ b/.clang-format @@ -0,0 +1,8 @@ +BasedOnStyle: WebKit +IndentWidth: 4 +ColumnLimit: 80 +IndentCaseLabels: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + SplitEmptyFunction: false diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..26ed4c4 --- /dev/null +++ b/.clangd @@ -0,0 +1,40 @@ +CompileFlags: + CompilationDatabase: ./builddir +Diagnostics: + ClangTidy: + Add: + - bugprone-* + - clang-analyzer-* + - cppcoreguidelines-* + - modernize-* + - readability-* + Remove: + - readability-braces-around-statements + - cppcoreguidelines-avoid-magic-numbers + - readability-magic-numbers + - readability-identifier-length + - bugprone-easily-swappable-parameters + + CheckOptions: + UnusedIncludes: Strict + + # typecase rules + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.ConstantCase: lower_case + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.EnumConstantCase: CamelCase + readability-identifier-naming.FunctionCase: lower_case + readability-identifier-naming.InlineNamespaceCase: lower_case + readability-identifier-naming.MacroDefinitionCase: UPPER_CASE + readability-identifier-naming.MemberCase: lower_case + readability-identifier-naming.MethodCase: lower_case + readability-identifier-naming.NamespaceCase: lower_case + readability-identifier-naming.ScopedEnumConstantCase: CamelCase + readability-identifier-naming.StructCase: CamelCase + readability-identifier-naming.TemplateParameterCase: CamelCase + readability-identifier-naming.TemplateTemplateParameterCase: CamelCase + readability-identifier-naming.TypeAliasCase: CamelCase + readability-identifier-naming.TypedefCase: CamelCase + readability-identifier-naming.UnionCase: CamelCase + readability-identifier-naming.ValueTemplateParameterCase: lower_case + readability-identifier-naming.VariableCase: lower_case diff --git a/README.md b/README.md index 64d2cf5..67fde65 100644 --- a/README.md +++ b/README.md @@ -1 +1,33 @@ -# web-stack-project \ No newline at end of file + +# web-stack-project + +## Build project + +- Open project in terminal +- Run `meson setup builddir`, or `CXX=clang- meson setup builddir` if clang and clang-version is different +- Navigate into builddir, `cd builddir` +- Compile `meson compile` +- Run, `./browser` or `./server` + +## VS Code development setup + +### Install +- `clang-15` recommended, `clang-15` based, check with `clang --version` +- [Meson](https://mesonbuild.com/), build system +- [Meson VS Code extension](https://marketplace.visualstudio.com/items?itemName=mesonbuild.mesonbuild) +- [VSCode - clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd), linter +- [VSCode - CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb), debugger +- [VSCode - Better C++ Syntax](https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax), syntax higlighting + +### Config + +Add these to `settings.json` if necessary +```json +{ + // probably necessary + "clangd.onConfigChanged": "restart", + + // only necessary if default `/usr/bin/clangd` isn't the correct version + "clangd.path": "/usr/bin/clangd-", // is a place holder, eg, `clangd-15` +} +``` diff --git a/browser/main.cpp b/browser/main.cpp new file mode 100644 index 0000000..d7b16c1 --- /dev/null +++ b/browser/main.cpp @@ -0,0 +1,3 @@ +#include + +int main() { fmt::print("browser: hello world!\n"); } \ No newline at end of file diff --git a/browser/meson.build b/browser/meson.build new file mode 100644 index 0000000..7053338 --- /dev/null +++ b/browser/meson.build @@ -0,0 +1,3 @@ +browser_sources += files( + 'main.cpp', +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..a533aae --- /dev/null +++ b/meson.build @@ -0,0 +1,43 @@ +project( + 'web-stack-project', + 'cpp', + version: '0.1', + default_options: [ + 'warning_level=3', + 'werror=true', + 'cpp_std=c++20', + ], +) + +fmt_dep = dependency('fmt') +sdl2_dep = dependency('sdl2') + +server_sources = [] +subdir('server') +server_exe = executable( + 'web-server', + server_sources, + win_subsystem: 'console', + include_directories: [ + include_directories('server'), + ], + dependencies: [ + fmt_dep, + sdl2_dep, + ], +) + +browser_sources = [] +subdir('browser') +browser_exe = executable( + 'web-browser', + browser_sources, + win_subsystem: 'console', + include_directories: [ + include_directories('browser'), + ], + dependencies: [ + fmt_dep, + sdl2_dep, + ], +) diff --git a/server/main.cpp b/server/main.cpp new file mode 100644 index 0000000..b96f161 --- /dev/null +++ b/server/main.cpp @@ -0,0 +1,3 @@ +#include + +int main() { fmt::print("server: hello world!\n"); } \ No newline at end of file diff --git a/server/meson.build b/server/meson.build new file mode 100644 index 0000000..235f926 --- /dev/null +++ b/server/meson.build @@ -0,0 +1,3 @@ +server_sources += files( + 'main.cpp', +) diff --git a/subprojects/.gitignore b/subprojects/.gitignore new file mode 100644 index 0000000..4ce29d7 --- /dev/null +++ b/subprojects/.gitignore @@ -0,0 +1,3 @@ +packagecache/ +fmt-* +SDL2-* diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap new file mode 100644 index 0000000..0ea7eb3 --- /dev/null +++ b/subprojects/fmt.wrap @@ -0,0 +1,12 @@ +[wrap-file] +directory = fmt-9.1.0 +source_url = https://github.com/fmtlib/fmt/archive/9.1.0.tar.gz +source_filename = fmt-9.1.0.tar.gz +source_hash = 5dea48d1fcddc3ec571ce2058e13910a0d4a6bab4cc09a809d8b1dd1c88ae6f2 +patch_filename = fmt_9.1.0-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/fmt_9.1.0-1/get_patch +patch_hash = 4557b9ba87b3eb63694ed9b21d1a2117d4a97ca56b91085b10288e9a5294adf8 +wrapdb_version = 9.1.0-1 + +[provide] +fmt = fmt_dep diff --git a/subprojects/sdl2.wrap b/subprojects/sdl2.wrap new file mode 100644 index 0000000..53a71e2 --- /dev/null +++ b/subprojects/sdl2.wrap @@ -0,0 +1,12 @@ +[wrap-file] +directory = SDL2-2.26.0 +source_url = https://github.com/libsdl-org/SDL/releases/download/release-2.26.0/SDL2-2.26.0.tar.gz +source_filename = SDL2-2.26.0.tar.gz +source_hash = 8000d7169febce93c84b6bdf376631f8179132fd69f7015d4dadb8b9c2bdb295 +patch_filename = sdl2_2.26.0-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/sdl2_2.26.0-1/get_patch +patch_hash = 6fcfd727d71cf7837332723518d5e47ffd64f1e7630681cf4b50e99f2bf7676f +wrapdb_version = 2.26.0-1 + +[provide] +sdl2 = sdl2_dep