Skip to content

Commit d0cdcb0

Browse files
ADD full code source + ci/cd
1 parent 2234bc5 commit d0cdcb0

File tree

115 files changed

+12848
-853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+12848
-853
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 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.
2+
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
3+
name: CMake on a single platform
4+
5+
on:
6+
push:
7+
branches: [ "main" ]
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
13+
BUILD_TYPE: Release
14+
BUILD_TESTS: ON
15+
16+
jobs:
17+
build:
18+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
19+
# You can convert this to a matrix build if you need cross-platform coverage.
20+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
21+
runs-on: ubuntu-latest
22+
container:
23+
image: guillaumemichel1026/cvector:latest
24+
options: --privileged
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Install Conan dependencies
30+
if: env.BUILD_TESTS == 'ON'
31+
run: |
32+
conan install . --output-folder=build --build=missing -s build_type=${{env.BUILD_TYPE}}
33+
34+
- name: Configure CMake
35+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
36+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
37+
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
38+
-DBUILD_TESTS=${{env.BUILD_TESTS}} \
39+
-DCMAKE_TOOLCHAIN_FILE=build/Debug/generators/conan_toolchain.cmake
40+
41+
- name: Build
42+
# Build your program with the given configuration
43+
run: cmake --build build --config ${{env.BUILD_TYPE}}
44+
45+
- name: Test
46+
if: env.BUILD_TESTS == 'ON'
47+
run: ctest --test-dir build --output-on-failure
48+

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/cvector.iml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/editor.xml

Lines changed: 0 additions & 485 deletions
This file was deleted.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
11
cmake_minimum_required(VERSION 3.30)
22
project(cvector LANGUAGES C CXX)
33

4+
option(BUILD_TESTS "Build tests" ON)
5+
46
include_directories(include)
57

6-
add_library(cvector STATIC src/utils.c)
8+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
9+
add_compile_options(-g -fprofile-arcs -ftest-coverage)
10+
add_link_options(-fprofile-arcs -ftest-coverage)
11+
endif()
12+
13+
add_library(cvector STATIC
14+
src/cvector_core.c
15+
src/cvector_insert_erase.c
16+
src/cvector_resize.c
17+
)
718

19+
# Exemple d'utilisation
820
add_executable(example examples/example_usage.c)
921
target_link_libraries(example cvector)
22+
23+
# Tests
24+
if(BUILD_TESTS)
25+
enable_testing()
26+
find_package(GTest REQUIRED)
27+
28+
add_executable(test_cvector tests/test_cvector.cpp)
29+
target_link_libraries(test_cvector PRIVATE cvector gtest::gtest)
30+
add_test(NAME cvector_tests COMMAND test_cvector)
31+
endif()
32+
33+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
34+
find_program(GCOVR_EXECUTABLE gcovr REQUIRED)
35+
add_custom_target(coverage
36+
COMMAND ${GCOVR_EXECUTABLE} --root ${CMAKE_SOURCE_DIR} --filter ${CMAKE_SOURCE_DIR}/src/ --html --html-details --output coverage.html
37+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
38+
COMMENT "Generating code coverage report"
39+
)
40+
endif()

build.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ BUILD_DIR="build"
1010

1111
# CMake options
1212
CMAKE_BUILD_TYPE="Debug" # Change to "Release" if needed
13-
BUILD_TESTS=OFF # Enable or disable tests
13+
BUILD_TESTS=ON # Enable or disable tests
1414

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

17+
# Install Conan dependencies if tests are enabled
18+
if [ "$BUILD_TESTS" = "ON" ]; then
19+
echo -e "${GREEN}--- Installing dependencies with Conan ---${NC}"
20+
if ! conan install . --output-folder="$BUILD_DIR" --build=missing -s build_type="$CMAKE_BUILD_TYPE"; then
21+
echo -e "${RED}Conan dependency installation failed.${NC}"
22+
exit 1
23+
fi
24+
fi
25+
1726
# Configure and generate build files using CMake
18-
if ! cmake -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" -DBUILD_TESTS="$BUILD_TESTS" .; then
27+
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
1928
echo -e "${RED}CMake configuration failed.${NC}"
2029
exit 1
2130
fi

0 commit comments

Comments
 (0)