-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix and improve jemalloc releated cmake #52
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,14 @@ set(DEP_LIBS_PKG_ARG_LISTS "IpcShm ${DEP_IPC_SHM_VERSION} CONFIG") | |
# (TODO: but look into the jemalloc/jemalloc-cmake GitHub repo -- what's that all about?) | ||
# Hence we must ensure 2 things more manually: the lib location and the include-path. | ||
|
||
# Try pkg-config if available | ||
pkg_check_modules(JEMALLOC REQUIRED jemalloc) | ||
if(JEMALLOC_FOUND) | ||
set(JEMALLOC_LIB "${JEMALLOC_LIBRARIES}") | ||
set(JEMALLOC_INCLUDE_PATH "${JEMALLOC_INCLUDEDIR}") | ||
Comment on lines
+60
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these lines set them as CACHE variables? I ask, because find_library() and find_path() do so (unless one sets NO_CACHE, which I did not). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am not sure, they are just aliases to avoid more modifications. Personally I recommend use https://cmake.org/cmake/help/latest/module/FindPkgConfig.html#command:pkg_check_modules says that |
||
unset(JEMALLOC_PREFIX CACHE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary? If they specified this prefix manually for some unholy reason (and we do advertise this), maybe we should let them? (I have the vague feeling CMake's philosophy on cache variables isn't totally clear... at least I couldn't glean it when I tried... like this value could be a wrongly-computed value from a previous run, in which case who knows what we should do - but presumably worst-case user can just clear cache and start over....) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant just the unset() line there... not the 3 preceding that. Apologies for being confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://cmake.org/cmake/help/latest/module/FindPkgConfig.html#command:pkg_check_modules says that a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, got it. There's quite a bit going on. I can surely improve this based on stuff you've taught me (plus subsequent experiments). Like I don't need to introduce more cache variables if some would already be set with the pkg... stuff... and clearly I should differentiate in naming between prefix as in path prefix, versus prefix as in the API name prefix (which is super duper important here). And probably more boring subtleties like that. The time to fix it up is now, before (god willing) all kinds of users start using mr Flow-IPC. So, not ready to go yet, but I'm optimistic. 👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A different name like I think some "save/restore" actions might help here, with proper explaining comments: Save user specified Be bold and do it! Changes are never too late. 👍🏻👍🏻👍🏻 |
||
endif() | ||
|
||
# Firstly: Finding the (static) library. This approach is recommended by FlowLikeLib.cmake docs. | ||
if(NOT JEMALLOC_LIB) | ||
block() | ||
|
@@ -131,9 +139,10 @@ function(jemalloc_config_run) | |
OUTPUT_VARIABLE output | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
COMMAND_ERROR_IS_FATAL ANY) | ||
string(REGEX REPLACE ".*--with-jemalloc-prefix=([^ ]*).*" "\\1" JEMALLOC_PREFIX ${output}) | ||
if(${JEMALLOC_PREFIX} STREQUAL "") | ||
set(${JEMALLOC_PREFIX} "${NONE}") | ||
string(REGEX MATCH "--with-jemalloc-prefix=[^ ]*" JEMALLOC_PREFIX "${output}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this... it seems like clearly an improvement/defensive in nature, at the very least. Again for my own education I ask how you came across the desire to do this. Is it that if one builds jemalloc without explicitly setting this prefix thing to blank when configuring it, then the jemalloc-config output will omit --with-jemalloc-prefix= entirely? (That may or may not be related to a certain problem someone found when setting the prefix to . But don't worry about that... my thing to track down. Bottom line is you may have fixed here the problem they found-- I am just not sure yet.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes! Distros using RPM (Fedora and OpenSUSE) ship Distros using DEB (Debian and Ubuntu) ship On Debian, I built Actually |
||
string(REPLACE "--with-jemalloc-prefix=" "" JEMALLOC_PREFIX "${JEMALLOC_PREFIX}") | ||
if("${JEMALLOC_PREFIX}" STREQUAL "") | ||
set(JEMALLOC_PREFIX "${NONE}") | ||
endif() | ||
|
||
# "Fun" quirk of CMake: a cache setting can't be straightforwardly modified from within a function. | ||
|
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.
There are a few related things going on possibly outside the issues you were trying to (and succeeding to) fix/improve, so I might make a new PR after looking into everything. I omit details here to avoid extra confusion. Anyway I shall look into that soon but probably not right this second.
Even before then, let me put some comments/questions here, before I forget. Your answers (if any) will serve to at least educate me. (Undoubtedly I am a CMake noob; in fact I learned it, to the extent that I did, for this project.)
--
if(NOT JEMALLOC_LIB)
? To the extent that this is better than find_library() and all that, perhaps it should be attempted a bit below, and if it fails then go on to my find_library() stuff?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.
Agree. This shoubld be within
if(NOT JEMALLOC_LIB)
.Personally I perfer the following logic:
find_package()
to find corresponding elements.find_package(PkgConfig)
and the followingpkg_check_modules()
(which drivespkgconf
or oldpkg-config
) to find corresponding elements.find_library()
andfind_path()
and set corresponding elements.Usually
find_package()
is the approach recommended by CMake, but regrettablyjemalloc
does not provided files used byfind_package()
.jemalloc.pc
is provided and much more cleaner than usingfind_library()
andfind_path()
directly.