Skip to content

Commit

Permalink
chore: Add boilerplate CMake project and Taskfile tasks to lint CMake…
Browse files Browse the repository at this point in the history
… files. (#7)
  • Loading branch information
kirkrodrigues authored Oct 24, 2024
1 parent 915a8a9 commit 03a98d9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .gersemirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# yamllint disable-line rule:line-length
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json

line_length: 100
list_expansion: "favour-expansion"
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# CMake 3.22.1 is the default on Ubuntu 22.04
cmake_minimum_required(VERSION 3.22.1)

project(
spider
LANGUAGES
C
CXX
VERSION 0.1.0
)

# Enable exporting compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
"Enable/Disable output of compile commands during generation."
FORCE
)

# Set the default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(SPIDER_DEFAULT_BUILD_TYPE "Release")
message(STATUS "No build type specified. Setting to '${SPIDER_DEFAULT_BUILD_TYPE}'.")
set(CMAKE_BUILD_TYPE
"${SPIDER_DEFAULT_BUILD_TYPE}"
CACHE STRING
"Choose the type of build."
FORCE
)
endif()

add_executable(spider)
target_compile_features(spider PRIVATE cxx_std_20)

set(SPIDER_SOURCES src/spider/spider.cpp)
target_sources(spider PRIVATE ${SPIDER_SOURCES})

target_include_directories(spider PRIVATE src/)
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ The commands above run all linting checks, but for performance you may want to r
if you only changed C++ files, you don't need to run the YAML linting checks) using one of the tasks
in the table below.

| Task | Description |
|-------------------------|----------------------------------------------------------|
| `lint:yml-check` | Runs the YAML linters. |
| `lint:yml-fix` | Runs the YAML linters and fixes some violations. |
| Task | Description |
|--------------------|--------------------------------------------------|
| `lint:cmake-check` | Runs the CMake linters. |
| `lint:cmake-fix` | Runs the CMake linters and fixes any violations. |
| `lint:yml-check` | Runs the YAML linters. |
| `lint:yml-fix` | Runs the YAML linters and fixes some violations. |

[Task]: https://taskfile.dev
1 change: 1 addition & 0 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gersemi>=0.16.2
yamllint>=1.35.1
29 changes: 29 additions & 0 deletions lint-tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@ vars:
tasks:
check:
cmds:
- task: "cmake-check"
- task: "yml-check"

fix:
cmds:
- task: "cmake-fix"
- task: "yml-fix"

cmake-check:
deps: ["venv"]
cmds:
- task: "cmake"
vars:
FLAGS: "--check"

cmake-fix:
deps: ["venv"]
cmds:
- task: "cmake"
vars:
FLAGS: "--in-place"

yml:
aliases:
- "yml-check"
Expand All @@ -22,6 +38,18 @@ tasks:
. "{{.G_LINT_VENV_DIR}}/bin/activate"
yamllint --strict .
cmake:
internal: true
requires:
vars: ["FLAGS"]
cmd: |-
. "{{.G_LINT_VENV_DIR}}/bin/activate"
find . \
-path ./build -prune \
-o -name CMakeLists.txt \
-print0 | \
xargs -0 --no-run-if-empty gersemi {{.FLAGS}}
venv:
internal: true
vars:
Expand All @@ -32,6 +60,7 @@ tasks:
- "{{.TASKFILE}}"
- "lint-requirements.txt"
generates: ["{{.CHECKSUM_FILE}}"]
run: "once"
deps:
- ":init"
- task: ":utils:validate-checksum"
Expand Down
6 changes: 6 additions & 0 deletions src/spider/spider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}

0 comments on commit 03a98d9

Please sign in to comment.