Skip to content

Add CMake build script#77

Open
tamasmeszaros wants to merge 8 commits into
atomicobject:masterfrom
tamasmeszaros:tm_cmake
Open

Add CMake build script#77
tamasmeszaros wants to merge 8 commits into
atomicobject:masterfrom
tamasmeszaros:tm_cmake

Conversation

@tamasmeszaros

Copy link
Copy Markdown

Hello there! I'm sending this PR on behalf of the PrusaSlicer team. We are considering to use heatshrink in our software and put together a CMake build script which supports installing the library and exporting CMake config scripts for downstream projects to be able to find the installed library.

@BenBE

BenBE commented Jul 27, 2023

Copy link
Copy Markdown

@tamasmeszaros Mind to squash those two commits and add proper newlines at EOF?

@tamasmeszaros

tamasmeszaros commented Jul 27, 2023

Copy link
Copy Markdown
Author

@tamasmeszaros Mind to squash those two commits and add proper newlines at EOF?

Absolutely no. Thank you for considering merging the PR. Should I do it?

@BenBE

BenBE commented Jul 27, 2023

Copy link
Copy Markdown

@tamasmeszaros Mind to squash those two commits and add proper newlines at EOF?

Absolutely no. Thank you for considering merging the PR. Should I do it?

I'm not a maintainer of this repository; just happened to take a look at it because I'm using this library myself.

@artyom-poptsov

Copy link
Copy Markdown

Hello! It would be nice to have CMake file for the project indeed, as PrusaSlicer project already patches heatshrink to add CMake build script thus making a custom version of heatshrink. And that is very inconvenient for packagers.

I'm trying to package heatshrink along with the new version of PrusaSlicer for GNU Guix and the situation gives me additional bumps on the road. Please consider merging this pull request, maybe with incorporating some ideas from PrusaSlicer patches.

Thanks!

-avp

@artyom-poptsov

Copy link
Copy Markdown

Also unfortunately in Nix patch there are no tests in CMakeLists.txt.

@silentbicycle

Copy link
Copy Markdown
Collaborator

I'm not opposed to including that but I'm not deeply familiar with CMake -- would it be a problem to include it in a contrib/ subdirectory? To signal that it isn't the primary way to build the project, but provided as a convenience.

I've been horrendously busy with moving and work projects the last couple months, but should be coming up for air soon and plan to scoop up this and some other things in a new release.

Comment thread cmake/CMakeLists.txt Outdated
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# Add separate libraries for lib instances with static and dynamic memory allocation
add_library(${PROJECT_NAME} ${srcdir}/heatshrink_decoder.c ${srcdir}/heatshrink_encoder.c)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not have the suffix be explicit in both cases?

_noalloc vs. dynalloc?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The naming in the makefile is _static and _dynamic. I find this unfortunate due to potential confusion with static or shared libraries (dynamic linking). If the project is named heatshrink, I would kind of expect that it provides a library with the same name. But yes, then it's hard to know which memory allocation is the library without the suffix using. Maybe I could add an alias to one of them as the default and export that as well.

Maybe this duplicity could also be avoided by using some kind of allocator abstraction. But that is out of the scope for this PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Creating an alias sounds good.

Regarding abstracting the allocator: you'd need LTO for this to work properly and the two libs are a reasonable compromise. Also AFAIK there's some actual code differences in how the memory is used with the dynamic allocation, thus that's not something you could easily abstract away without compromising on the memory footprint.

@tamasmeszaros tamasmeszaros May 17, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually while I'm thinking about this library naming, I guess even if the naming is confusing to me, it might still be better to replicate the naming from the original Makefile. Because now, when you build with CMake you get differently named libraries installed compared to what the Makefile produces. It should not matter which build system was used to install the libraries, the result should be the same.

@tamasmeszaros

tamasmeszaros commented May 17, 2024

Copy link
Copy Markdown
Author

@silentbicycle Please note that the tests fail when building in Debug mode.
See this action run: https://github.com/tamasmeszaros/heatshrink/actions/runs/9120973451
Feel free to incorporate the workflow file into your repo, I will not make a separate PR for that,

@tamasmeszaros

Copy link
Copy Markdown
Author

I'm not opposed to including that but I'm not deeply familiar with CMake -- would it be a problem to include it in a contrib/ subdirectory? To signal that it isn't the primary way to build the project, but provided as a convenience.

I've been horrendously busy with moving and work projects the last couple months, but should be coming up for air soon and plan to scoop up this and some other things in a new release.

I've put the CMake stuff into cmake subdirectory. I actually forgot that you requested 'contrib' but I would not change it now it you are ok with 'cmake' subdir. I fully understand your perspective about CMake. It is unusual to not place the top level CMake file into the project root and will create confusion, but I think it is managable by any maintainer and is better than not having any CMake build.

Create aliases for CMake targets with better naming
Comment thread cmake/Config.cmake.in Outdated
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.

5 participants