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

blosc/CMakeLists.txt: Update Lz4 handling #386

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

johnwparent
Copy link

@johnwparent johnwparent commented Oct 10, 2024

Lz4 is capable of vendoring its own CMake config module, which is considered preferable over vendored find modules according to CMake best practices.

This patch adds support for importing an LZ4 install detected via its CMake Config module by searching for the targets imported via that module. It then updates the link interface for cblosc static and shared variants to link to their respective LZ4 libraries (or whichever is available).

Lz4 is capable of vendoring its own CMake config
module, which is considerd preferable over vendored
find modules according to CMake best practices.

This patch adds support for importing an LZ4 install
detected via its CMake Config module by searching
for the targets imported via that module.
It then updates the link interface for cblosc
static and shared variants to link to their
respective LZ4 libraries (or whichevere is available)
set(LIBS ${LIBS} ${STATIC_LIBS})
endif()
elseif(NOT SHARED_LIBS AND NOT STATIC_LIBS)
# Fallback to cblosc vendored find module
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the vendored case handled below, after else(LZ4_FOUND)?

Copy link
Author

Choose a reason for hiding this comment

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

That's the case where you vendor LZ4 in its entirety, this handles the case where the c-blosc vendored find module for LZ4 is used instead of LZ4's config module.

Copy link
Author

Choose a reason for hiding this comment

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

Different components being vendored, I had hoped the "vendored find module" would be clear enough, but evidently it was not, my apologies.

Copy link
Contributor

@kalvdans kalvdans Oct 10, 2024

Choose a reason for hiding this comment

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

I'm not familiar with libraries providing cmake snippets, i only heard about pkg-config. I'll let someone more familiar with Cmake review. To me, the "genex" code is unreadable and gives vibes of the xz backdoor...

Copy link
Author

Choose a reason for hiding this comment

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

CMake's Config modules are an integral part of a healthy CMake ecosystem, it allows you to export your project in a way that allows consumers to use your project exactly as you intend.

The doc

Copy link
Author

Choose a reason for hiding this comment

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

I did just notice a mistake in the generator expressions, but that doesn't mean they're a vulnerability...

Copy link
Author

Choose a reason for hiding this comment

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

Which is now fixed, forgot to refactor the code from my test project.

@FrancescAlted
Copy link
Member

Thanks @johnwparent . This contribution seems legitimate to me, but it is going well beyond my knowledge (CMake requires a lot of attention to understand its full capabilities). Besides, I don't fully understand the purpose of this one. But if @kalvdans is fine with it, I'm +1 on merging this.

@johnwparent
Copy link
Author

This contribution seems legitimate to me
Thanks!

Besides, I don't fully understand the purpose of this one.

c-blosc has its own find module for the purposes to detecting lz4 on the filesystem, and then incorporating the lz4 artifacts into its own CMake. This works (clearly), however CMake best practices suggest that whenever possible, a config module should be preferred. In general, it is typically better to let a project define its own export interface and subsequent usage requirements.

Lz4 support producing this config module, so it would be ideal to allow c-blosc to utilize it, however because c-blosc's CMake is setup in a way that it expects the results of find_package(lz4) to have been the result of its vendored "find module", it is unable to actually use the results of lz4's config module appropriately, which results in the call to find_package succeeding, and c-blosc attempting to build, and then failing when it cannot find lz4's headers or libraries.

In short, the purpose is to enable compatibility with lz4's config module, while still maintaining the ability to use the vendored find module.

Basically the CMake here checks for the target that would be imported by Lz4's config module, and if it's available (i.e. find_package found the config module and used that to provide lz4 instead of c-blosc's find module), integrates those targets into the existing build logic.
Lz4 can build both shared and static at once (much like c-blosc) so much of the logic here is simply detecting which type of Lz4's binaries is available (if not both) and incorporating correctly into the c-blosc compile and link interface.

The generator expressions look complex, but perform a very simple task. They check for the type of the library the expression is being evaluated in the context of (in this case, either cblosc_shared or cblosc_static), and yield the correct type of lz4 binary depending on the type of the c-blosc library.

@kalvdans
Copy link
Contributor

while still maintaining the ability to use the vendored find module.

Will the code gets smaller if we drop support for the old way of finding the module?

@johnwparent
Copy link
Author

Will the code gets smaller if we drop support for the old way of finding the module?

Technically yes, but you'll lose that functionality, which is still fairly relevant. LZ4 can be built with makefiles or by CMake, so while the CMake derived builds of lz4 can work with this config approach, the makefile based builds cannot. I'd recommend keeping the old find module until Lz4 drops their makefile support.

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.

3 participants