|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# |
| 14 | +# Tries to find jemalloc headers and libraries. |
| 15 | +# |
| 16 | +# Usage of this module as follows: |
| 17 | +# |
| 18 | +# find_package(jemalloc) |
| 19 | +# |
| 20 | +# Variables used by this module, they can change the default behaviour and need |
| 21 | +# to be set before calling find_package: |
| 22 | +# |
| 23 | +# JEMALLOC_HOME - |
| 24 | +# When set, this path is inspected instead of standard library locations as |
| 25 | +# the root of the jemalloc installation. The environment variable |
| 26 | +# JEMALLOC_HOME overrides this veriable. |
| 27 | +# |
| 28 | +# This module defines |
| 29 | +# JEMALLOC_INCLUDE_DIR, directory containing headers |
| 30 | +# JEMALLOC_SHARED_LIB, path to libjemalloc.so/dylib |
| 31 | +# JEMALLOC_FOUND, whether flatbuffers has been found |
| 32 | + |
| 33 | +if( NOT "$ENV{JEMALLOC_HOME}" STREQUAL "") |
| 34 | + file( TO_CMAKE_PATH "$ENV{JEMALLOC_HOME}" _native_path ) |
| 35 | + list( APPEND _jemalloc_roots ${_native_path} ) |
| 36 | +elseif ( JEMALLOC_HOME ) |
| 37 | + list( APPEND _jemalloc_roots ${JEMALLOC_HOME} ) |
| 38 | +endif() |
| 39 | + |
| 40 | +set(LIBJEMALLOC_NAMES jemalloc libjemalloc.so.1 libjemalloc.so.2 libjemalloc.dylib) |
| 41 | + |
| 42 | +# Try the parameterized roots, if they exist |
| 43 | +if ( _jemalloc_roots ) |
| 44 | + find_path( JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h |
| 45 | + PATHS ${_jemalloc_roots} NO_DEFAULT_PATH |
| 46 | + PATH_SUFFIXES "include" ) |
| 47 | + find_library( JEMALLOC_SHARED_LIB NAMES ${LIBJEMALLOC_NAMES} |
| 48 | + PATHS ${_jemalloc_roots} NO_DEFAULT_PATH |
| 49 | + PATH_SUFFIXES "lib" ) |
| 50 | +else () |
| 51 | + find_path( JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h ) |
| 52 | + message(STATUS ${JEMALLOC_INCLUDE_DIR}) |
| 53 | + find_library( JEMALLOC_SHARED_LIB NAMES ${LIBJEMALLOC_NAMES}) |
| 54 | + message(STATUS ${JEMALLOC_SHARED_LIB}) |
| 55 | +endif () |
| 56 | + |
| 57 | +if (JEMALLOC_INCLUDE_DIR AND JEMALLOC_SHARED_LIB) |
| 58 | + set(JEMALLOC_FOUND TRUE) |
| 59 | +else () |
| 60 | + set(JEMALLOC_FOUND FALSE) |
| 61 | +endif () |
| 62 | + |
| 63 | +if (JEMALLOC_FOUND) |
| 64 | + if (NOT jemalloc_FIND_QUIETLY) |
| 65 | + message(STATUS "Found the jemalloc library: ${JEMALLOC_LIBRARIES}") |
| 66 | + endif () |
| 67 | +else () |
| 68 | + if (NOT jemalloc_FIND_QUIETLY) |
| 69 | + set(JEMALLOC_ERR_MSG "Could not find the jemalloc library. Looked in ") |
| 70 | + if ( _flatbuffers_roots ) |
| 71 | + set(JEMALLOC_ERR_MSG "${JEMALLOC_ERR_MSG} in ${_jemalloc_roots}.") |
| 72 | + else () |
| 73 | + set(JEMALLOC_ERR_MSG "${JEMALLOC_ERR_MSG} system search paths.") |
| 74 | + endif () |
| 75 | + if (jemalloc_FIND_REQUIRED) |
| 76 | + message(FATAL_ERROR "${JEMALLOC_ERR_MSG}") |
| 77 | + else (jemalloc_FIND_REQUIRED) |
| 78 | + message(STATUS "${JEMALLOC_ERR_MSG}") |
| 79 | + endif (jemalloc_FIND_REQUIRED) |
| 80 | + endif () |
| 81 | +endif () |
| 82 | + |
| 83 | +mark_as_advanced( |
| 84 | + JEMALLOC_INCLUDE_DIR |
| 85 | + JEMALLOC_SHARED_LIB |
| 86 | +) |
0 commit comments