Skip to content

Commit a6ff50a

Browse files
authored
Merge pull request #19 from avalentino/feature/ci
Setup CI with GitHub Actions
2 parents b5005dc + 26aaefb commit a6ff50a

2 files changed

Lines changed: 104 additions & 4 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: CMake on multiple platforms
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [ "master" ]
7+
8+
jobs:
9+
build:
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
# Set fail-fast to false to ensure that feedback is delivered for all
14+
# matrix combinations. Consider changing this to true when your
15+
# workflow is stable.
16+
fail-fast: false
17+
18+
# Set up a matrix to run the following 3 configurations:
19+
# 1. <Windows, Release, latest MSVC compiler toolchain on the default
20+
# runner image, default generator>
21+
# 2. <Linux, Release, latest GCC compiler toolchain on the default
22+
# runner image, default generator>
23+
# 3. <Linux, Release, latest Clang compiler toolchain on the default
24+
# runner image, default generator>
25+
#
26+
# To add more build types (Release, Debug, RelWithDebInfo, etc.)
27+
# customize the build_type list.
28+
matrix:
29+
os: [ubuntu-latest, windows-latest]
30+
build_type: [Release]
31+
c_compiler: [gcc, clang, cl]
32+
include:
33+
- os: windows-latest
34+
c_compiler: cl
35+
cpp_compiler: cl
36+
build_tests: OFF
37+
- os: ubuntu-latest
38+
c_compiler: gcc
39+
cpp_compiler: g++
40+
build_tests: ON
41+
- os: ubuntu-latest
42+
c_compiler: clang
43+
cpp_compiler: clang++
44+
build_tests: ON
45+
exclude:
46+
- os: windows-latest
47+
c_compiler: gcc
48+
- os: windows-latest
49+
c_compiler: clang
50+
- os: ubuntu-latest
51+
c_compiler: cl
52+
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: Set reusable strings
57+
# Turn repeated input strings (such as the build output directory)
58+
# into step outputs.
59+
# These step outputs can be used throughout the workflow file.
60+
id: strings
61+
shell: bash
62+
run: |
63+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
64+
65+
- name: Configure CMake
66+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only
67+
# required if you are using a single-configuration generator such as make.
68+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
69+
run: >
70+
cmake -B ${{ steps.strings.outputs.build-output-dir }}
71+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
72+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
73+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
74+
-DBUILD_DOCS=ON
75+
-DBUILD_TESTS=${{ matrix.build_tests }}
76+
-S ${{ github.workspace }}
77+
78+
- name: Build
79+
# Build your program with the given configuration. Note that --config
80+
# is needed because the default Windows generator is a multi-config
81+
# generator (Visual Studio generator).
82+
run: >
83+
cmake
84+
--build ${{ steps.strings.outputs.build-output-dir }}
85+
--config ${{ matrix.build_type }}
86+
87+
- name: Test
88+
if: ${{ matrix.build_tests == 'ON' }}
89+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
90+
# Execute tests defined by the CMake configuration.
91+
# Note that --build-config is needed because the default Windows
92+
# generator is a multi-config generator (Visual Studio generator).
93+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html
94+
# for more detail
95+
run: ctest --build-config ${{ matrix.build_type }}
96+

src/test/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ target_link_libraries(epr_performance_test epr_api)
99
add_executable(epr_test_endian epr_test_endian.c)
1010
target_link_libraries(epr_test_endian epr_api)
1111

12+
if(NOT MSVC)
13+
set(EXTRALIBS "m")
14+
endif(NOT MSVC)
15+
1216
# the following test programs use some internal function that is not exported
1317
# by the shared library
1418
if(BUILD_STATIC_LIB)
1519
add_executable(epr_main_test epr_main_test.c)
16-
target_link_libraries(epr_main_test epr_api_static bccunit m)
20+
target_link_libraries(epr_main_test epr_api_static bccunit ${EXTRALIBS})
1721

1822
add_executable(api_unit_tests api_unit_tests.c)
19-
target_link_libraries(api_unit_tests epr_api_static m)
23+
target_link_libraries(api_unit_tests epr_api_static ${EXTRALIBS})
2024
elseif(BUILD_STATIC_LIB)
2125
add_executable(epr_main_test epr_main_test.c ${SOURCES})
22-
target_link_libraries(epr_main_test bccunit m)
26+
target_link_libraries(epr_main_test bccunit ${EXTRALIBS})
2327

2428
add_executable(api_unit_tests api_unit_tests.c ${SOURCES})
25-
target_link_libraries(api_unit_tests m)
29+
target_link_libraries(api_unit_tests ${EXTRALIBS})
2630
endif(BUILD_STATIC_LIB)
2731

2832

0 commit comments

Comments
 (0)