templates: add c++-cmake

This commit is contained in:
Bruno BELANYI 2023-04-04 15:48:04 +00:00
parent 951770904f
commit 9822b034f7
12 changed files with 230 additions and 1 deletions

View file

@ -0,0 +1,23 @@
# vim: ft=yaml
---
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
# Short functions should not be on a single line, unless empty
AllowShortFunctionsOnASingleLine: Empty
# Make them level
AccessModifierOffset: -4
# It makes more sense this way
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
# Aesthetic
AlignOperands: AlignAfterOperator
---

View file

@ -0,0 +1,10 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi
use flake
watch_file ./flake/checks.nix
watch_file ./flake/dev-shells.nix
eval "$shellHooks"

7
templates/c++-cmake/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
# CMake build directories
/build
/build-*
# Nix generated files
/.pre-commit-config.yaml
/result

View file

@ -0,0 +1,26 @@
labels:
type: exec
pipeline:
- name: nix flake check
image: bash
commands:
- nix flake check
- name: notifiy
image: bash
secrets:
- source: matrix_homeserver
target: address
- source: matrix_roomid
target: room
- source: matrix_username
target: user
- source: matrix_password
target: pass
commands:
- nix run '.#matrix-notifier'
when:
status:
- failure
- success

View file

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.10)
project(project VERSION 0.0.0 LANGUAGES CXX)
enable_testing()
add_library(common_options INTERFACE)
target_compile_features(common_options INTERFACE
cxx_std_20
)
target_compile_options(common_options INTERFACE
-Wall
-Wextra
)
target_include_directories(common_options INTERFACE
src
)
add_subdirectory(src)
add_subdirectory(tests)

View file

@ -0,0 +1,112 @@
{
description = "A C++ project";
inputs = {
futils = {
type = "github";
owner = "numtide";
repo = "flake-utils";
ref = "main";
};
nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixos-unstable";
};
pre-commit-hooks = {
type = "github";
owner = "cachix";
repo = "pre-commit-hooks.nix";
ref = "master";
inputs = {
flake-utils.follows = "futils";
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, futils, nixpkgs, pre-commit-hooks }:
{
overlays = {
default = final: prev: {
project = with final; stdenv.mkDerivation {
pname = "project";
version = "0.0.0";
src = self;
nativeBuildInputs = with pkgs; [
cmake
ninja
pkg-config
];
checkInputs = with pkgs; [
gtest
];
doCheck = true;
meta = with lib; {
description = "A C++ project";
homepage = "https://gitea.belanyi.fr/ambroisie/project";
license = licenses.mit;
maintainers = with maintainers; [ ambroisie ];
platforms = platforms.unix;
};
};
};
};
} // futils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
pre-commit = pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
nixpkgs-fmt = {
enable = true;
};
clang-format = {
enable = true;
};
};
};
in
{
checks = {
inherit (self.packages.${system}) project;
inherit pre-commit;
};
devShells = {
default = pkgs.mkShell {
inputsFrom = with self.packages.${system}; [
project
];
packages = with pkgs; [
clang-tools
];
inherit (pre-commit) shellHook;
};
};
packages = futils.lib.flattenTree {
default = pkgs.project;
inherit (pkgs) project;
};
});
}

View file

@ -0,0 +1,4 @@
add_executable(project main.cc)
target_link_libraries(project PRIVATE common_options)
install(TARGETS project)

View file

@ -0,0 +1,5 @@
#include <iostream>
int main() {
std::cout << "Hello World!\n";
}

View file

@ -0,0 +1 @@
add_subdirectory(unit)

View file

@ -0,0 +1,15 @@
find_package(GTest)
if (${GTest_FOUND})
include(GoogleTest)
add_executable(dummy_test dummy_test.cc)
target_link_libraries(dummy_test PRIVATE common_options)
target_link_libraries(dummy_test PRIVATE
GTest::gtest
GTest::gtest_main
)
gtest_discover_tests(dummy_test)
endif (${GTest_FOUND})

View file

@ -0,0 +1,5 @@
#include <gtest/gtest.h>
TEST(misc, passing) {
ASSERT_EQ(1, 1);
}

View file

@ -1,3 +1,6 @@
{ {
# Add templates "c++-cmake" = {
path = ./c++-cmake;
description = "A C++ project using CMake";
};
} }