aboutsummaryrefslogtreecommitdiff
path: root/cmake/FindJeMalloc.cmake
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-04-12 11:40:08 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-04-13 08:22:59 -0300
commit8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2 (patch)
tree89ef647267ef31794eeb2f297886e6bde97dcf10 /cmake/FindJeMalloc.cmake
parent34c48aaf123ffd8aec31b79f0b4d16d9a63fe59b (diff)
downloadrneovim-8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2.tar.gz
rneovim-8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2.tar.bz2
rneovim-8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2.zip
deps: Add jemalloc as an optional dependency
Jemalloc will be used if the cmake option `USE_JEMALLOC` is enabled(which is the default). To avoid trouble with clang's ASAN, it is disabled by default if the `SANITIZE` option is enabled. Since jemalloc has thread cache for small objects, it fills the gap created by removing klib memory pools. The `xstrdup` funciton(memory.c) had to be reimplemented on top of `xmalloc` to make it work with a custom allocator.
Diffstat (limited to 'cmake/FindJeMalloc.cmake')
-rw-r--r--cmake/FindJeMalloc.cmake48
1 files changed, 48 insertions, 0 deletions
diff --git a/cmake/FindJeMalloc.cmake b/cmake/FindJeMalloc.cmake
new file mode 100644
index 0000000000..fd20a456fb
--- /dev/null
+++ b/cmake/FindJeMalloc.cmake
@@ -0,0 +1,48 @@
+# - Try to find jemalloc
+# Once done this will define
+# JEMALLOC_FOUND - System has jemalloc
+# JEMALLOC_INCLUDE_DIRS - The jemalloc include directories
+# JEMALLOC_LIBRARIES - The libraries needed to use jemalloc
+
+find_package(PkgConfig)
+if(NOT JEMALLOC_USE_BUNDLED)
+ find_package(PkgConfig)
+ if (PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_JEMALLOC QUIET jemalloc)
+ endif()
+else()
+ set(PC_JEMALLOC_INCLUDEDIR)
+ set(PC_JEMALLOC_INCLUDE_DIRS)
+ set(PC_JEMALLOC_LIBDIR)
+ set(PC_JEMALLOC_LIBRARY_DIRS)
+ set(LIMIT_SEARCH NO_DEFAULT_PATH)
+endif()
+
+set(JEMALLOC_DEFINITIONS ${PC_JEMALLOC_CFLAGS_OTHER})
+
+find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h
+ PATHS ${PC_JEMALLOC_INCLUDEDIR} ${PC_JEMALLOC_INCLUDE_DIRS}
+ ${LIMIT_SEARCH})
+
+# If we're asked to use static linkage, add libjemalloc.a as a preferred library name.
+if(JEMALLOC_USE_STATIC)
+ list(APPEND JEMALLOC_NAMES
+ "${CMAKE_STATIC_LIBRARY_PREFIX}jemalloc${CMAKE_STATIC_LIBRARY_SUFFIX}")
+endif()
+
+list(APPEND JEMALLOC_NAMES jemalloc)
+
+find_library(JEMALLOC_LIBRARY NAMES ${JEMALLOC_NAMES}
+ HINTS ${PC_JEMALLOC_LIBDIR} ${PC_JEMALLOC_LIBRARY_DIRS}
+ ${LIMIT_SEARCH})
+
+set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY})
+set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(JeMalloc DEFAULT_MSG
+ JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR)
+
+mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY)