Skip to content

cmake: propagate public header directory to target consumers - #240

Open
fhgffy wants to merge 1 commit into
fukuchi:masterfrom
fhgffy:fix-cmake-target-includes
Open

fhgffy wants to merge 1 commit into
fukuchi:masterfrom
fhgffy:fix-cmake-target-includes

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 5, 2026

Copy link
Copy Markdown

A parent project using add_subdirectory(libqrencode) and target_link_libraries(app qrencode) cannot include <qrencode.h> without adding libqrencode's source directory manually. The library builds, but the consumer fails with fatal error: qrencode.h: No such file or directory. This affects both static and shared builds.

Attach the public header directory to qrencode as a build-tree interface include directory. Add a CMake consumer regression that includes the public header, links only the library target, encodes a string, and frees the result. Include its source in Automake's EXTRA_DIST so source distributions retain the CMake test.

The existing tests mostly include the header using a relative path and therefore do not catch this missing target usage requirement. Subdirectory use was previously supported by #133.

Validation on Linux with GCC 14.2.0, CMake 3.11.2 and 3.31.6:

  • Static and shared parent consumers fail before the fix and build/run afterward; the new regression also fails when the production change is removed
  • Direct and transitive target consumers pass, including paths containing spaces
  • Original CTest suite: 12/12 pass; fixed static Debug and shared Release suites: 13/13 pass each
  • Installed-header/library consumers and the PNG-disabled CLI still build and run

The patch received an independent review and a fresh replay of all 48 validation commands with CMake 3.31.6. Windows, macOS, CMake 3.1, PNG-enabled tools, and Autotools make dist were not run locally. CMake 4's existing minimum-version configuration failure affects both base and fixed code and remains separate in #235.

Prepared with AI assistance.

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