Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .cmake-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"line_width": 120,
"tab_size": 4,
"max_subgroups_hwrap": 3
}
29 changes: 18 additions & 11 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive
ARG USER=ubuntu

RUN apt-get update && apt-get install -y \
# Install packages and clean up after
RUN apt-get update && apt-get install -y --no-install-recommends \
bash-completion \
build-essential \
cmake \
clang \
clangd \
clang-format \
clang-tidy \
clangd \
curl \
doxygen \
gdb \
Expand All @@ -19,19 +21,24 @@ RUN apt-get update && apt-get install -y \
lldb \
llvm \
nano \
software-properties-common \
openssh-client \
pipx \
sudo \
unzip \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Configure user environment and permissions
RUN passwd -d ${USER} \
&& mkdir -p /home/${USER}/.cache \
&& chown -R ${USER}:${USER} /home/${USER}/.cache \
&& echo "export PROMPT_COMMAND='history -a'" >> /home/${USER}/.bashrc \
&& echo "export HISTFILE=/home/${USER}/.cache/.bash_history" >> /home/${USER}/.bashrc

ARG USERNAME=ubuntu
RUN passwd -d ${USERNAME} \
&& mkdir -p /home/${USERNAME}/.cache && chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.cache \
&& SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/home/${USERNAME}/.cache/.bash_history" \
&& echo "$SNIPPET" >> "/home/${USERNAME}/.bashrc"
USER ${USER}

USER $USERNAME
# Install cmake-format
RUN pipx install cmake-format --include-deps \
&& pipx ensurepath

WORKDIR /workspace
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"twxs.cmake",
"fredericbonnet.cmake-test-adapter",
"llvm-vs-code-extensions.vscode-clangd",
"vadimcn.vscode-lldb"
"vadimcn.vscode-lldb",
"cheshirekow.cmake-format",
"ms-vscode.cpptools"
]
}
},
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,21 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{github.workspace}}/build/coverage.info

clang-format:
name: Clang Format
format:
name: Format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run Clang Format
run: clang-format --dry-run --Werror $(find include tests examples -type f -name *.*pp)
- name: C++
run: clang-format --dry-run --Werror $(find . -name *.*pp)

- name: CMake
run: |
pip install cmake-format
cmake-format -i $(find -name CMakeLists.txt)
git diff --exit-code

clang-tidy:
name: Clang Tidy
Expand Down
24 changes: 22 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,35 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch (LLDB)",
"name": "Launch GDB",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Launch LLDB",
"type": "lldb",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [
"--gtest_color=yes"
],
"cwd": "${workspaceFolder}",
"terminal": "integrated"
"terminal": "integrated",
"initCommands": [
"settings set target.disable-aslr false"
]
}
]
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[cmake]": {
"editor.defaultFormatter": "cheshirekow.cmake-format"
},
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build",
"--background-index",
"--clang-tidy"
],
"C_Cpp.intelliSenseEngine": "disabled",
"cSpell.words": [
"clangd",
"ensurepath",
"graphviz",
"HISTFILE",
"lldb",
"noninteractive",
"pipx"
]
}
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.15)
project(cpp_channel)
set(PROJECT_VERSION 1.3.0)

Expand All @@ -20,12 +20,12 @@ option(CPP_CHANNEL_COVERAGE "Generate test coverage." OFF)
option(CPP_CHANNEL_SANITIZERS "Build with sanitizers." OFF)
option(CPP_CHANNEL_SANITIZE_THREADS "Build with thread sanitizer." OFF)

if (CPP_CHANNEL_BUILD_TESTS)
if(CPP_CHANNEL_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if (CPP_CHANNEL_BUILD_EXAMPLES)
if(CPP_CHANNEL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DIRS = include tests examples

all:

bench:
Expand Down Expand Up @@ -25,3 +27,10 @@ coverage:
doc:
doxygen
cd docs && python3 -m http.server 8000

format:
clang-format -i $(shell find $(DIRS) -name *.*pp)
cmake-format -i $(shell find $(DIRS) -name CMakeLists.txt)

clean:
rm -rf build docs
7 changes: 3 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ function(add_example NAME)

set_target_warnings(${NAME} PRIVATE)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(${NAME} -ltsan)
target_compile_options(${NAME} PRIVATE -fsanitize=thread)
endif()
endif()

add_dependencies(examples ${NAME})
endfunction()
Expand All @@ -18,8 +18,7 @@ function(run_example NAME)
TARGET ${NAME}
POST_BUILD
COMMAND ${NAME}
COMMENT "Running example: ${NAME}"
)
COMMENT "Running example: ${NAME}")
endfunction()

add_custom_target(examples)
Expand Down
13 changes: 6 additions & 7 deletions examples/cmake-project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.15)
project(cmake_project)
set(PROJECT_VERSION 0.1.0)

Expand All @@ -10,11 +10,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror --cover
add_executable(cmake_project src/main.cpp)

include(FetchContent)
if (NOT channel_POPULATED)
FetchContent_Declare(channel URL https://github.com/andreiavrammsd/cpp-channel/archive/v1.3.0.zip DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
if(NOT channel_POPULATED)
FetchContent_Declare(channel URL https://github.com/andreiavrammsd/cpp-channel/archive/v1.3.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
FetchContent_Populate(channel)
include_directories(${channel_SOURCE_DIR}/include)
# OR
# add_subdirectory(${channel_SOURCE_DIR}/)
# target_link_libraries(cmake_project msd_channel)
endif ()
# OR add_subdirectory(${channel_SOURCE_DIR}/) target_link_libraries(cmake_project msd_channel)
endif()
33 changes: 15 additions & 18 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

# Testing framework
if (MSVC)
option(
gtest_force_shared_crt
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
ON)
if(MSVC)
option(gtest_force_shared_crt "Use shared (DLL) run-time lib even when Google Test is built as static lib." ON)
endif()

include(FetchContent)
if (NOT googletest_POPULATED)
if(NOT googletest_POPULATED)
FetchContent_Declare(googletest URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip)
FetchContent_MakeAvailable(googletest)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_GTEST_TESTS OFF CACHE BOOL "" FORCE)
endif ()
endif()

# Test macro
function(package_add_test TESTNAME)
Expand All @@ -28,12 +25,12 @@ function(package_add_test TESTNAME)
set_target_warnings(${TESTNAME} PRIVATE)
target_link_libraries(${TESTNAME} gtest gtest_main)

if (CPP_CHANNEL_COVERAGE)
if(CPP_CHANNEL_COVERAGE)
target_link_libraries(${TESTNAME} -lgcov)
target_compile_options(${TESTNAME} PRIVATE --coverage)
endif ()
endif()

if (CPP_CHANNEL_SANITIZERS)
if(CPP_CHANNEL_SANITIZERS)
target_link_libraries(${TESTNAME} -lubsan)
target_compile_options(${TESTNAME} PRIVATE -fsanitize=undefined)

Expand All @@ -42,12 +39,12 @@ function(package_add_test TESTNAME)
target_link_libraries(${TESTNAME} ${COVERAGE_FLAGS})
target_compile_options(${TESTNAME} PRIVATE ${COVERAGE_FLAGS})
endif()
endif ()
endif()

if (CPP_CHANNEL_SANITIZE_THREADS)
target_link_libraries(${TESTNAME} -fsanitize=thread)
if(CPP_CHANNEL_SANITIZE_THREADS)
target_link_libraries(${TESTNAME} -fsanitize=thread)
target_compile_options(${TESTNAME} PRIVATE -fsanitize=thread)
endif ()
endif()

add_test(NAME ${TESTNAME} COMMAND ${TESTNAME})
set_tests_properties(${TESTNAME} PROPERTIES LABELS "channel_tests")
Expand All @@ -62,18 +59,18 @@ package_add_test(channel_test channel_test.cpp)
package_add_test(blocking_iterator_test blocking_iterator_test.cpp)
package_add_test(storage_test storage_test.cpp)

if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# Disable warnings about C++17 extensions
target_compile_options(channel_test PRIVATE -Wno-c++17-extensions)
endif()

# Benchmark
if (NOT benchmark_POPULATED)
if(NOT benchmark_POPULATED)
FetchContent_Declare(benchmark URL https://github.com/google/benchmark/archive/refs/tags/v1.9.4.zip)
FetchContent_MakeAvailable(benchmark)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
endif ()
endif()

add_executable(channel_benchmark channel_benchmark.cpp)
target_link_libraries(channel_benchmark benchmark)
Expand Down