Skip to content

cmake: allow C-only builds when tests are disabled - #449

Open
fhgffy wants to merge 1 commit into
PJK:masterfrom
fhgffy:fix/c-only-build
Open

fhgffy wants to merge 1 commit into
PJK:masterfrom
fhgffy:fix/c-only-build

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 5, 2026

Copy link
Copy Markdown

Description

The library and ordinary examples are C, but project(... LANGUAGES C CXX) requires a working C++ compiler even with WITH_TESTS=OFF. For example, configuration fails on master with:

cmake -S . -B build-c-only -DWITH_TESTS=OFF \
  -DCMAKE_CXX_COMPILER=/nonexistent/cxx

Enable CXX only for the optional test suite or CMake older than 3.12. The older-CMake exception preserves the existing minimum version: GenerateExportHeader gained C-project support in CMake 3.12.

Add a standalone regression project that forces an unavailable C++ compiler, builds libcbor and its examples, checks that CXX was not enabled, and runs the existing C linkage consumer. Run it from the existing CircleCI linkage-test command. Document the C++ requirement and add a changelog entry.

Validation

Tested on Linux with GCC/G++ 14.2.0:

  • The new regression fails against the unmodified base for the unavailable C++ compiler and passes with the fix on CMake 3.31.6 and 4.0.3
  • Static and shared C-only builds, examples, and installed CMake consumers pass
  • All 29 upstream tests pass on the base, fixed static build, and fixed shared build; both C++ linkage controls pass
  • Ordinary builds with CMake 3.11.2 still pass with C++ available, using explicit C99 to avoid an unrelated old-CMake/GCC-14 standard-detection mismatch
  • The exact added CircleCI command passes locally, including paths containing spaces
  • Independent review and a fresh offline replay of the final patch pass

CMake 3.5, exact 3.12, Windows/macOS, sanitizers, documentation generation, lint tools, and the full CI matrix were not run locally.

Checklist

  • Contribution guidance reviewed
  • Regression test added
  • Documentation updated
  • CHANGELOG updated without changing the version

No public API or runtime C implementation changes, new platform-specific code, or intended security/performance changes.

Developed with AI assistance; the patch was independently reviewed and tested locally.

This branch has not been deployed

No deployments
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.

1 participant