Skip to content

Make include-what-you-use mandatory for all example builds #114

Description

@thomasnemer

Problem

Currently, include-what-you-use (iwyu) is only enforced for the main Prong library (CMakeLists.txt:110), but not for any of the example applications. This creates an inconsistency where:

  • The library code must pass iwyu checks (good!)
  • Example code can have incorrect/excessive includes without triggering errors (bad!)

According to CLAUDE.md:265, we should "NEVER bypass iwyu or clang-format". While clang-format is properly enforced for all examples via the format-example-sources target, iwyu is missing.

Current State

What has iwyu:

  • prong library target (via CXX_INCLUDE_WHAT_YOU_USE property)

What lacks iwyu:

  • prong_demo_app executable
  • All 8 basic examples (examples/basic/*/)
  • All 4 intermediate examples (examples/intermediate/*/)
  • All 4 advanced examples (examples/advanced/*/)
  • glfw_adapters library

Why This Matters

  1. Example code quality: Examples are learning resources and should demonstrate best practices
  2. Include hygiene: Examples may accumulate unnecessary includes that slow compilation
  3. Consistency: All code in the repository should follow the same standards
  4. Documentation: Examples with incorrect includes can mislead users

Proposed Solution

Add the CXX_INCLUDE_WHAT_YOU_USE property to:

  1. All example executables in individual CMakeLists.txt files
  2. The glfw_adapters library
  3. The prong_demo_app executable

Example configuration:

set_target_properties(01_hello_button PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples/basic/01_hello_button"
    CXX_INCLUDE_WHAT_YOU_USE "${IWYU_PATH};-Xiwyu;--error;-Xiwyu;--verbose=3"
)

Affected Files

  • examples/CMakeLists.txt (demo app + glfw_adapters)
  • examples/basic/*/CMakeLists.txt (8 files)
  • examples/intermediate/*/CMakeLists.txt (4 files)
  • examples/advanced/*/CMakeLists.txt (4 files)

Total: 18 CMakeLists.txt files need updating

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions