1# - Find JeMalloc library 2# Find the native JeMalloc includes and library 3# This module defines 4# JEMALLOC_INCLUDE_DIRS, where to find jemalloc.h, Set when 5# JEMALLOC_INCLUDE_DIR is found. 6# JEMALLOC_LIBRARIES, libraries to link against to use JeMalloc. 7# JEMALLOC_ROOT_DIR, The base directory to search for JeMalloc. 8# This can also be an environment variable. 9# JEMALLOC_FOUND, If false, do not try to use JeMalloc. 10# 11# also defined, but not for general use are 12# JEMALLOC_LIBRARY, where to find the JeMalloc library. 13 14#============================================================================= 15# Copyright 2011 Blender Foundation. 16# 17# Distributed under the OSI-approved BSD 3-Clause License, 18# see accompanying file BSD-3-Clause-license.txt for details. 19#============================================================================= 20 21# If JEMALLOC_ROOT_DIR was defined in the environment, use it. 22IF(NOT JEMALLOC_ROOT_DIR AND NOT $ENV{JEMALLOC_ROOT_DIR} STREQUAL "") 23 SET(JEMALLOC_ROOT_DIR $ENV{JEMALLOC_ROOT_DIR}) 24ENDIF() 25 26SET(_jemalloc_SEARCH_DIRS 27 ${JEMALLOC_ROOT_DIR} 28 /opt/lib/jemalloc 29) 30 31FIND_PATH(JEMALLOC_INCLUDE_DIR 32 NAMES 33 jemalloc.h 34 HINTS 35 ${_jemalloc_SEARCH_DIRS} 36 PATH_SUFFIXES 37 include/jemalloc 38) 39 40FIND_LIBRARY(JEMALLOC_LIBRARY 41 NAMES 42 jemalloc 43 HINTS 44 ${_jemalloc_SEARCH_DIRS} 45 PATH_SUFFIXES 46 lib64 lib 47 ) 48 49if(JEMALLOC_INCLUDE_DIR) 50 SET(_version_regex "^#define[ \t]+JEMALLOC_VERSION[ \t]+\"([^\"]+)\".*") 51 file(STRINGS "${JEMALLOC_INCLUDE_DIR}/jemalloc.h" 52 JEMALLOC_VERSION REGEX "${_version_regex}") 53 string(REGEX REPLACE "${_version_regex}" "\\1" 54 JEMALLOC_VERSION "${JEMALLOC_VERSION}") 55 unset(_version_regex) 56endif() 57 58# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE if 59# all listed variables are TRUE 60INCLUDE(FindPackageHandleStandardArgs) 61FIND_PACKAGE_HANDLE_STANDARD_ARGS(JeMalloc DEFAULT_MSG 62 JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR) 63 64IF(JEMALLOC_FOUND) 65 SET(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY}) 66 SET(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) 67ENDIF() 68 69MARK_AS_ADVANCED( 70 JEMALLOC_INCLUDE_DIR 71 JEMALLOC_LIBRARY 72) 73