Skip to content

Commit

Permalink
feat: add support to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
igormcoelho committed Feb 28, 2023
1 parent ea0b0e6 commit 73bf774
Show file tree
Hide file tree
Showing 31 changed files with 24,887 additions and 18,776 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
./tests/thirdparty/
build/
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build --cxxopt='-std=c++17'
build --cxxopt='-Wfatal-errors'
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.4.0
14 changes: 14 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# clang-format -style=google -dump-config > .clang-format
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
ReferenceAlignment: Left
DerivePointerAlignment: false
#
# Offending cpplint itself: "More than one command on the same line" "[whitespace/newline]"
# Sometimes, we need to manually add more lines to lambda, to make sure it will break line
# AllowShortLambdasOnASingleLine : SLS_Inline
#
...

42 changes: 42 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
UseColor: true

Checks: >
cppcoreguidelines-*,
google-*,
performance-*,
-cppcoreguidelines-avoid-magic-numbers,
-google-readability-todo,
-performance-unnecessary-value-param,
-google-readability-braces-around-statements,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-pro-type-cstyle-cast,
-clang-diagnostic-builtin-macro-redefined,
-google-readability-casting
#
HeaderFilterRegex: ".*"
# HeaderFilterRegex: "^((?!catch2).)*$" # DOES NOT WORK FOR CPP... only HPP...
#
# HeaderFilterRegex: '^((?!tests/thirdparty/|/external/).)*$' # DOES NOT WORK
#
#
# disable: cppcoreguidelines-pro-type-union-access
# how to disable: bugprone-easily-swappable-parameters
# bugprone-*,
# -cppcoreguidelines-pro-type-union-access,
# -bugprone-easily-swappable-parameters

# TODO: include 'performance-unnecessary-value-param'


CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: '1'
# https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/special-member-functions.html

FormatStyle: 'file'

WarningsAsErrors: "*"

# ignore protobuf and gRPC generated header (bug in union impl)
# Code '(?<!' will start a negative look behind expression
HeaderFilterRegex: 'bftevent.*(?<!\.pb\.h)$'
52 changes: 52 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM mcr.microsoft.com/devcontainers/cpp:0-ubuntu-22.04
# LIST: https://mcr.microsoft.com/v2/vscode/devcontainers/cpp/tags/list

# command 'add-apt-repository'
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends software-properties-common

# see: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
# RUN sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test

# ===========

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"

# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

#RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends nodejs npm

# clang-tidy
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends clang-tidy clang-format clangd

# bazel
RUN curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends nodejs

RUN npm install -g @bazel/bazelisk

# install pip and cpplint
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends python3-pip
# install cpplint into /usr/local/bin/cpplint
RUN pip install cpplint

# bumpver
RUN python3 -m pip install bumpver
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",
// Configure tool-specific properties.
// "customizations": {},
"extensions": [
"mine.cpplint",
"DevonDCarew.bazel-code",
"llvm-vs-code-extensions.vscode-clangd",
"matepek.vscode-catch2-test-adapter"
],
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root",
"postCreateCommand": "bazel --version && test -e .clang-format && cp .clang-format ~/.cache"
//"runArgs": ["--userns=keep-id"],
//"postCreateCommand": "su imcoelho",
//"containerUser": "vscode",
}
58 changes: 58 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
appMain
*~
bazel-*
build/
.cache/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tests/thirdparty/gbenchmark"]
path = tests/thirdparty/gbenchmark
url = https://github.com/google/benchmark.git
[submodule "tests/thirdparty/Catch2"]
path = tests/thirdparty/Catch2
url = https://github.com/catchorg/Catch2.git
118 changes: 48 additions & 70 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,99 +1,77 @@
{
"[cpp]": {
"editor.tabSize" : 3,
"editor.detectIndentation": false
},
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle : Mozilla , ColumnLimit : 0, IndentWidth: 3, AccessModifierOffset: -3}",
"editor.formatOnSave": true,
"cpplint.cpplintPath": "/usr/local/bin/cpplint",
"cpplint.root": "${workspaceFolder}/include",
"cpplint.repository": "${workspaceFolder}",
"clangd.arguments": [
"-log=verbose",
"-pretty",
"--background-index",
"--compile-commands-dir=/workspaces/cycles/build/",
// "--compile-commands-dir=/workspaces/cycles/",
],
"C_Cpp.intelliSenseEngine": "Disabled",
"testMate.cpp.test.advancedExecutables": [
{
//"pattern": "{bazel-bin}/**/*{test}*"
"pattern": "{build}/**/*{test}*"
}
],
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true,
"C_Cpp.default.compileCommands": "${workspaceFolder}/compile_commands.json",
//
"files.associations": {
"iostream": "cpp",
"limits": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"compare": "cpp",
"concepts": "cpp",
"coroutine": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"mutex": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"numbers": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
},
"search.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/bower_components": true,
"**/tmp": true,
"**/gbenchmark" : true
},
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "googletest.failed",
"settings": {
"foreground": "#f00"
}
},
{
"scope": "googletest.passed",
"settings": {
"foreground": "#0f0"
}
},
{
"scope": "googletest.run",
"settings": {
"foreground": "#0f0"
}
}
]
"utility": "cpp",
"cstring": "cpp",
"algorithm": "cpp",
"cerrno": "cpp",
"climits": "cpp",
"ios": "cpp",
"iterator": "cpp",
"queue": "cpp",
"random": "cpp"
},
//"testMate.cpp.test.executables": "{tests,build,Build,BUILD,out,Out,OUT,bazel-bin}/**/*{test,Test,TEST}*",
"testMate.cpp.test.executables": "{bazel-bin}/**/*{test,Test,TEST}*",
"bazel.pathsToIgnore": ["./tests/thirdparty"],
// ...
"cmake.sourceDirectory": "${workspaceFolder}/.",
}
Loading

0 comments on commit 73bf774

Please sign in to comment.