From c12b5de6bed826322cd6e1b233a0b0f333c266b0 Mon Sep 17 00:00:00 2001 From: JackBoosY Date: Tue, 14 Jun 2022 02:07:24 -0700 Subject: [PATCH 1/2] Support non-Windows configure and build --- CMakeLists.txt | 1 + Utilities.cmake | 33 +++++++++++++++------------------ src/jemalloc.c | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06e83ef1..9244e1d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -491,6 +491,7 @@ if(NOT WIN32) set(JEMALLOC_HAVE_SYSCALL 1) endif() + include(CheckFunctionExists) CHECK_FUNCTION_EXISTS(secure_getenv HAVE_SECURE_GETENV) if(HAVE_SECURE_GETENV) set(JEMALLOC_HAVE_SECURE_GETENV 1) diff --git a/Utilities.cmake b/Utilities.cmake index 8fe8bb47..1ab2dc46 100644 --- a/Utilities.cmake +++ b/Utilities.cmake @@ -628,17 +628,6 @@ function (ConfigureFile file_path output_path ExpandDefine) # Use Powershell to convert autoconf file to a cmake conf file # and see if that fixes the issue of line continuations and ; in the file # PS Snipper -file(TO_NATIVE_PATH "${file_path}" ntv_file_path) - -# This converts #undefs into #cmakedefines so configure_file can handle it -set(PS_CMD -"Get-Content \"${ntv_file_path}\" | -ForEach { -if($_ -match '^#undef[ \t]*[^ \t]*') - { $_ -replace '^#undef[ \t]*([^ \t]*)','#cmakedefine $1 @$1@' } else {$_} -} | -Set-Content \"${ntv_file_path}.cmake\"" -) if(EXISTS ${file_path}) if(NOT ${ExpandDefine}) @@ -646,17 +635,16 @@ if(EXISTS ${file_path}) else() file(REMOVE ${file_path}.cmake) # Convert autoconf .in into a cmake .in - execute_process(COMMAND powershell -Command "${PS_CMD}" - RESULT_VARIABLE error_level - ERROR_VARIABLE error_output) - - if(NOT ${error_level} EQUAL 0) - message(FATAL_ERROR "Powershell completed with ${error_level} : ${error_output}") - endif() + file(RELATIVE_PATH ntv_file_relative_path "${CMAKE_SOURCE_DIR}" "${file_path}") + file(READ "${file_path}" NTV_FILE_CONTENT) + string(REGEX REPLACE "#( *)undef +([^ ][^\n]+)\n" "#\\1cmakedefine \\2 @\\2@ \n" NTV_FILE_CONTENT "${NTV_FILE_CONTENT}") + file(WRITE "${CMAKE_BINARY_DIR}/${ntv_file_relative_path}" "${NTV_FILE_CONTENT}") + configure_file(${CMAKE_BINARY_DIR}/${ntv_file_relative_path} ${output_path} @ONLY NEWLINE_STYLE WIN32) configure_file(${file_path}.cmake ${output_path} @ONLY NEWLINE_STYLE WIN32) file(REMOVE ${file_path}.cmake) endif() + include_directories("${CMAKE_SOURCE_DIR}/include") else() message(FATAL_ERROR "${file_path} not found") endif() @@ -728,9 +716,14 @@ set(SRC "${WORK_FOLDER}/getpagesize.c") set(COMPILE_OUTPUT_FILE "${WORK_FOLDER}/getpagesize.log") file(WRITE ${SRC} +"#ifdef _WIN32\n" "#include \n" "#include \n" +"#else\n" +"#include \n" +"#endif\n" "int main(int argc, const char** argv) {\n" +"#ifdef _WIN32\n" "int result;\n" "#ifdef _WIN32\n" "SYSTEM_INFO si;\n" @@ -740,6 +733,9 @@ file(WRITE ${SRC} "result = sysconf(_SC_PAGESIZE);\n" "#endif\n" "printf(\"%d\", result);\n" +"#else\n" +"printf(\"page size = %d\\n\", getpagesize());\n" +"#endif\n" "return 0;\n" "}\n" ) @@ -776,6 +772,7 @@ function(JeCflagsAppend cflags APPEND_TO_VAR RESULT_VAR) # Combine the result to try set(TFLAGS "${${APPEND_TO_VAR}} ${cflags}") + include(CheckCCompilerFlag) CHECK_C_COMPILER_FLAG(${TFLAGS} status) if(status) diff --git a/src/jemalloc.c b/src/jemalloc.c index 38650ff0..2b8c545d 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -988,7 +988,7 @@ malloc_conf_init(void) int saved_errno = errno; const char *linkname = # ifdef JEMALLOC_PREFIX - "/etc/"JEMALLOC_PREFIX"malloc.conf" + "/etc/JEMALLOC_PREFIXmalloc.conf" # else "/etc/malloc.conf" # endif From ed113de2a748a10a46bc717e575472aeb9797516 Mon Sep 17 00:00:00 2001 From: JackBoosY Date: Tue, 14 Jun 2022 20:09:09 -0700 Subject: [PATCH 2/2] sync changes to fix OSX build --- CMakeLists.txt | 5 +++-- Utilities.cmake | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9244e1d9..07d33c4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ option(enable-lazy-lock "Enable lazy locking (only lock when multi-threaded" OFF option(force_lazy_lock "Forcing lazy-lock to avoid allocator/threading bootstrap issues" OFF) # install_prefix - installation directory prefix # with-xslroot= XSL stylesheet root path +option(disable-zone-allocator "Disable zone allocator for Darwin" ON) set (PACKAGE_NAME "jemalloc") project (${PACKAGE_NAME} C) @@ -204,7 +205,7 @@ set(abi "elf") # Whether malloc_usable_size definition can use const argument CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H) -if(HAVE_MALLOC_H) +if(HAVE_MALLOC_H OR APPLE) set(JEMALLOC_USABLE_SIZE_CONST const) endif() @@ -702,7 +703,7 @@ set(C_SRCS src/witness.c ) -if(CMAKE_SYSTEM_NAME MATCHES "Darwin") +if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT disable-zone-allocator) list(APPEND C_SRCS src/zone.c) endif() diff --git a/Utilities.cmake b/Utilities.cmake index 1ab2dc46..755e3909 100644 --- a/Utilities.cmake +++ b/Utilities.cmake @@ -641,7 +641,6 @@ if(EXISTS ${file_path}) file(WRITE "${CMAKE_BINARY_DIR}/${ntv_file_relative_path}" "${NTV_FILE_CONTENT}") configure_file(${CMAKE_BINARY_DIR}/${ntv_file_relative_path} ${output_path} @ONLY NEWLINE_STYLE WIN32) - configure_file(${file_path}.cmake ${output_path} @ONLY NEWLINE_STYLE WIN32) file(REMOVE ${file_path}.cmake) endif() include_directories("${CMAKE_SOURCE_DIR}/include") @@ -716,25 +715,34 @@ set(SRC "${WORK_FOLDER}/getpagesize.c") set(COMPILE_OUTPUT_FILE "${WORK_FOLDER}/getpagesize.log") file(WRITE ${SRC} +"#include \n" "#ifdef _WIN32\n" "#include \n" -"#include \n" +"#elif defined(__APPLE__)\n" +"#include \n" +"#include \n" "#else\n" "#include \n" "#endif\n" "int main(int argc, const char** argv) {\n" "#ifdef _WIN32\n" "int result;\n" -"#ifdef _WIN32\n" "SYSTEM_INFO si;\n" "GetSystemInfo(&si);\n" "result = si.dwPageSize;\n" -"#else\n" -"result = sysconf(_SC_PAGESIZE);\n" -"#endif\n" "printf(\"%d\", result);\n" +"#elif defined(__APPLE__)\n" +"int mib[2], value, pagesize;\n" +"size_t size;\n" +"mib[0] = CTL_HW;\n" +"mib[1] = HW_PAGESIZE;\n" +"size = sizeof value;\n" +"if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)\n" +" pagesize = -1;\n" +"pagesize = value;\n" +"printf(\"%d\", pagesize);\n" "#else\n" -"printf(\"page size = %d\\n\", getpagesize());\n" +"printf(\"%d\", getpagesize());\n" "#endif\n" "return 0;\n" "}\n"