◐ Shell
clean mode source ↗

feat: Ordered search paths for `-I`, `-isystem`, `-F`, `-iframework` + Darwin framework support (with legacy `-I` back-compat) by jcfr · Pull Request #511 · cppcheck-opensource/simplecpp

@jcfr jcfr mentioned this pull request

Aug 26, 2025

@jcfr jcfr mentioned this pull request

Aug 28, 2025

@jcfr jcfr changed the title Add Apple Framework header support for __has_include and #include feat: Add Darwin-style framework search with ordered path lookup

Aug 29, 2025

danmar

@jcfr jcfr changed the title feat: Add Darwin-style framework search with ordered path lookup feat: Ordered search paths for -I, -isystem, -F, -iframework + Darwin framework support (with legacy -I back-compat)

Aug 30, 2025

jcfr and others added 5 commits

August 30, 2025 15:30
…th lookup

This change teaches simplecpp to resolve headers from Apple-style Framework
directories while preserving the left-to-right order of interleaved
-I/-F/-iframework search paths (like GCC/Clang on Darwin).

This enables both:
- `__has_include(<Pkg/Hdr.h>)` -> `<Pkg.framework/Headers/Hdr.h>` (or `PrivateHeaders`)
- `#include <Pkg/Hdr.h>`       -> same framework layout when a package prefix exists

Changes:
- Add `DUI::SearchPath` with `PathKind {Include, Framework, SystemFramework}`.
- If `DUI::searchPaths` is non-empty, use it verbatim (interleaved -I/-F/-iframework).
  Otherwise preserve back-compat by mirroring `includePaths` as Include paths.
- Update `openHeader()` to consult typed paths, and only rewrite `<Pkg/Hdr.h>`
  to `Pkg.framework/{Headers,PrivateHeaders}/Hdr.h` when a package prefix exists.
- Implement `toAppleFrameworkRelatives()` returning prioritized candidates
  (Headers first, then PrivateHeaders).
- Tests use `PathKind::Framework` when checking framework layout.

CLI
- Support -F<dir> and -iframework<dir> (keep -I as before).

Behavior notes
- The order of -I/-F/-iframework is preserved exactly as provided.
- `Framework` vs `SystemFramework` differ only in diagnostic semantics (not lookup).
- Legacy users who only set `DUI::includePaths` see identical behavior.

Tests
- Add `appleFrameworkHasIncludeTest` for `__has_include` resolution.
- Add `appleFrameworkIncludeTest` for `#include` resolution.
- Add dummy fixture: `testsuite/Foundation.framework/Headers/Foundation.h`.

This brings simplecpp closer to GCC/Clang behavior on macOS and enables
robust resolution of framework headers like `Foundation/Foundation.h`.

Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
Co-authored-by: Hans Johnson <hans-johnson@uiowa.edu>
Suggested-by: glankk <glankk@users.noreply.github.com>
This change introduces support for the -isystem flag, allowing users to
specify system include directories. The addition includes handling the
new flag in both the argument parsing and include resolution logic,
as well as updating relevant tests to validate the new functionality.
This improves test coverage by ensuring that DUI::addIncludePath is
tested with both legacy mode on and off. It adds new test functions
for each scenario and updates the test cases accordingly.
This changes the default value of the 'legacy' parameter in the
DUI::addIncludePath method to false. Since this API was just introduced,
it is preferred to use the new capabilities by preserving the left-to-right
order.

@jcfr jcfr mentioned this pull request

Aug 30, 2025

@jcfr jcfr mentioned this pull request

Sep 18, 2025

danmar