-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
base: main
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
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. |
Lz4 support producing this config module, so it would be ideal to allow 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 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 |
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. |
How do I test this? I installed liblz4-dev (which on Debian doesn't seem to ship with any cmake config module) and it was detected when I passed Could you @johnwparent please give me some instructions of 1) a dev package that contains the cmake config module, and 2) cmake options that will build a static blosc and 3) dynamically linked blosc. Sorry to ask so much, given your very long description above, but since we don't have any other cmake expert around you'll have to spoonfeed me... |
That's the case that necessitates preserving the find module mechanism in the codebase, as you asked about here.
Happy to. I'm actually making this contribution on behalf of the Spack package manager, so Spack installing lz4 is one option. You can also build lz4 from source via it's CMake build system following the instructions in that repo (the only thing you really need to specify on the command line is the preference for shared, static, or both types of artifacts) and install it. Both options will provide an lz4 w/ CMake config to test with. So for an lz4 from source build your command line would look something like: This is the line I use to build Lz4. For c-blosc: The Specifying no preference for static vs shared when giving CMake arguments to blosc will build both at once.
No worries, happy to do what needs to be done to help this land! |
I gave it a shot but can't see any CMake module among the installed files. Maybe I did something wrong:
|
A little more progress:
Still haven't reproduced any build errors caused by header files not found. Also a bit confused why we the need to differentiate lz4_static and lz4_shared as the |
No you did everything correctly (and thanks for trying Spack!). I do Spack's Windows support, so this is my fault for forgetting other platforms build LZ4 differently by default. Spack will prefer building LZ4 with autotools everywhere but Windows, but you can make it use cmake by specifying That said, installing from source worked, which is great.
Awesome! Thanks for being so diligent in trying to test my changes!
Hmm, the uppercase iteration worked for me with a patched lz4, but that wasn't from main, so perhaps there's a naming change. I'll look into a resolution for that as that will need to be addressed for the changes here to be useful.
I dug into this a bit more, and the issue I reported initially has two origins, both of which contribute. The first issue is LZ4's CMake config did not actually export their include interface (they have since patched it, but it only exists on their main branch, no releases incorporate that change, and I was working off their most recent release), Obviously this is not your problem (nor is it lz4's any longer since they've fixed it LOL), but that is likely why you did not observe any failures. The second issue is that without my changes, even if lz4's CMake config was perfect, if c-blosc were to use the lz4 config module, the variables c-blosc's CMake expects to provide the include directories, normally set by
Another two part answer. One, this approach better models/reflects the state and availability of lz4's binaries we're trying to bring in here, and allows CMake to resolve the correct library as needed. Adding any library to the |
In case you're curious this pipeline is the failure that inspired the creation of this PR. |
Thanks a lot for explaining things in much detail! I totally forgot windows, which is usually the main reason projects switches to CMake 🤦 I think it is prettier to fix the vendored Findlz4.cmake (needs to be lowercase to work on Linux) to do the same thing as Lz4's CMake config files. It seems you can make find_package() try config mode first, and then module mode, by set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE). Would it be possible? Then we move all complexity to the vendored Findlz4.cmake (that we could drop as more and more distros bundle cmake files with lz4). I have access to a windows machine at work so I can try out the change there. |
Perhaps we could drop the usecase of a external lz4 package that lacks cmake config, and only support 1) bundled lz4 sources or 2) external lz4 package with cmake config. |
Apologies for my very delayed response, hectic week.
Happens all the time,
Agreed, wasn't sure if you folks were meeting particular use case with your vendored copy. I'll re-do the PR to synchronize your vendored find module with Lz4's config.
Yup! That's actually how I discovered this issue. I'm trying to improve Spack's sandboxing of its builds against system pollution and in doing so, mandated that variable for all our CMake builds and encountered this failure (among numerous others 😓 )
Some of the complexity (static vs shared) will have to remain outside of the find module (it's not the responsibility of the find module to determine useage). I'd still leave the choice of
great!
I think this would be a good step once the majority of package managers are vendoring an lz4 with the CMake config. For now, it seems like apt, yum, and zypper all vendor the non CMake version, so I don't think making those versions undetectable is a good idea. |
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).