premake-core icon indicating copy to clipboard operation
premake-core copied to clipboard

`os.findheader` support relative headerdirs

Open mercury233 opened this issue 9 months ago • 1 comments

What does this PR do?

Let os.findheader can support searching relative paths. Some libraries, by default, install header files within folders. For example, the header files for libfreetype-dev are located in: /usr/include/freetype2/freetype/*.h /usr/include/freetype2/ft2build.h

Previously, if a program included the header with #include <ft2build.h>, you had to use: os.findheader("freetype2/ft2build.h") .. "freetype2" to locate it.

Now you can simply use: os.findheader("ft2build.h", "freetype2") to achieve the same result.

How does this PR change Premake's behavior?

Nothing.

Anything else we should know?

Nothing.

Did you check all the boxes?

  • [x] Focus on a single fix or feature; remove any unrelated formatting or code changes
  • [x] Add unit tests showing fix or feature works; all tests pass
  • [x] Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • [x] Follow our coding conventions
  • [x] Minimize the number of commits
  • [x] Align documentation to your changes

You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!

mercury233 avatar May 17 '25 09:05 mercury233

How does this PR change Premake's behavior?

Nothing.

In fact behavior changes

os.findheader("header.h", "./submodules/library")

would no longer search from local directory.

Maybe creating another API would be cleaner, something like

function os.findheaderleaf(name, userpaths)
  local res = os.findheaderleaf(name, userpaths)
  if res then
    path.join(res, path.getdirectory(name))
  else
    return nil
  end
end

Jarod42 avatar May 23 '25 08:05 Jarod42