Skip to content

Commit a36f64b

Browse files
committed
Add CMake workflows
1 parent 9091073 commit a36f64b

File tree

6 files changed

+325
-2
lines changed

6 files changed

+325
-2
lines changed

.github/workflows/cmake.yaml

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
name: CMake
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
name: ${{ matrix.preset }}-${{ matrix.config }}-${{ matrix.sanitize }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
preset: [linux-clang, linux-gcc, macos, windows]
12+
config: [Debug, Release]
13+
sanitize: [address, thread, undefined, leak, memory]
14+
exclude:
15+
- { preset: linux-gcc, sanitize: memory }
16+
- { preset: macos, sanitize: leak }
17+
- { preset: macos, sanitize: memory }
18+
- { preset: windows, sanitize: thread }
19+
- { preset: windows, sanitize: undefined }
20+
- { preset: windows, sanitize: leak }
21+
- { preset: windows, sanitize: memory }
22+
include:
23+
- preset: linux-clang
24+
os: ubuntu-latest
25+
generator: '"Ninja Multi-Config"'
26+
cc: clang
27+
cxx: clang++
28+
- preset: linux-gcc
29+
os: ubuntu-latest
30+
generator: '"Ninja Multi-Config"'
31+
cc: gcc
32+
cxx: g++
33+
- preset: macos
34+
os: macos-latest
35+
generator: Xcode
36+
- preset: windows
37+
os: windows-latest
38+
generator: '"Visual Studio 17 2022"'
39+
runs-on: ${{ matrix.os }}
40+
steps:
41+
- name: Prepare git before checkout
42+
run: git config --global core.autocrlf input
43+
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
47+
- name: Install dependencies on Linux
48+
if: runner.os == 'Linux'
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y ninja-build
52+
53+
- name: Set CMake caches
54+
run: |
55+
echo 'set(CMAKE_INSTALL_PREFIX install CACHE STRING "")' >> cache.cmake
56+
echo 'set(HTTPLIB_COMPILE ON CACHE STRING "")' >> cache.cmake
57+
echo 'set(HTTPLIB_TEST ON CACHE STRING "")' >> cache.cmake
58+
59+
- name: Set CMake caches for Linux
60+
if: runner.os == 'Linux'
61+
run: |
62+
echo 'set(CMAKE_C_COMPILER "${{ matrix.cc }}" CACHE STRING "")' >> cache.cmake
63+
echo 'set(CMAKE_CXX_COMPILER "${{ matrix.cxx }}" CACHE STRING "")' >> cache.cmake
64+
65+
- name: Print CMake caches
66+
run: cat cache.cmake
67+
68+
- name: Configure
69+
run: cmake -B build -G ${{ matrix.generator }} -C cache.cmake
70+
71+
- name: Build
72+
run: cmake --build build --config ${{ matrix.config }}
73+
74+
- name: Test
75+
id: test
76+
working-directory: build
77+
continue-on-error: true
78+
run: ctest -C ${{ matrix.config }} --timeout 100 --schedule-random --output-on-failure
79+
80+
- name: Rerun failed tests
81+
if: steps.test.outcome == 'failure'
82+
working-directory: build
83+
run: ctest -C ${{ matrix.config }} --timeout 100 --rerun-failed --output-on-failure
84+
85+
- name: Install
86+
run: cmake --install build --config ${{ matrix.config }}
87+
88+
build-mobile:
89+
name: ${{ matrix.preset }}-${{ matrix.config }}
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
preset: [android, ios]
94+
config: [Debug, Release]
95+
include:
96+
- preset: android
97+
os: ubuntu-latest
98+
generator: '"Ninja Multi-Config"'
99+
- preset: ios
100+
os: macos-latest
101+
generator: Xcode
102+
runs-on: ${{ matrix.os }}
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v4
106+
107+
- name: Install dependencies on Linux
108+
if: runner.os == 'Linux'
109+
run: |
110+
sudo apt-get update
111+
sudo apt-get install -y ninja-build
112+
113+
- name: Set CMake caches
114+
run: |
115+
echo 'set(CMAKE_INSTALL_PREFIX install CACHE STRING "")' >> cache.cmake
116+
echo 'set(HTTPLIB_COMPILE ON CACHE STRING "")' >> cache.cmake
117+
118+
- name: Set CMake caches for Android
119+
if: matrix.preset == 'android'
120+
run: |
121+
echo 'set(CMAKE_TOOLCHAIN_FILE $ENV{ANDROID_NDK}/build/cmake/android.toolchain.cmake CACHE STRING "")' >> cache.cmake
122+
123+
- name: Set CMake caches for iOS
124+
if: matrix.preset == 'ios'
125+
run: |
126+
echo 'set(CMAKE_SYSTEM_NAME iOS)' >> ios.toolchain.cmake
127+
echo 'set(CMAKE_SYSTEM_PROCESSOR aarch64)' >> ios.toolchain.cmake
128+
echo 'set(CMAKE_OSX_ARCHITECTURES arm64)' >> ios.toolchain.cmake
129+
echo 'set(CMAKE_OSX_SYSROOT iphoneos)' >> ios.toolchain.cmake
130+
echo 'set(CMAKE_TOOLCHAIN_FILE ios.toolchain.cmake CACHE STRING "")' >> cache.cmake
131+
132+
- name: Print CMake caches
133+
run: cat cache.cmake
134+
135+
- name: Configure
136+
run: cmake -B build -G ${{ matrix.generator }} -C cache.cmake
137+
138+
- name: Build
139+
run: cmake --build build --config ${{ matrix.config }}
140+
141+
- name: Install
142+
run: cmake --install build --config ${{ matrix.config }}
143+
144+
build-bsd:
145+
name: ${{ matrix.preset }}-${{ matrix.arch }}-${{ matrix.config }}
146+
strategy:
147+
fail-fast: false
148+
matrix:
149+
preset: [freebsd, netbsd, openbsd]
150+
arch: [arm64, x86_64]
151+
config: [Debug, Release]
152+
exclude:
153+
- { preset: netbsd, arch: arm64 }
154+
include:
155+
- preset: freebsd
156+
version: "13.2"
157+
install: sudo pkg install -y
158+
pkg: cmake ninja python3
159+
- preset: netbsd
160+
version: "9.3"
161+
install: sudo pkgin update && sudo pkgin -y install
162+
pkg: cmake ninja-build python310
163+
- preset: openbsd
164+
version: "7.4"
165+
install: sudo pkg_add -U
166+
pkg: cmake ninja python3
167+
runs-on: ubuntu-latest
168+
steps:
169+
- name: Checkout
170+
uses: actions/checkout@v4
171+
172+
- name: Run BSD workflows
173+
uses: cross-platform-actions/action@master
174+
with:
175+
operating_system: ${{ matrix.preset }}
176+
architecture: ${{ matrix.arch }}
177+
version: ${{ matrix.version }}
178+
shell: bash
179+
run: |
180+
${{ matrix.install }} ${{ matrix.pkg }}
181+
cmake -B build -G "Ninja Multi-Config" \
182+
-DCMAKE_INSTALL_PREFIX=install \
183+
-DHTTPLIB_COMPILE=ON \
184+
-DHTTPLIB_TEST=ON
185+
cmake --build build --config ${{ matrix.config }}
186+
cd build
187+
EXIT_CODE=0
188+
ctest -C ${{ matrix.config }} --timeout 100 --schedule-random --output-on-failure || EXIT_CODE=$?
189+
if [ $EXIT_CODE -ne 0 ]; then ctest -C ${{ matrix.config }} --timeout 100 --rerun-failed --output-on-failure; fi
190+
cd ..
191+
cmake --install build --config ${{ matrix.config }}
192+
193+
build-msys2:
194+
name: msys2-${{ matrix.preset }}-${{ matrix.config }}
195+
strategy:
196+
fail-fast: false
197+
matrix:
198+
preset: [CLANG32, CLANG64, MINGW32, MINGW64, UCRT64]
199+
config: [Debug, Release]
200+
runs-on: windows-latest
201+
defaults:
202+
run:
203+
shell: msys2 {0}
204+
steps:
205+
- name: Prepare git before checkout
206+
shell: powershell
207+
run: git config --global core.autocrlf input
208+
209+
- name: Checkout
210+
uses: actions/checkout@v4
211+
212+
- uses: msys2/setup-msys2@v2
213+
with:
214+
msystem: ${{ matrix.preset }}
215+
update: true
216+
pacboy: cmake:p gcc:p ninja:p
217+
218+
- name: Configure
219+
run: >
220+
cmake -B build -G "Ninja Multi-Config"
221+
-DCMAKE_INSTALL_PREFIX=install
222+
-DHTTPLIB_COMPILE=ON
223+
-DHTTPLIB_TEST=ON
224+
225+
- name: Build
226+
run: cmake --build build --config ${{ matrix.config }}
227+
228+
- name: Test
229+
id: test
230+
working-directory: build
231+
continue-on-error: true
232+
run: ctest -C ${{ matrix.config }} --timeout 100 --schedule-random --output-on-failure
233+
234+
- name: Rerun failed tests
235+
if: steps.test.outcome == 'failure'
236+
working-directory: build
237+
run: ctest -C ${{ matrix.config }} --timeout 100 --rerun-failed --output-on-failure
238+
239+
- name: Install
240+
run: cmake --install build --config ${{ matrix.config }}
241+
242+
build-cygwin:
243+
name: cygwin-${{ matrix.config }}
244+
strategy:
245+
fail-fast: false
246+
matrix:
247+
config: [Debug, Release]
248+
runs-on: windows-latest
249+
defaults:
250+
run:
251+
shell: C:\cygwin\bin\bash.exe --noprofile --norc -o igncr -eo pipefail '{0}'
252+
steps:
253+
- name: Prepare git before checkout
254+
shell: powershell
255+
run: git config --global core.autocrlf input
256+
257+
- name: Checkout
258+
uses: actions/checkout@v4
259+
260+
- name: Install dependencies
261+
uses: cygwin/cygwin-install-action@v4
262+
with:
263+
packages: cmake gcc-g++ ninja python3 libbrotli-devel libssl-devel zlib-devel
264+
265+
- name: Configure
266+
run: >
267+
cmake -B build -G "Ninja Multi-Config"
268+
-DCMAKE_INSTALL_PREFIX=install
269+
-DHTTPLIB_COMPILE=ON
270+
-DHTTPLIB_TEST=ON
271+
272+
- name: Build
273+
run: cmake --build build --config ${{ matrix.config }}
274+
275+
- name: Test
276+
id: test
277+
working-directory: build
278+
continue-on-error: true
279+
run: ctest -C ${{ matrix.config }} --timeout 100 --schedule-random --output-on-failure
280+
281+
- name: Rerun failed tests
282+
if: steps.test.outcome == 'failure'
283+
working-directory: build
284+
run: ctest -C ${{ matrix.config }} --timeout 100 --rerun-failed --output-on-failure
285+
286+
- name: Install
287+
run: cmake --install build --config ${{ matrix.config }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ ipch
4242
.*
4343
!/.gitattributes
4444
!/.travis.yml
45+
!.github

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ endif()
164164
# like CMAKE_INSTALL_INCLUDEDIR or CMAKE_INSTALL_DATADIR
165165
include(GNUInstallDirs)
166166

167+
if(MSVC)
168+
if("${HTTPLIB_SANITIZE}" STREQUAL "address")
169+
string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
170+
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
171+
add_compile_options(/fsanitize=address /Zi)
172+
add_link_options(
173+
/INCREMENTAL:NO
174+
$<$<CONFIG:Release>:/DEBUG>
175+
)
176+
endif()
177+
else()
178+
if(NOT "${HTTPLIB_SANITIZE}" STREQUAL "")
179+
add_compile_options(-g -fno-omit-frame-pointer)
180+
add_compile_options(-fsanitize=${HTTPLIB_SANITIZE})
181+
add_link_options(-fsanitize=${HTTPLIB_SANITIZE})
182+
endif()
183+
endif()
184+
167185
if(HTTPLIB_COMPILE)
168186
# Put the split script into the build dir
169187
configure_file(split.py "${CMAKE_CURRENT_BINARY_DIR}/split.py"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cpp-httplib
22
===========
33

4-
[![](https://github.com/yhirose/cpp-httplib/workflows/test/badge.svg)](https://github.com/yhirose/cpp-httplib/actions)
4+
[![test](https://github.com/yhirose/cpp-httplib/workflows/test/badge.svg)](https://github.com/yhirose/cpp-httplib/actions/workflows/test.yaml)
5+
[![CIFuzz](https://github.com/yhirose/cpp-httplib/actions/workflows/cifuzz.yaml/badge.svg)](https://github.com/yhirose/cpp-httplib/actions/workflows/cifuzz.yaml)
6+
[![CMake](https://github.com/yhirose/cpp-httplib/actions/workflows/cmake.yaml/badge.svg)](https://github.com/yhirose/cpp-httplib/actions/workflows/cmake.yaml)
57

68
A C++11 single-file header-only cross platform HTTP/HTTPS library.
79

test/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ find_package(CURL REQUIRED)
2929
add_executable(httplib-test test.cc)
3030
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>")
3131
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main CURL::libcurl)
32-
gtest_discover_tests(httplib-test)
32+
33+
if(MSVC)
34+
cmake_path(GET CMAKE_CXX_COMPILER PARENT_PATH VS_PATH)
35+
gtest_discover_tests(httplib-test
36+
PROPERTIES ENVIRONMENT PATH=${VS_PATH}
37+
)
38+
else()
39+
gtest_discover_tests(httplib-test)
40+
endif()
3341

3442
file(
3543
COPY www www2 www3 ca-bundle.crt image.jpg

test/fuzzing/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ add_test(
88
NAME httplib-test-fuzz
99
COMMAND httplib-test-fuzz ${HTTPLIB_CORPUS}
1010
)
11+
12+
if(MSVC)
13+
cmake_path(GET CMAKE_CXX_COMPILER PARENT_PATH VS_PATH)
14+
set_tests_properties(httplib-test-fuzz
15+
PROPERTIES ENVIRONMENT PATH=${VS_PATH}
16+
)
17+
endif()

0 commit comments

Comments
 (0)