Skip to content

Commit fab1981

Browse files
Test all stds in different jobs (#56)
* Set copyright * Allow std override * Use one target, multiple jobs * Test with 11 and 17 * Upgrade runners * Upgrade codecov * Parallel builds * Add cpp_channel_coverage cmake option * Uppercase cmake option * Add CPP_CHANNEL_SANITIZERS cmake option
1 parent 2e1b9e8 commit fab1981

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

.github/workflows/cmake.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,39 @@ jobs:
2929
matrix:
3030
config:
3131
- {
32-
name: "Ubuntu Latest GCC (Release)",
33-
os: ubuntu-latest,
34-
build_type: "Release",
32+
name: "Ubuntu 24.04 GCC, C++11 (Debug)",
33+
os: ubuntu-24.04,
34+
build_type: "Debug",
35+
std: "11",
36+
sanitizers: "ON",
3537
}
3638
- {
37-
name: "Ubuntu 22.04 GCC (Debug)",
38-
os: ubuntu-22.04,
39+
name: "Ubuntu Latest GCC, C++17 (Debug)",
40+
os: ubuntu-latest,
3941
build_type: "Debug",
42+
std: "17",
43+
sanitizers: "OFF",
44+
}
45+
- {
46+
name: "Ubuntu Latest GCC, C++11 (Release)",
47+
os: ubuntu-latest,
48+
build_type: "Release",
49+
std: "11",
50+
sanitizers: "OFF",
4051
}
4152
- {
42-
name: "macOS Latest Clang (Release)",
53+
name: "macOS Latest Clang, C++11 (Release)",
4354
os: macos-latest,
4455
build_type: "Release",
56+
std: "11",
57+
sanitizers: "OFF",
4558
}
4659
- {
47-
name: "Windows Latest (Release)",
60+
name: "Windows Latest, C++11 (Release)",
4861
os: windows-latest,
4962
build_type: "Release",
63+
std: "11",
64+
sanitizers: "OFF",
5065
}
5166

5267
steps:
@@ -57,19 +72,19 @@ jobs:
5772

5873
- name: Configure CMake
5974
working-directory: ${{github.workspace}}/build
60-
run: cmake ${{ github.workspace }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -Dcpp_channel_build_examples=ON -Dcpp_channel_build_tests=ON
75+
run: cmake ${{ github.workspace }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DCMAKE_CXX_STANDARD=${{ matrix.config.std }} -DCPP_CHANNEL_BUILD_EXAMPLES=ON -DCPP_CHANNEL_BUILD_TESTS=ON -DCPP_CHANNEL_SANITIZERS=${{ matrix.config.sanitizers }}
6176

6277
- name: Build
6378
working-directory: ${{github.workspace}}/build
64-
run: cmake --build . --config ${{ matrix.config.build_type }} --target tests
79+
run: cmake --build . --config ${{ matrix.config.build_type }} --target tests -j
6580

6681
- name: Test
6782
working-directory: ${{github.workspace}}/build
68-
run: ctest -C ${{ matrix.config.build_type }} --verbose -R channel_test*
83+
run: ctest -C ${{ matrix.config.build_type }} --verbose -R channel_test --output-on-failure -j
6984

7085
- name: Run examples
7186
working-directory: ${{github.workspace}}/build
72-
run: cmake --build . --config ${{ matrix.config.build_type }} --target examples
87+
run: cmake --build . --config ${{ matrix.config.build_type }} --target examples -j
7388

7489
coverage:
7590
name: Coverage
@@ -83,18 +98,18 @@ jobs:
8398

8499
- name: Configure CMake
85100
working-directory: ${{github.workspace}}/build
86-
run: cmake ${{ github.workspace }} -DCMAKE_BUILD_TYPE=Debug -Dcpp_channel_build_tests=ON
101+
run: cmake ${{ github.workspace }} -DCMAKE_BUILD_TYPE=Debug -DCPP_CHANNEL_BUILD_TESTS=ON -DCPP_CHANNEL_COVERAGE=ON
87102

88103
- name: Build
89104
working-directory: ${{github.workspace}}/build
90105
run: cmake --build . --config Debug --target tests
91106

92107
- name: Test
93108
working-directory: ${{github.workspace}}/build
94-
run: ctest -C Debug --verbose -R channel_test11
109+
run: ctest -C Debug --verbose -R channel_test
95110

96111
- name: Upload coverage reports to Codecov
97-
uses: codecov/codecov-action@v4.0.1
112+
uses: codecov/codecov-action@v5
98113
with:
99114
token: ${{ secrets.CODECOV_TOKEN }}
100115

.vscode/settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"cmake.configureArgs": [
3-
"-Dcpp_channel_build_examples=ON",
4-
"-Dcpp_channel_build_tests=ON"
3+
"-DCPP_CHANNEL_BUILD_EXAMPLES=ON",
4+
"-DCPP_CHANNEL_BUILD_TESTS=ON",
5+
"-DCPP_CHANNEL_COVERAGE=ON",
6+
"-DCPP_CHANNEL_SANITIZERS=ON",
7+
"-DCMAKE_CXX_STANDARD=11"
58
],
69
"clang-tidy.fixOnSave": false,
710
"clang-tidy.lintOnSave": false,

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
22
project(cpp_channel)
33
set(PROJECT_VERSION 0.8.3)
44

5-
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard")
66
set(CMAKE_CXX_STANDARD_REQUIRED YES)
77
set(CXX_EXTENSIONS NO)
88

@@ -14,14 +14,16 @@ include_directories(include)
1414
add_library(msd_channel INTERFACE)
1515
target_include_directories(msd_channel INTERFACE include)
1616

17-
option(cpp_channel_build_tests "Build all of cpp_channel's own tests." OFF)
18-
option(cpp_channel_build_examples "Build cpp_channel's example programs." OFF)
17+
option(CPP_CHANNEL_BUILD_TESTS "Build all of cpp_channel's own tests." OFF)
18+
option(CPP_CHANNEL_BUILD_EXAMPLES "Build cpp_channel's example programs." OFF)
19+
option(CPP_CHANNEL_COVERAGE "Generate test coverage." OFF)
20+
option(CPP_CHANNEL_SANITIZERS "Build with sanitizers." OFF)
1921

20-
if (cpp_channel_build_tests)
22+
if (CPP_CHANNEL_BUILD_TESTS)
2123
enable_testing()
2224
add_subdirectory(tests)
2325
endif()
2426

25-
if (cpp_channel_build_examples)
27+
if (CPP_CHANNEL_BUILD_EXAMPLES)
2628
add_subdirectory(examples)
2729
endif()

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2023 Andrei Avram
1+
Copyright (c) 2020-2025 Andrei Avram
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
THE SOFTWARE.
19+
THE SOFTWARE.

tests/CMakeLists.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ function(package_add_test TESTNAME)
2323
set_target_warnings(${TESTNAME} PRIVATE)
2424
target_link_libraries(${TESTNAME} gtest gtest_main)
2525

26-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
27-
target_link_libraries(${TESTNAME} -lgcov -lubsan)
28-
target_compile_options(${TESTNAME} PRIVATE --coverage -fsanitize=undefined)
26+
if (CPP_CHANNEL_COVERAGE)
27+
target_link_libraries(${TESTNAME} -lgcov)
28+
target_compile_options(${TESTNAME} PRIVATE --coverage)
29+
endif ()
30+
31+
if (CPP_CHANNEL_SANITIZERS)
32+
target_link_libraries(${TESTNAME} -lubsan)
33+
target_compile_options(${TESTNAME} PRIVATE -fsanitize=undefined)
2934
endif ()
3035

3136
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME})
@@ -36,17 +41,11 @@ endfunction()
3641
add_custom_target(tests)
3742

3843
# Tests
39-
package_add_test(channel_test11 channel_test.cpp blocking_iterator_test.cpp)
40-
package_add_test(channel_test14 channel_test.cpp blocking_iterator_test.cpp)
41-
package_add_test(channel_test17 channel_test.cpp blocking_iterator_test.cpp)
42-
43-
set_target_properties(channel_test14 PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES)
44-
set_target_properties(channel_test17 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
44+
package_add_test(channel_test channel_test.cpp blocking_iterator_test.cpp)
4545

4646
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
4747
# Disable warnings about C++17 extensions
48-
target_compile_options(channel_test11 PRIVATE -Wno-c++17-extensions)
49-
target_compile_options(channel_test14 PRIVATE -Wno-c++17-extensions)
48+
target_compile_options(channel_test PRIVATE -Wno-c++17-extensions)
5049
endif()
5150

5251
# Benchmark

0 commit comments

Comments
 (0)