Commit d5558e3
authored
Fix compiler errors from check third-party dependency on Windows (#188)
# Issue
The check unit testing framework (used as a third-party dependency)
emits compiler diagnostics that break the build on Windows platforms,
even though it's configured as an external dependency with
`SYSTEM_INCLUDES`.
Specific error:
```
D:\a\libsbp\libsbp\c\third_party\check\lib\timer_delete.c:48:5: error: implicit declaration of function 'alarm' [-Wimplicit-function-declaration]
```
# Root Cause
The check library has platform compatibility issues on Windows:
1. Missing POSIX functions: Windows lacks POSIX functions like alarm(),
setitimer(), and proper timer support
2. Incomplete fallback detection: While check includes compatibility
shims (e.g., alarm.c), the file timer_delete.c calls alarm() directly
without proper header inclusion or declaration checking
3. SYSTEM_INCLUDES limitation: The SYSTEM_INCLUDES flag in CMake only
suppresses warnings from headers consumed via
target_include_directories(). However, check adds its compatibility
source files (including timer_delete.c) directly to the target via
target_sources(), so these files are compiled as part of the target
itself and inherit all parent compile flags including -Werror
Note: The check project has been unmaintained for over 4 years (last
release: 0.15.2 in 2020), making an upstream fix unlikely.
# Solution
Modified cmake/common/FindCheck.cmake to temporarily adjust
CMAKE_C_FLAGS during the check library's configuration and compilation:
1. Save original flags before including the dependency
2. Apply platform-specific suppressions:
- MinGW/GCC: Remove -Werror and add
-Wno-error=implicit-function-declaration
- MSVC: Remove /WX and add /wd4013 (disables C4013: implicit function
declaration)
3. Restore original flags immediately after the dependency is added
This approach:
- ✅ Doesn't modify third-party code
- ✅ Only affects check library compilation
- ✅ Preserves strict warnings for project code
- ✅ Supports both MinGW and MSVC toolchains1 parent 1ab487a commit d5558e3
1 file changed
+22
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
16 | 34 | | |
17 | 35 | | |
18 | 36 | | |
19 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments