Skip to content

Commit 01cf545

Browse files
authored
Merge pull request #111 from fdefelici/release_v2.4.5
Release v2.4.5
2 parents 11e49b0 + c3efbbe commit 01cf545

33 files changed

+761
-274
lines changed

.github/workflows/ci_action.yml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ jobs:
2222
BUILD_DIR: ${{ github.workspace }}\build
2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2626
- name: List Workspace
2727
run: dir /a ${{ github.workspace }}
2828
- name: Compile
2929
run: |
3030
echo "== CMAKE VERSION =="
3131
cmake --version
3232
echo "== CMAKE CONFIGURE =="
33-
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_BUILD=true
33+
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_BUILD=ON
3434
echo "== CMAKE BUILD =="
3535
cmake --build ${{env.BUILD_DIR}} --config Release
3636
- name: List Build
@@ -53,15 +53,15 @@ jobs:
5353
BUILD_DIR: ${{ github.workspace }}/build
5454
steps:
5555
- name: Checkout
56-
uses: actions/checkout@v3
56+
uses: actions/checkout@v4
5757
- name: List Workspace
5858
run: ls -la ${{ github.workspace }}
5959
- name: Compile
6060
run: |
6161
echo "== CMAKE VERSION =="
6262
cmake --version
6363
echo "== CMAKE CONFIGURE =="
64-
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_BUILD=true
64+
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_BUILD=ON
6565
echo "== CMAKE BUILD =="
6666
cmake --build ${{env.BUILD_DIR}} --config Release
6767
- name: List Build
@@ -73,27 +73,27 @@ jobs:
7373
cd ${{ github.workspace }}
7474
build_ubuntu:
7575
name: Build ubuntu_${{matrix.compiler.c}}-${{matrix.compiler.v}}
76-
runs-on: ubuntu-latest
76+
runs-on: ubuntu-22.04
7777
strategy:
7878
fail-fast: false
7979
matrix:
8080
compiler:
81-
- {c: gcc, cpp: g++, v: 11, strict: false}
82-
- {c: gcc, cpp: g++, v: 12, strict: false}
83-
- {c: gcc, cpp: g++, v: 13, strict: true}
84-
- {c: clang, cpp: clang++, v: 13, strict: true}
85-
- {c: clang, cpp: clang++, v: 14, strict: true}
86-
- {c: clang, cpp: clang++, v: 15, strict: true}
87-
- {c: clang, cpp: clang++, v: 16, strict: true}
88-
- {c: clang, cpp: clang++, v: 17, strict: true}
81+
- {c: gcc, cpp: g++, v: 11, strict: OFF}
82+
- {c: gcc, cpp: g++, v: 12, strict: OFF}
83+
- {c: gcc, cpp: g++, v: 13, strict: ON}
84+
- {c: clang, cpp: clang++, v: 13, strict: ON}
85+
- {c: clang, cpp: clang++, v: 14, strict: ON}
86+
- {c: clang, cpp: clang++, v: 15, strict: ON}
87+
- {c: clang, cpp: clang++, v: 16, strict: ON}
88+
- {c: clang, cpp: clang++, v: 17, strict: ON}
8989
defaults:
9090
run:
9191
shell: bash
9292
env:
9393
BUILD_DIR: ${{ github.workspace }}/build
9494
steps:
9595
- name: Checkout
96-
uses: actions/checkout@v3
96+
uses: actions/checkout@v4
9797
- name: List Workspace
9898
run: ls -la ${{ github.workspace }}
9999
- name: Install Clang (if needed)
@@ -102,20 +102,30 @@ jobs:
102102
with:
103103
version: "${{ matrix.compiler.v }}"
104104
env: true # set CC / CXX variable
105+
- name: Install GCC (if needed)
106+
# Installing GCC-13 due to regression introduced in ubuntu 22.04 image
107+
# https://github.com/actions/runner-images/issues/9866
108+
if: ${{ matrix.compiler.c == 'gcc' && matrix.compiler.v == 13 }}
109+
run: |
110+
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
111+
sudo apt-get update -y
112+
sudo apt-get install gcc-13
113+
sudo apt-get install g++-13
105114
- name: Set Compiler # only if CC / CXX are not already set from new installation
106115
run: |
107116
if [ -z "${CC}" ]; then
108117
echo "CC=${{matrix.compiler.c}}-${{matrix.compiler.v}}" >> "$GITHUB_ENV"
109118
echo "CXX=${{matrix.compiler.cpp}}-${{matrix.compiler.v}}" >> "$GITHUB_ENV"
119+
else
120+
echo CC=$CC
121+
echo CXX=$CXX
110122
fi
111-
echo CC=$CC
112-
echo CXX=$CXX
113123
- name: Compile
114124
run: |
115125
echo "== CMAKE VERSION =="
116126
cmake --version
117127
echo "== CMAKE CONFIGURE =="
118-
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_BUILD=true -DCLOVE_CMAKE__CPP_STRICT_WARN_AS_ERROR=${{matrix.compiler.strict}}
128+
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_BUILD=ON -DCLOVE_CMAKE__CPP_STRICT_WARN_AS_ERROR=${{matrix.compiler.strict}}
119129
echo "== CMAKE BUILD =="
120130
cmake --build ${{env.BUILD_DIR}} --config Release
121131
- name: List Build
@@ -135,15 +145,15 @@ jobs:
135145
BUILD_DIR: ${{ github.workspace }}/build
136146
steps:
137147
- name: Checkout
138-
uses: actions/checkout@v3
148+
uses: actions/checkout@v4
139149
- name: List Workspace
140150
run: ls -la ${{ github.workspace }}
141151
- name: Compile
142152
run: |
143153
echo "== CMAKE VERSION =="
144154
cmake --version
145155
echo "== CMAKE CONFIGURE =="
146-
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_SANITY=true
156+
cmake -B${{env.BUILD_DIR}} -DCLOVE_CMAKE__UC_SANITY=ON
147157
echo "== CMAKE BUILD =="
148158
cmake --build ${{env.BUILD_DIR}} --config Release
149159
- name: List Build

.github/workflows/release_action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212
- name: Upload Release Asset
1313
id: upload-release-asset
1414
uses: actions/upload-release-asset@v1

CMakeLists.txt

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,105 @@
11
cmake_minimum_required(VERSION 3.18)
2-
project(CLoveUnit LANGUAGES C)
3-
include(CTest)
42

5-
#[[
6-
add_subdirectory(tests/functs)
7-
if (DEFINED CLOVE_CMAKE__CI_TRIGGERED)
8-
add_subdirectory(tests/stricts/clove-c)
9-
add_subdirectory(tests/stricts/clove-cpp)
10-
add_subdirectory(examples/clove101)
11-
add_subdirectory(examples/clovepp)
12-
endif()
3+
set(CLOVE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
4+
list(INSERT CMAKE_MODULE_PATH 0 ${CLOVE_SOURCE_DIR}/cmake/modules)
135

14-
if (DEFINED CLOVE_CMAKE__ENABLE_PERFS)
15-
add_subdirectory(tests/perfs)
16-
endif()
17-
]]
6+
include(CLoveModules)
7+
clove_get_version(CLOVE_VERSION)
8+
9+
# Configure Project
10+
project(
11+
CLoveUnit
12+
VERSION ${CLOVE_VERSION}
13+
DESCRIPTION "Single-header Unit Testing framework for C (interoperable with C++) with test autodiscovery feature"
14+
HOMEPAGE_URL "https://github.com/fdefelici/clove-unit"
15+
LANGUAGES C
16+
)
17+
18+
include(GNUInstallDirs)
19+
include(CMakePackageConfigHelpers)
20+
21+
# Eventually CMAKE_INSTALL_PREFIX can be overridden by the user to change base installation path for the package
22+
clove_join_paths(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" clove-unit ${PROJECT_VERSION})
23+
24+
# Library Target definition and configuration
25+
add_library(clove-unit INTERFACE)
26+
add_library(clove-unit::clove-unit ALIAS clove-unit)
27+
28+
target_include_directories(
29+
clove-unit INTERFACE
30+
$<BUILD_INTERFACE:${CLOVE_SOURCE_DIR}>
31+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
32+
)
33+
34+
target_compile_features(clove-unit INTERFACE c_std_11)
35+
36+
# Install command stuffs for enabling find_package usage
37+
install(
38+
TARGETS clove-unit
39+
EXPORT clove-unit-targets
40+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
41+
)
1842

19-
if (CLOVE_CMAKE__UC_BUILD)
43+
write_basic_package_version_file(
44+
clove-unit-config-version.cmake
45+
VERSION ${PROJECT_VERSION}
46+
COMPATIBILITY AnyNewerVersion
47+
)
48+
49+
configure_package_config_file(
50+
${CLOVE_SOURCE_DIR}/cmake/in/clove-unit-config.cmake.in
51+
clove-unit-config.cmake
52+
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake
53+
)
54+
55+
install(
56+
FILES ${CLOVE_SOURCE_DIR}/clove-unit.h
57+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
58+
)
59+
60+
install(
61+
FILES
62+
${PROJECT_BINARY_DIR}/clove-unit-config.cmake
63+
${PROJECT_BINARY_DIR}/clove-unit-config-version.cmake
64+
DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake
65+
)
66+
67+
install(
68+
EXPORT clove-unit-targets
69+
#NAMESPACE clove-unit::
70+
DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake
71+
)
72+
73+
export(PACKAGE clove-unit)
74+
75+
76+
#[[
77+
In case this is the root project add dev targets (Development mode).
78+
To avoid targets pollution when using FetchContent were only the target library is required
79+
Note: PROJECT_IS_TOP_LEVEL cmake variable exists in version 3.21+
80+
]]
81+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
82+
include(CTest)
83+
84+
option(CLOVE_CMAKE__UC_BUILD "enable build use case" OFF)
85+
option(CLOVE_CMAKE__UC_SANITY "enable sanity check use case" OFF)
86+
option(CLOVE_CMAKE__UC_PERFS "enable performance test use case" OFF)
87+
option(CLOVE_CMAKE__CPP_STRICT_WARN_AS_ERROR "threat compilation warning as error" OFF)
88+
89+
if (CLOVE_CMAKE__UC_BUILD)
2090
add_subdirectory(tests/functs)
2191
add_subdirectory(tests/stricts/clove-c)
2292
add_subdirectory(tests/stricts/clove-cpp)
2393
add_subdirectory(examples/clove101)
2494
add_subdirectory(examples/clovepp)
25-
endif()
95+
endif()
2696

27-
if (CLOVE_CMAKE__UC_SANITY)
97+
if (CLOVE_CMAKE__UC_SANITY)
2898
add_subdirectory(tests/stricts/clove-sanity)
29-
endif()
99+
endif()
30100

31-
if (CLOVE_CMAKE__UC_PERFS)
101+
if (CLOVE_CMAKE__UC_PERFS)
32102
add_subdirectory(tests/perfs)
103+
endif()
104+
33105
endif()

README.md

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CLove-Unit &middot; [![version](https://img.shields.io/github/v/release/fdefelici/clove-unit?label=latest&sort=semver)](./clove-unit.h) [![workflow](https://img.shields.io/github/actions/workflow/status/fdefelici/clove-unit/ci_action.yml)](https://github.com/fdefelici/clove-unit/actions/workflows/ci_action.yml) [![conan](https://img.shields.io/badge/conan-available-blueviolet)](https://conan.io/center/recipes/clove-unit) [![Discord channel](https://img.shields.io/discord/1167864219190964255?logo=discord&logoColor=violet)](https://discord.gg/Mjx4YRQfFt)
1+
# CLove-Unit &middot; [![version](https://img.shields.io/github/v/release/fdefelici/clove-unit?label=latest&sort=semver)](./clove-unit.h) [![workflow](https://img.shields.io/github/actions/workflow/status/fdefelici/clove-unit/ci_action.yml)](https://github.com/fdefelici/clove-unit/actions/workflows/ci_action.yml) [![conan](https://img.shields.io/conan/v/clove-unit)](https://conan.io/center/recipes/clove-unit) [![Discord channel](https://img.shields.io/discord/1167864219190964255?logo=discord&logoColor=violet)](https://discord.gg/Mjx4YRQfFt)
22

33
`CLove-Unit` is a single-header unit testing library designed for C (compatible with C++).
44

@@ -19,7 +19,7 @@ Consider also supporting `CLove-Unit` development becoming a [**sponsor**](https
1919

2020
* [Features](#features)
2121
* [IDE Extensions](#ide-extensions)
22-
* [Supported Package Managers](#supported-package-managers)
22+
* [How to Integrate](#how-to-integrate)
2323
* [How It Works](#how-it-works)
2424
* [Getting Started](#getting-started)
2525
* [Programming API](#programming-api)
@@ -48,11 +48,88 @@ For those who prefer a UI oriented test executor, `CLove-Unit` is supported on t
4848

4949
Have a look and enjoy ;-)
5050

51-
## Supported Package Managers
51+
## How to Integrate
5252

53-
`CLove-Unit` is also available on the following Package Managers:
53+
`CLove-Unit` can be imported in your project in the following ways:
54+
- Sourcing the header file
55+
- Using a Package Manager
56+
- Using CMake
5457

55-
* [Conan](https://conan.io/center/recipes/clove-unit)
58+
### Sourcing the Header file
59+
Being an header-only library, you can just download [clove-unit.h](./clove-unit.h) file and include it in your project.
60+
61+
```c
62+
#include "clove-unit.h"
63+
```
64+
65+
Then remember to properly configure your compiler include paths.
66+
67+
### Using a Package Manager
68+
`CLove-Unit` is currently available on the following Package Managers:
69+
70+
* [Conan](https://conan.io): read [here](https://conan.io/center/recipes/clove-unit) for details on how to import it.
71+
72+
### Using CMake
73+
In case you still need dependency management, but you want to avoid Package Manager configuration complexity, you can use standard mechansim provided by `CMake` such as [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html), [add_subdirectory](https://cmake.org/cmake/help/latest/command/add_subdirectory.html) and [find_package](https://cmake.org/cmake/help/latest/command/find_package.html).
74+
75+
> NOTE: CMake library is named `clove-unit`
76+
77+
Here a few examples:
78+
79+
* **FetchContent**
80+
81+
```cmake
82+
cmake_minimum_required(VERSION 3.18)
83+
project(TestProject C)
84+
85+
Include(FetchContent)
86+
FetchContent_Declare(
87+
clove-unit
88+
GIT_REPOSITORY https://github.com/fdefelici/clove-unit.git
89+
GIT_TAG master # or eventually any branch, tag or commit sha
90+
)
91+
FetchContent_MakeAvailable(clove-unit)
92+
93+
add_executable(tests <YOUR_TEST_FILES>)
94+
target_link_libraries(tests clove-unit)
95+
```
96+
97+
* **add_subdirectory**
98+
99+
First download `CLove-Unit` repository and then point properly to it like this:
100+
101+
```cmake
102+
cmake_minimum_required(VERSION 3.18)
103+
project(TestProject C)
104+
105+
add_subdirectory(<PATH_TO_CLOVE_UNIT_REPOSITORY>)
106+
107+
add_executable(tests <YOUR_TEST_FILES>)
108+
target_link_libraries(tests clove-unit)
109+
```
110+
111+
* **find_package**
112+
113+
First download `CLove-Unit` repository and then run cmake install command on it.
114+
115+
Package will be installed in at following path: `<CMAKE_INSTALL_PREFIX>/clove-unit/<CLOVE_VERSION>`
116+
117+
Eventually you may want to customize [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) variable to override cmake default installation path for packages.
118+
119+
120+
Then use the package as follow:
121+
```cmake
122+
cmake_minimum_required(VERSION 3.18)
123+
project(TestProject C)
124+
125+
find_package(clove-unit REQUIRED PATHS <INSTALLATION_PATH>)
126+
127+
# or more strict
128+
# find_package(clove-unit <CLOVE_VERSION> EXACT REQUIRED PATHS <INSTALLATION_PATH>)
129+
130+
add_executable(tests <YOUR_TEST_FILES>)
131+
target_link_libraries(tests clove-unit)
132+
```
56133

57134
## How It Works
58135

@@ -236,10 +313,10 @@ Assertions that can be used within a `CLOVE_TEST` definition.
236313

237314
Helper APIs to support test implementation.
238315

239-
| API | Description |
240-
|--------------------------|------------------------------------------------------------|
241-
| `CLOVE_EXEC_PATH()` | Macro to easily retrieve executable path as a `char*` |
242-
| `CLOVE_EXEC_BASE_PATH()` | Macro to easily retrieve executable base path as a `char*` |
316+
| API | Description |
317+
|--------------------------|---------------------------------------------------------------------------|
318+
| `CLOVE_EXEC_PATH()` | Macro to easily retrieve executable absolute path as a `const char*` |
319+
| `CLOVE_EXEC_BASE_PATH()` | Macro to easily retrieve executable absolute base path as a `const char*` |
243320

244321
## Command-Line API
245322

0 commit comments

Comments
 (0)