Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake packaging fixes #6966

Merged
merged 5 commits into from
Aug 23, 2022
Merged

CMake packaging fixes #6966

merged 5 commits into from
Aug 23, 2022

Conversation

alexreinking
Copy link
Member

This PR makes a few fixes to our CMake package (as used by find_package).

  • The package now includes a hint as to the location of HalideHelpers, so that errors regarding not being able to find it are rarer (e.g. setting Halide_DIR instead of Halide_ROOT).
  • Halide_ASAN_ENABLED is added to the package to allow consumers to confirm that they found the right Halide when they are using ASAN in their own projects.
  • The handling of optional components was fixed. Previously, it incorrectly used the REQUIRED-ness of the whole Halide package itself, not the individual component.
    • PNG and JPEG dependencies are now optional by default. If any are missing, find_package(Halide REQUIRED) will still succeed. If you need a specific dependency for Halide::ImageIO, you can make it required by writing, e.g. find_package(Halide REQUIRED PNG).
  • Variables and macros that are internal to HalideConfig.cmake are now explicitly deleted with unset and a re-definition trick. This keeps our package API in line with what's documented.

These are automatically set by CMake after processing
HalideConfigVersion.cmake, so this code was totally pointless.
Before this change, users would either need to set Halide_ROOT to a
Halide installation path or add said path to CMAKE_PREFIX_PATH. If they
tried to use a different mechanism, like setting Halide_DIR or directly
annotating their find_package call with HINTS or PATHS, then it would
fail to find HalideHelpers.cmake.

Adding this hint inside HalideConfig.cmake makes the package more
robust, while still respecting the more powerful Halide_ROOT and
CMAKE_PREFIX_PATH variables.
Some of our package's internal variables and macros leak out into user
builds. We don't want users to use any of these. We might hit Hyrum's
Law here, but I hope not. Users of these variables and macros should
seek other means.
unset(Halide_static_targets)

# Delete internal macros -- CMake saves redefined macros and functions with a
# single underscore prefixed so, for example, Halide_fail is still available as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtaf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know! It's almost as crazy as foreach (i RANGE n) iterating over 0...n inclusive.

@alexreinking alexreinking merged commit 2f0957b into main Aug 23, 2022
@alexreinking alexreinking deleted the cmake/packaging-fixes branch August 23, 2022 19:38
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
* Add Halide_ASAN_ENABLED to package.
* Fix handling of optional components. Make PNG/JPEG optional.
* Make it easier to find HalideHelpers

Before this change, users would either need to set Halide_ROOT to a
Halide installation path or add said path to CMAKE_PREFIX_PATH. If they
tried to use a different mechanism, like setting Halide_DIR or directly
annotating their find_package call with HINTS or PATHS, then it would
fail to find HalideHelpers.cmake.

Adding this hint inside HalideConfig.cmake makes the package more
robust, while still respecting the more powerful Halide_ROOT and
CMAKE_PREFIX_PATH variables.

* Delete undocumented variables in HalideConfig

Some of our package's internal variables and macros leak out into user
builds. We don't want users to use any of these. We might hit Hyrum's
Law here, but I hope not. Users of these variables and macros should
seek other means.
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.

2 participants