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 improvements when vendoring with FetchContent #267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jchv
Copy link

@jchv jchv commented Mar 9, 2024

This patch makes the following improvements to the CMake configuration:

  • If the target ZLIB::ZLIB already exists, find_package for zlib is not called: this is advantageous if the project that is vendoring libspng is also vendoring zlib, or has an alternate zlib implementation (like zlib-ng.) Otherwise, ugly hacks are needed to make the find_package a no-op (e.g.: introducing a FindZLIB.cmake module somewhere earlier in the search path that does this check and then calls the root module.)

  • It will now honor the SKIP_INSTALL_ALL, SKIP_INSTALL_HEADERS, and SKIP_INSTALL_LIBRARIES variables when setting up install targets. This is useful because zlib also honors this setting, and there's not much sense in installing libspng if it depends on vendored zlib which is not going to have install targets. (It causes an error, too.)

This should be fairly safe: when configuring standalone, this shouldn't change any of the existing behavior. For vendoring with FetchContent, I reckon this still shouldn't break any of the existing cases. This can help on Windows for a project that aims to compile out-of-the-box using Visual Studio without needing tooling like vcpkg, as zlib isn't present by default in this environment.

Fixes #266.

P.S.: Thanks for your work, by the way! libspng is a breath of fresh air.

This patch makes the following improvements to the CMake configuration:

- If the target ZLIB::ZLIB already exists, find_package for zlib is not
  called: this is advantageous if the project that is vendoring libspng
  is also vendoring zlib, or has an alternate zlib implementation (like
  zlib-ng.) Otherwise, ugly hacks are needed to make the find_package a
  no-op (e.g.: introducing a FindZLIB.cmake module somewhere earlier in
  the search path that does this check and then calls the root module.)

- It will now honor the `SKIP_INSTALL_ALL`, `SKIP_INSTALL_HEADERS`, and
  `SKIP_INSTALL_LIBRARIES` variables when setting up `install` targets.
  This is useful because zlib also honors this setting, and there's not
  much sense in installing libspng if it depends on vendored zlib which
  is not going to have install targets. (It causes an error, too.)

This should be fairly safe: when configuring standalone, this shouldn't
change any of the existing behavior. For vendoring with `FetchContent`,
I reckon this still shouldn't break any of the existing cases. This can
help on Windows for a project that aims to compile out-of-the-box using
Visual Studio without needing tooling like vcpkg, as zlib isn't present
by default in this environment.

Fixes randy408#266.
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.

Feature request: ability to disable CMake install targets
1 participant