Skip to content

Conversation

@sbmueller
Copy link
Contributor

@sbmueller sbmueller commented Oct 15, 2025

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)
  1. 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 toolchains

@sbmueller sbmueller requested a review from a team as a code owner October 15, 2025 12:55
@sonarqubecloud
Copy link

Copy link

@martin4861 martin4861 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Thanks for fixing!

Copy link

@jakalm jakalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sbmueller sbmueller merged commit d5558e3 into master Oct 15, 2025
2 checks passed
@sbmueller sbmueller deleted the smuller/fix-check branch October 15, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants