You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CMake support would be wonderful for cross-platform support. It would allow easy integration into existing cross-platform projects.
Reacted by Giacomo Pozzoni, Jean-Michaël Celerier, lysu, Egor Pugin, David Hirvonen, Sergey Kostyaev, Wilfried Goesgens, DesWurstes, Gareth Andrew Lloyd, Stanislav Denisov and 13 more
I build internally with CMake but there are 3 Windows specific places which can be fixed/augumented. However, I do not have other platforms handy to make it gneric.
I'm open to switching over to CMake, but it's way down my list of things to do right now. If someone besides me is passionate about converting all the portability logic in configure.ac and making the new build system function reliably on at least Linux, FreeBSD, OS X, and Windows, I'm willing to do my part to learn more about CMake and help maintain it as the sole build system.
+1 I think a good idea would be to issue a fairly generic CMake and then a few people could take a platform each and fix it up. That would parallelize the effort and would not tax a specific individual trying to support everything that is in configure.ac, This is a high bar to get something out that might benefit people immediatly.
However, that would require a short transition period where CMake file would exist in parallel with the existing system. If @jasone would soften his stand on having 4 platform support at the first iteration, although those 4 may become available almost immediately due to the nature of CMake.
I'm fine with an iterative approach to CMake transition, but I don't want to do a release with both build systems. Incremental changes (and refactoring diffs that touch files outside the new CMake-related files) need to be self-contained so that we can cherry-pick around them for bugfix releases, and leave them out entirely if the effort isn't complete in time for the 4.2.0 release.
Re: 4.2.0 release date, pretty much all of the features we're currently considering are non-trivial, and it's likely to be at least a couple months before we have enough functionality to justify release.
I was going to suggest perhaps another repository under this organization so that those of who are interested in contributing might be able to do so more easily? @photex mentioned already having started on Linux and OSX. I can work on Windows and would be willing to setup virtual machines to work on the more obscure platforms if it helps to get the change adopted.
git clone [email protected]:jemalloc/jemalloc-cmake.git
git remote add -m dev upstream https://github.com/jemalloc/jemalloc.git
git pull upstream dev
git push origin master
It looks like you will manually need to add the remote to your cloned repo so that you can merge the upstream into the jemalloc-cmake repo master branch from time to time.
@leezu
I just tried your cmake-2019 branch for building jemalloc on Windows using Visual Studio.
I had to make some changes to make it configure and partially compile, but not fully.
DetectOSFeatures fails to detect the Windows platform.
During build, the final step failed because nm and awk are generally not available on Windows.
The warning that is shown during this failure is also awkward.
Because ${CMAKE_NM} is empty, cmake thinks -a is the name of the application.
Also, because JEMALLOC_AWK_EXEC is undefined, JEMALLOC_AWK_EXEC-NOTFOUND is shown in the log.
The configure step should fail when these 2 variables are undefined.
But better, the default configuration options should be that it just works.
I would like to suggest some additional changes:
Add support for install.
Make use of cmake targets. So no global include_directories or add_definitions.
This also allows the install step to install cmake scripts that export these cmake targets.
No use of linux specific utilities. The current sln project can build jemalloc on Windows, so I don't see why cmake cannot. cmake has a script mode which might be useful.
Wrap all calls to option and store the decsription, value and default in a list(s). This allows cmake to print a summary at the end of configuration. SDL2 does something similar.
CI for Windows, as well as Linux and Macos (using appveyor and travis-ci)?
Patch to get things going on Visual Studio 2017
These changes are just hacks to get things working. I did not use the proper cmake variables.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 49d5439c..693c667a 100644
--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -16,6 +16,9 @@ include(${PROJECT_SOURCE_DIR}/build-aux/DetectCompilerFeatures.cmake) # 2
# Tell CMake where to find default headers:
include_directories(${PROJECT_SOURCE_DIR}/include)
+if(MSVC)+ include_directories(${PROJECT_SOURCE_DIR}/include/msvc_compat)+endif()
# Also tell CMake where to find out-of-source generated headers:
include_directories(${PROJECT_BINARY_DIR}/include)
diff --git a/build-aux/DetectCompilerFeatures.cmake b/build-aux/DetectCompilerFeatures.cmake
index d764428c..822a271b 100644
--- a/build-aux/DetectCompilerFeatures.cmake+++ b/build-aux/DetectCompilerFeatures.cmake@@ -151,7 +151,7 @@ int main(void) {
mach_absolute_time();
return 0;
}" JEMALLOC_HAVE_MACH_ABSOLUTE_TIME)
-+set(CMAKE_REQUIRED_INCLUDES "${PROJECT_SOURCE_DIR}/include/msvc_compat")
check_c_source_runs("
#include <assert.h>
#include <strings.h>
@@ -166,13 +166,14 @@ if(HAS_BUILTIN_FFSL)
set(JEMALLOC_INTERNAL_FFSL __builtin_ffsl)
set(JEMALLOC_INTERNAL_FFS __builtin_ffs)
else()
+ set(CMAKE_REQUIRED_INCLUDES "${PROJECT_SOURCE_DIR}/include/msvc_compat")
check_c_source_runs("
#include <assert.h>
#include <strings.h>
int main() {
int rv = ffsl(0x08);
assert(rv == 4);
- return 0);+ return 0;
}" HAS_FFSL)
if(HAS_FFSL)
diff --git a/build-aux/DetectOSFeatures.cmake b/build-aux/DetectOSFeatures.cmake
index 523db5ff..de0a5911 100644
--- a/build-aux/DetectOSFeatures.cmake+++ b/build-aux/DetectOSFeatures.cmake@@ -76,8 +76,7 @@ else()
endif()
# Only run check if we haven't run it before
-if(CMAKE_SYSTEM_PROCESSOR MATCHES "i686" OR- CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")+if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i686|x86_64|AMD64)")
check_c_source_compiles("
int main(void) {
__asm__ volatile(\"pause\");
@@ -118,7 +117,7 @@ endif()
if(NOT LG_VADDR)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") # maybe "arm64" too?
set(LG_VADDR 48)
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|AMD64)")
GetSystemAddrBits(LG_VADDR)
# Cache result so we don't run the check every time
set(LG_VADDR ${LG_VADDR} CACHE INTERNAL "System Address Bits")
diff --git a/build-aux/GetSystemSizes.cmake b/build-aux/GetSystemSizes.cmake
index 0baf3296..35d3a924 100644
--- a/build-aux/GetSystemSizes.cmake+++ b/build-aux/GetSystemSizes.cmake@@ -41,7 +41,7 @@ int main() {
SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buffer = 0;
GetSystemInfo(&si);
- result = si.dwSizes;+ result = si.dwPageSize;
#else
result = sysconf(_SC_PAGESIZE);
#endif
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a3cceb4d..bd3d56f0 100644
--- a/src/CMakeLists.txt+++ b/src/CMakeLists.txt@@ -59,7 +59,7 @@ if(NOT JEMALLOC_CXX_DISABLE)
# C++14 support exists, so add C++ file and configure C++ options
list(APPEND JEMALLOC_CMAKE_SOURCES
jemalloc_cpp.cpp)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g3 -O3")+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g3 -O3")
endif()
if(enable_valgrind)
@@ -75,7 +75,7 @@ find_program(JEMALLOC_AWK_EXEC awk)
function(ExtractSymbolsGenerateNamespaceHeader target top-target symExt awk dir hdr)
# Don't compile -syms with optimization so it builds faster.
# The target is only for symbol extraction so we don't care about performance.
-target_compile_options(${target} PRIVATE "-O0")+# target_compile_options(${target} PRIVATE "-O0")
target_compile_definitions(${target} PRIVATE
JEMALLOC_NO_PRIVATE_NAMESPACE
_GNU_SOURCE)
diff --git a/src/jemalloc_cpp.cpp b/src/jemalloc_cpp.cpp
index da0441a7..01abe32d 100644
--- a/src/jemalloc_cpp.cpp+++ b/src/jemalloc_cpp.cpp@@ -67,7 +67,7 @@ handleOOM(std::size_t size, bool nothrow) {
}
if (ptr == nullptr && !nothrow)
- std::__throw_bad_alloc();+ std::bad_alloc();
return ptr;
}
These changes can be summed up as:
include include/msvc_compat as well when using the MSVC compiler
when calling check_c_source_compiles and check_c_source_runs, set CMAKE_REQUIRED_*variables. I suggest wrapping these functions.
CMAKE_SYSTEM_PROCESSOR is AMD64 on Windows using MSVC
2 bugs in C code (embedded in cmake)
not adding gcc/clang options to CMAKE_{LANG}_FLAGS
std::__throw_bad_alloc in src/jemalloc_cpp.cpp is not defined in MSVC2017.
What is the status on this? I would like to start using CMake with jemalloc as automake is just hopeless to work with. Thanks for your hard work so far!
I've been actively working on converting to a cmake-based build for the past week or so. I think I've already got plans for most of the things that have the potential to cause problems.
How to configure with cmake to get rid of the 'je_' prefix?
The library generated by autoconf has:
$nm ./lib/libjemalloc.so | grep -w malloc
000000000000d740 T malloc
The library generated by cmake has:
nm ./build/src/libjemalloc.so | grep -w je_malloc
00000000000551d0 T je_malloc
OK, too bad. I'm the build/cmake guy at mysql, and I was able to integrate your stuff into our cmake code. I gave up though, when I realized the jemalloc C codebase is gcc-only, will not compile with Visual Studio.
@davidtgoldblatt Any progress there? I think I can give some help.
Since there are some issues about using the latest autoconf, microsoft/vcpkg#22627 was blocked.
Activity
rustyx commentedon Feb 26, 2016
+1. Not to mention CMake is much more BSD-friendly license-wise.
yuslepukhin commentedon Feb 26, 2016
I build internally with CMake but there are 3 Windows specific places which can be fixed/augumented. However, I do not have other platforms handy to make it gneric.
jasone commentedon Feb 27, 2016
I'm open to switching over to CMake, but it's way down my list of things to do right now. If someone besides me is passionate about converting all the portability logic in
configure.acand making the new build system function reliably on at least Linux, FreeBSD, OS X, and Windows, I'm willing to do my part to learn more about CMake and help maintain it as the sole build system.wbierman commentedon Feb 29, 2016
Is there an overview of the different build environments jemalloc currently supports? I might be willing to undertake this.
jasone commentedon Feb 29, 2016
@wbierman, most of the supported platforms are enumerated in
configure.ac.photex commentedon Feb 29, 2016
+1 I just started to work on this for Linux and OSX. :)
yuslepukhin commentedon Feb 29, 2016
+1 I think a good idea would be to issue a fairly generic CMake and then a few people could take a platform each and fix it up. That would parallelize the effort and would not tax a specific individual trying to support everything that is in configure.ac, This is a high bar to get something out that might benefit people immediatly.
However, that would require a short transition period where CMake file would exist in parallel with the existing system. If @jasone would soften his stand on having 4 platform support at the first iteration, although those 4 may become available almost immediately due to the nature of CMake.
jasone commentedon Feb 29, 2016
I'm fine with an iterative approach to CMake transition, but I don't want to do a release with both build systems. Incremental changes (and refactoring diffs that touch files outside the new CMake-related files) need to be self-contained so that we can cherry-pick around them for bugfix releases, and leave them out entirely if the effort isn't complete in time for the 4.2.0 release.
Re: 4.2.0 release date, pretty much all of the features we're currently considering are non-trivial, and it's likely to be at least a couple months before we have enough functionality to justify release.
rustyx commentedon Feb 29, 2016
Sounds like a good candidate for a feature branch.
jasone commentedon Feb 29, 2016
Good idea.
wbierman commentedon Feb 29, 2016
I was going to suggest perhaps another repository under this organization so that those of who are interested in contributing might be able to do so more easily? @photex mentioned already having started on Linux and OSX. I can work on Windows and would be willing to setup virtual machines to work on the more obscure platforms if it helps to get the change adopted.
yuslepukhin commentedon Feb 29, 2016
@wbierman I can share my Windows CMake build as a starting point or just as a reference if there interest.
wbierman commentedon Feb 29, 2016
Sounds good to me.
@jasone would you be willing to create a 'jemalloc-cmake' repository and add myself, @yuslepukhin, @rustyx, @photex to it?
jasone commentedon Feb 29, 2016
Okay, https://github.com/jemalloc/jemalloc-cmake is set up. GitHub doesn't directly support forks within the same project, so I had to do the following to create the repo:
It looks like you will manually need to add the remote to your cloned repo so that you can merge the upstream into the jemalloc-cmake repo master branch from time to time.
58 remaining items
Add 3rdparty/jemalloc
Add 3rdparty/jemalloc
Add 3rdparty/jemalloc
madebr commentedon Feb 4, 2020
@leezu
I just tried your
cmake-2019branch for building jemalloc on Windows using Visual Studio.I had to make some changes to make it configure and partially compile, but not fully.
DetectOSFeaturesfails to detect theWindowsplatform.During build, the final step failed because
nmandawkare generally not available on Windows.The warning that is shown during this failure is also awkward.
Because
${CMAKE_NM}is empty, cmake thinks-ais the name of the application.Also, because
JEMALLOC_AWK_EXECis undefined,JEMALLOC_AWK_EXEC-NOTFOUNDis shown in the log.The configure step should fail when these 2 variables are undefined.
But better, the default configuration options should be that it just works.
I would like to suggest some additional changes:
include_directoriesoradd_definitions.This also allows the install step to install cmake scripts that export these cmake targets.
optionand store the decsription, value and default in a list(s). This allows cmake to print a summary at the end of configuration. SDL2 does something similar.Patch to get things going on Visual Studio 2017
These changes are just hacks to get things working. I did not use the proper cmake variables.
These changes can be summed up as:
include/msvc_compatas well when using the MSVC compilercheck_c_source_compilesandcheck_c_source_runs, setCMAKE_REQUIRED_*variables. I suggest wrapping these functions.CMAKE_SYSTEM_PROCESSORisAMD64on Windows using MSVCCMAKE_{LANG}_FLAGSstd::__throw_bad_allocinsrc/jemalloc_cpp.cppis not defined in MSVC2017.Great work!!
leezu commentedon Feb 4, 2020
@madebr I only did a very small modification to @mattsta's work to verify a special use-case. @mattsta is driving this work and may be able to help.
Add 3rdparty/jemalloc
Add 3rdparty/jemalloc
curoky commentedon Jun 6, 2020
@leezu It seems that some files was included twice.
Perhaps, we can directly delete the second
APPENDin judgment for CMAKE_BUILD_TYPE.fwsGonzo commentedon Jun 27, 2020
What is the status on this? I would like to start using CMake with jemalloc as automake is just hopeless to work with. Thanks for your hard work so far!
davidtgoldblatt commentedon Jun 27, 2020
I've been actively working on converting to a cmake-based build for the past week or so. I think I've already got plans for most of the things that have the potential to cause problems.
fwsGonzo commentedon Jun 27, 2020
Have you tried using it as a library in another project? I would have liked to be able to use
add_subdirectory(jemalloc). :) 👍tormardi commentedon May 18, 2021
How to configure with cmake to get rid of the 'je_' prefix?
The library generated by autoconf has:
$nm ./lib/libjemalloc.so | grep -w malloc
000000000000d740 T malloc
The library generated by cmake has:
nm ./build/src/libjemalloc.so | grep -w je_malloc
00000000000551d0 T je_malloc
jackpoz commentedon Jul 18, 2021
It would be nice to see this feature merged but after 6 years my hopes are diminishing
tormardi commentedon Aug 12, 2021
OK, too bad. I'm the build/cmake guy at mysql, and I was able to integrate your stuff into our cmake code. I gave up though, when I realized the jemalloc C codebase is gcc-only, will not compile with Visual Studio.
JackBoosY commentedon Mar 4, 2022
@davidtgoldblatt Any progress there? I think I can give some help.
Since there are some issues about using the latest autoconf, microsoft/vcpkg#22627 was blocked.