From 2904f24565a8a3178ff56d72106e1bbe792d7135 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sat, 18 Mar 2023 23:31:20 +0100 Subject: [PATCH] Meta: Add project prerequisites --- .clang-format | 39 ++++++++++++++++++++++ .gitignore | 7 ++++ CMakeLists.txt | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 CMakeLists.txt diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3afd345 --- /dev/null +++ b/.clang-format @@ -0,0 +1,39 @@ +# -*- yaml -*- + +--- +BasedOnStyle: WebKit +IndentWidth: 4 +--- +Language: Cpp + +AlignAfterOpenBracket: Align +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true + +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortLambdasOnASingleLine: All + +AlwaysBreakTemplateDeclarations: Yes +IndentPPDirectives: BeforeHash + +BraceWrapping: + AfterEnum: false + AfterFunction: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + SplitEmptyRecord: false +BreakBeforeBraces: Custom +BreakInheritanceList: BeforeComma + +SpaceAfterTemplateKeyword: false +SpaceInEmptyBlock: false +NamespaceIndentation: None +FixNamespaceComments: true +Standard: c++20 +TabWidth: 4 +UseTab: AlignWithSpaces +... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe4e9e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Directories + +.cache/ +.clangd/ +build/ + +# Files diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..dac6ddd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,89 @@ +# ------------------------------------------ +# User config between these lines + +# Set project name +set(PROJECT "blaze") + +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(BLAZE_STANDALONE TRUE) +endif() + +# Options +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) +option(BLAZE_BUILD_EXAMPLES "Build the Blaze example programs" ${BLAZE_STANDALONE}) + +# ------------------------------------------ + +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) +project(${PROJECT} CXX C) + +# ------------------------------------------ +# Setup C++ compiler + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Compiler flags used for all build types +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") +# -Wall = All warnings about contructions that are easily avoidable +# -Wextra = Extra warning flags not covered by -Wall +# -Wpedantic = Warnings for compiler extensions not part of the standard + +# Set default build type if not specified +set(DEFAULT_BUILD_TYPE Release) +if(EXISTS ${CMAKE_SOURCE_DIR}/.git) + set(DEFAULT_BUILD_TYPE Debug) +endif() +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE}) +endif() + +# Set build type specific compiler flags +message("--- ${CMAKE_BUILD_TYPE} ---") +if(${CMAKE_BUILD_TYPE} STREQUAL Debug) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g -pg") + # -Og = Optimizations that do not interfere with debugging + # -g = Produce debugging information in OS's native format + # -pg = Generate profile information for analysis with gprof + # $ gprof gmon.out > profile-data.txt +elseif(${CMAKE_BUILD_TYPE} STREQUAL Release) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") + # -O3 = Optimizations that increase compilation time and performance +endif() + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# ------------------------------------------ +# Library + +add_subdirectory("vendor/ruc") + +# ------------------------------------------ +# Application target + +# Define source files +file(GLOB_RECURSE PROJECT_SOURCES "src/*.cpp") + +add_executable(${PROJECT} ${PROJECT_SOURCES}) +target_include_directories(${PROJECT} PRIVATE + "src") +target_link_libraries(${PROJECT} ruc) + +# ------------------------------------------ +# Execute target + +add_custom_target(run + COMMAND ${PROJECT}) +add_dependencies(run ${PROJECT}) + +# ------------------------------------------ +# Test targets + +add_custom_target(test0 + COMMAND env STEP=step0_repl MAL_IMPL=js ../vendor/mal/runtest.py --deferrable --optional ../vendor/mal/tests/step0_repl.mal -- ./${PROJECT}) +add_dependencies(test0 ${PROJECT}) + +add_custom_target(test1 + COMMAND env STEP=step1_read_print MAL_IMPL=js ../vendor/mal/runtest.py --deferrable --optional ../vendor/mal/tests/step1_read_print.mal -- ./${PROJECT}) +add_dependencies(test1 ${PROJECT})