Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 48 additions & 0 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake on a single platform

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
BUILD_TESTS: ON

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
container:
image: guillaumemichel1026/cvector:latest
options: --privileged

steps:
- uses: actions/checkout@v4

- name: Install Conan dependencies
if: env.BUILD_TESTS == 'ON'
run: |
conan install . --output-folder=build --build=missing -s build_type=${{env.BUILD_TYPE}}

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DBUILD_TESTS=${{env.BUILD_TESTS}} \
-DCMAKE_TOOLCHAIN_FILE=build/Debug/generators/conan_toolchain.cmake

- name: Build
# Build your program with the given configuration
run: cmake --build build --config ${{env.BUILD_TYPE}}

- name: Test
if: env.BUILD_TESTS == 'ON'
run: ctest --test-dir build --output-on-failure

13 changes: 13 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.30)
project(cvector LANGUAGES C CXX)

option(BUILD_TESTS "Build tests" ON)

include_directories(include)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-g -fprofile-arcs -ftest-coverage)
add_link_options(-fprofile-arcs -ftest-coverage)
endif()

add_library(cvector STATIC
src/cvector_core.c
src/cvector_insert_erase.c
src/cvector_resize.c
)

# Exemple d'utilisation
add_executable(example examples/example_usage.c)
target_link_libraries(example cvector)

# Tests
if(BUILD_TESTS)
enable_testing()
find_package(GTest REQUIRED)

add_executable(test_cvector tests/test_cvector.cpp)
target_link_libraries(test_cvector PRIVATE cvector gtest::gtest)
add_test(NAME cvector_tests COMMAND test_cvector)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
find_program(GCOVR_EXECUTABLE gcovr REQUIRED)
add_custom_target(coverage
COMMAND ${GCOVR_EXECUTABLE} --root ${CMAKE_SOURCE_DIR} --filter ${CMAKE_SOURCE_DIR}/src/ --html --html-details --output coverage.html
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating code coverage report"
)
endif()
50 changes: 50 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No color

# Directories
BUILD_DIR="build"

# CMake options
CMAKE_BUILD_TYPE="Debug" # Change to "Release" if needed
BUILD_TESTS=ON # Enable or disable tests

echo -e "${GREEN}--- Configuring and building with CMake ---${NC}"

# Install Conan dependencies if tests are enabled
if [ "$BUILD_TESTS" = "ON" ]; then
echo -e "${GREEN}--- Installing dependencies with Conan ---${NC}"
if ! conan install . --output-folder="$BUILD_DIR" --build=missing -s build_type="$CMAKE_BUILD_TYPE"; then
echo -e "${RED}Conan dependency installation failed.${NC}"
exit 1
fi
fi

# Configure and generate build files using CMake
if ! cmake -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" -DBUILD_TESTS="$BUILD_TESTS" -DCMAKE_TOOLCHAIN_FILE="$BUILD_DIR/build/Debug/generators/conan_toolchain.cmake" .; then
echo -e "${RED}CMake configuration failed.${NC}"
exit 1
fi

# Build the project
if ! cmake --build "$BUILD_DIR" --config "$CMAKE_BUILD_TYPE"; then
echo -e "${RED}Build failed.${NC}"
exit 1
fi

echo -e "${GREEN}--- Build completed successfully ---${NC}"

# Run tests if enabled
if [ "$BUILD_TESTS" = "ON" ]; then
echo -e "${GREEN}--- Running tests ---${NC}"
if ! ctest --test-dir "$BUILD_DIR" --output-on-failure; then
echo -e "${RED}Some tests failed.${NC}"
exit 1
fi
echo -e "${GREEN}All tests passed successfully.${NC}"
fi

echo -e "${GREEN}Script completed successfully.${NC}"
Loading
Loading