Add .editorconfig

This commit is contained in:
2021-12-02 07:15:35 +00:00
parent d9e1d2cf89
commit e58dede1b6
4 changed files with 64 additions and 33 deletions

24
.editorconfig Normal file
View File

@@ -0,0 +1,24 @@
# \file .editorconfig
# \author Copyright 2020, Matthew Gretton-Dann
# SPDX-License-Identifier: Apache-2.0
# top-most EditorConfig file
root = true
# We default to 2-spaces at tabs
[*]
indent_style = space
indent_size = 2
tab_width = 8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
# Python is 4 spaces
[*.py]
indent_size = 4
max_line_length = 79
# Makefiles use Tabs.
[Makefile]
indent_style = tab

View File

@@ -5,13 +5,15 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
file(GLOB years LIST_DIRECTORIES true RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "20[1-9][0-9]")
file(GLOB years LIST_DIRECTORIES true RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS
"20[1-9][0-9]")
message(STATUS "Years to examine: ${years}")
foreach (year IN LISTS years)
file(GLOB puzzles RELATIVE "${CMAKE_SOURCE_DIR}" CONFIGURE_DEPENDS "${year}/puzzle-*.cc")
foreach (puzzle IN LISTS puzzles)
string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" "puzzle-${year}-\\1" puzzle_name "${puzzle}")
string(REGEX REPLACE "^.*puzzle-(.*)\\.cc" "${CMAKE_SOURCE_DIR}/${year}/puzzle-\\1.CMakeLists.txt" sub_cmake_lists "${puzzle}")
string(REGEX REPLACE "^.*puzzle-(.*)\\.cc"
"${CMAKE_SOURCE_DIR}/${year}/puzzle-\\1.CMakeLists.txt" sub_cmake_lists "${puzzle}")
message(STATUS "Puzzle: ${puzzle_name} - source ${puzzle}")
add_executable("${puzzle_name}" "${puzzle}")
if (EXISTS "${sub_cmake_lists}")

View File

@@ -1,11 +1,12 @@
# C++ Solutions to Advent of Code
This repository contains solutions to various years of the [Advent of Code](https://adventofcode.com)
puzzles. All solutions are written in C++. The solutions aren't designed to be nice or
pretty. Instead, I am using it as an experiment in understanding how I approach solving
problems.
This repository contains solutions to various years of
the [Advent of Code](https://adventofcode.com)
puzzles. All solutions are written in C++. The solutions aren't designed to be nice or pretty.
Instead, I am using it as an experiment in understanding how I approach solving problems.
The solutions are authored by Matthew Gretton-Dann, and Copyright 2020-2021, Matthew Gretton-Dann. Licensed under Apache 2.0 - see [license](./LICENSE).
The solutions are authored by Matthew Gretton-Dann, and Copyright 2020-2021, Matthew Gretton-Dann.
Licensed under Apache 2.0 - see [license](./LICENSE).
## Getting the sources
@@ -25,8 +26,8 @@ The following is required to build the puzzles:
## Running the Puzzles
There is a driver script (`./driver.sh`) in the root of the checkout. It will build and run specific tests. Example
use is as follows:
There is a driver script (`./driver.sh`) in the root of the checkout. It will build and run specific
tests. Example use is as follows:
```sh
YEAR=2020 # Year of puzzle to run
@@ -45,7 +46,10 @@ cmake -Bbuild -S.
cmake --build build
```
Note that some of the puzzles require OpenSSL for the MD5 implementation. On macOS this also requires you to pass an appropariate value for `OPENSSL_ROOT_DIR` to cmake. On x86 this is `-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl` and on AArch64 this is `-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl`.
**Note**: Some puzzles require OpenSSL for the MD5 implementation. On macOS this requires you to
pass an appropriate value for `OPENSSL_ROOT_DIR` to `cmake`. If using `homebrew` then x86 this
is `-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl` and on AArch64 this
is `-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl`.
## Sources
@@ -57,9 +61,10 @@ Each year of puzzles is in a self-contained directory `YEAR`.
Within the directory there are the following files:
* `puzzle-DAY-NUMBER.cc`. The source for puzzle NUMBER on day DAY in the year.
* `puzzle-DAY-NUMBER.cc`. The source for puzzle NUMBER on DAY in the year.
* `driver-DAY-NUMBER.sh`. If present this is used as the driver to run that puzzle.
* `puzzle-DAY-NUMBER.CMakeLists.txt`. If present this is included by `CMakeLists.txt`. The variable `${puzzle_name}`
* `puzzle-DAY-NUMBER.CMakeLists.txt`. If present this is included by `CMakeLists.txt`. The
variable `${puzzle_name}`
contains the name of the puzzle target. Some puzzles use this to depend on OpenSSL.
### Command Line Interface
@@ -67,5 +72,5 @@ Within the directory there are the following files:
The executable command line interface should just take the input in on standard-input and print its
result on standard-output.
If this is not possible the script `driver-DAY-NUMBER.sh` within the year directory should be provided. It should take
two arguments - the executable to run and the input file to use.
If this is not possible the script `driver-DAY-NUMBER.sh` within the year directory should be
provided. It should take two arguments - the executable to run and the input file to use.

View File

@@ -44,8 +44,8 @@ fi
# Rebuild the executable we want to run.
if [ ! -d "build" ]; then
opts=
if [ "$(uname -s)" == "Darwin" ]; then
if [ "$(uname -m)" == "arm64" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -m)" = "arm64" ]; then
opts="-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl"
else
opts="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl"