• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# - Try to find jemalloc
2# Once done this will define
3#  JEMALLOC_FOUND        - System has jemalloc
4#  JEMALLOC_INCLUDE_DIRS - The jemalloc include directories
5#  JEMALLOC_LIBRARIES    - The libraries needed to use jemalloc
6
7find_package(PkgConfig QUIET)
8pkg_check_modules(PC_JEMALLOC QUIET jemalloc)
9
10find_path(JEMALLOC_INCLUDE_DIR
11  NAMES jemalloc/jemalloc.h
12  HINTS ${PC_JEMALLOC_INCLUDE_DIRS}
13)
14find_library(JEMALLOC_LIBRARY
15  NAMES jemalloc
16  HINTS ${PC_JEMALLOC_LIBRARY_DIRS}
17)
18
19if(JEMALLOC_INCLUDE_DIR)
20  set(_version_regex "^#define[ \t]+JEMALLOC_VERSION[ \t]+\"([^\"]+)\".*")
21  file(STRINGS "${JEMALLOC_INCLUDE_DIR}/jemalloc/jemalloc.h"
22    JEMALLOC_VERSION REGEX "${_version_regex}")
23  string(REGEX REPLACE "${_version_regex}" "\\1"
24    JEMALLOC_VERSION "${JEMALLOC_VERSION}")
25  unset(_version_regex)
26endif()
27
28include(FindPackageHandleStandardArgs)
29# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE
30# if all listed variables are TRUE and the requested version matches.
31find_package_handle_standard_args(Jemalloc REQUIRED_VARS
32                                  JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR
33                                  VERSION_VAR JEMALLOC_VERSION)
34
35if(JEMALLOC_FOUND)
36  set(JEMALLOC_LIBRARIES    ${JEMALLOC_LIBRARY})
37  set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR})
38endif()
39
40mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY)
41