Skip to content
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

Support non-Windows configure and build #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=<path> XSL stylesheet root path
option(disable-zone-allocator "Disable zone allocator for Darwin" ON)

set (PACKAGE_NAME "jemalloc")
project (${PACKAGE_NAME} C)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -491,6 +492,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)
Expand Down Expand Up @@ -701,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)
Copy link
Author

Choose a reason for hiding this comment

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

I don't know how to get apple zone, so temporary disable this according to configure.ac.

list(APPEND C_SRCS src/zone.c)
endif()

Expand Down
51 changes: 28 additions & 23 deletions Utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -628,35 +628,22 @@ 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})
configure_file(${file_path} ${output_path} @ONLY NEWLINE_STYLE WIN32)
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(${file_path}.cmake ${output_path} @ONLY NEWLINE_STYLE WIN32)
configure_file(${CMAKE_BINARY_DIR}/${ntv_file_relative_path} ${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()
Expand Down Expand Up @@ -728,18 +715,35 @@ set(SRC "${WORK_FOLDER}/getpagesize.c")
set(COMPILE_OUTPUT_FILE "${WORK_FOLDER}/getpagesize.log")

file(WRITE ${SRC}
"#include <windows.h>\n"
"#include <stdio.h>\n"
"#ifdef _WIN32\n"
"#include <windows.h>\n"
"#elif defined(__APPLE__)\n"
"#include <sys/param.h>\n"
"#include <sys/sysctl.h>\n"
"#else\n"
"#include <unistd.h>\n"
"#endif\n"
"int main(int argc, const char** argv) {\n"
"int result;\n"
"#ifdef _WIN32\n"
"int result;\n"
"SYSTEM_INFO si;\n"
"GetSystemInfo(&si);\n"
"result = si.dwPageSize;\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"
"result = sysconf(_SC_PAGESIZE);\n"
"printf(\"%d\", getpagesize());\n"
"#endif\n"
"printf(\"%d\", result);\n"
"return 0;\n"
"}\n"
)
Expand Down Expand Up @@ -776,6 +780,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)
Expand Down
2 changes: 1 addition & 1 deletion src/jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down