From d0a7f73512441162a5db2669074e756f4f245c7e Mon Sep 17 00:00:00 2001 From: karl Date: Thu, 4 Mar 2021 19:37:40 +0100 Subject: [PATCH] Restructure to SCons with empty Vector lib --- .gitignore | 4 ++++ .vscode/launch.json | 17 +++++++++++++++++ .vscode/tasks.json | 11 +++++++++++ Makefile | 11 ----------- README.md | 12 +++++++----- SConstruct | 8 ++++++++ Vector.cpp | 6 ++++++ Vector.h | 4 ++++ main.cpp | 5 ++--- tools/format.sh | 13 ------------- 10 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json delete mode 100644 Makefile create mode 100644 SConstruct create mode 100644 Vector.cpp create mode 100644 Vector.h delete mode 100755 tools/format.sh diff --git a/.gitignore b/.gitignore index e257658..290f354 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ *.out *.app +# SConstruct +**/.sconsign.dblite +compile_commands.json +.cache/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fa0eb02 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // 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": "Debug", + "type": "gdb", + "request": "launch", + "target": "./vector.out", + "cwd": "${workspaceRoot}", + "valuesFormatting": "parseText", + "preLaunchTask": "build" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..482b877 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "scons", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 87d04ec..0000000 --- a/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -CXX = g++ -CXXFLAGS = -Wall -O3 - -program: main.o - $(CXX) $(CXXFLAGS) -o program.out main.o - -main.o: main.cpp - $(CXX) $(CXXFLAGS) -c main.cpp - -clean : - -rm *.o *.out diff --git a/README.md b/README.md index 53d7865..10f7f4a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -# cpp-template +# Vector Library -## Instructions +## Building +Run `scons` in the root directory. -- Formatting: `./format.sh` -- Building: `make` -- Running: `./program.out` +## Developing +The `scons` command also generates a `compile_commands.json` which can be used by the VSCodium extension `clangd` for autocompletion, debugging, etc. + +Build and run scripts for VSCodium are provided as well. \ No newline at end of file diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..2f851b0 --- /dev/null +++ b/SConstruct @@ -0,0 +1,8 @@ +#!python + +# Create the environment and create a Compilation Database for use in VSCodium +env = DefaultEnvironment(tools=['default', 'compilation_db']) +env.CompilationDatabase() + +# Build the output program +Program('vector.out', Glob('*.cpp')) diff --git a/Vector.cpp b/Vector.cpp new file mode 100644 index 0000000..670384a --- /dev/null +++ b/Vector.cpp @@ -0,0 +1,6 @@ +#include "Vector.h" +#include + +Vector::Vector() { + std::cout << "Vector created" << std::endl; +} diff --git a/Vector.h b/Vector.h new file mode 100644 index 0000000..abdb1a7 --- /dev/null +++ b/Vector.h @@ -0,0 +1,4 @@ +class Vector { + public: + Vector(); +}; diff --git a/main.cpp b/main.cpp index cf41c94..8f8e0b8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,6 @@ +#include "Vector.h" #include int main() { - std::cout << "Hello World!" << std::endl; - - return 0; + Vector vector; } diff --git a/tools/format.sh b/tools/format.sh deleted file mode 100755 index ec33b0f..0000000 --- a/tools/format.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -if [[ "$OSTYPE" == "darwin"* ]]; then - clang_format_command="clang-format" - clang_tidy_command="run-clang-tidy" -fi -if [[ "$OSTYPE" == "linux"* ]]; then - clang_format_command="clang-format-11" - clang_tidy_command="run-clang-tidy-11" -fi - -eval "$clang_format_command -i *.h *.cpp -style=file" -eval "$clang_tidy_command -fix"