1*9e3b08aeSAndroid Build Coastguard Worker# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2*9e3b08aeSAndroid Build Coastguard Worker# 3*9e3b08aeSAndroid Build Coastguard Worker# Copyright 2023 Google LLC 4*9e3b08aeSAndroid Build Coastguard Worker# 5*9e3b08aeSAndroid Build Coastguard Worker# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); 6*9e3b08aeSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. You may 7*9e3b08aeSAndroid Build Coastguard Worker# obtain a copy of the License at 8*9e3b08aeSAndroid Build Coastguard Worker# 9*9e3b08aeSAndroid Build Coastguard Worker# https://llvm.org/LICENSE.txt 10*9e3b08aeSAndroid Build Coastguard Worker# 11*9e3b08aeSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*9e3b08aeSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13*9e3b08aeSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14*9e3b08aeSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 15*9e3b08aeSAndroid Build Coastguard Worker# the License. 16*9e3b08aeSAndroid Build Coastguard Worker# 17*9e3b08aeSAndroid Build Coastguard Worker# Author: Aleksei Vetrov 18*9e3b08aeSAndroid Build Coastguard Worker 19*9e3b08aeSAndroid Build Coastguard Worker#[=======================================================================[.rst: 20*9e3b08aeSAndroid Build Coastguard WorkerFindJemalloc 21*9e3b08aeSAndroid Build Coastguard Worker--------- 22*9e3b08aeSAndroid Build Coastguard Worker 23*9e3b08aeSAndroid Build Coastguard WorkerFinds the jemalloc library. 24*9e3b08aeSAndroid Build Coastguard Worker 25*9e3b08aeSAndroid Build Coastguard WorkerImported Targets 26*9e3b08aeSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^ 27*9e3b08aeSAndroid Build Coastguard Worker 28*9e3b08aeSAndroid Build Coastguard WorkerThis module provides the following imported targets, if found: 29*9e3b08aeSAndroid Build Coastguard Worker 30*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc::Jemalloc`` 31*9e3b08aeSAndroid Build Coastguard Worker The Jemalloc library 32*9e3b08aeSAndroid Build Coastguard Worker 33*9e3b08aeSAndroid Build Coastguard WorkerResult Variables 34*9e3b08aeSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^ 35*9e3b08aeSAndroid Build Coastguard Worker 36*9e3b08aeSAndroid Build Coastguard WorkerThis will define the following variables: 37*9e3b08aeSAndroid Build Coastguard Worker 38*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_FOUND`` 39*9e3b08aeSAndroid Build Coastguard Worker True if the system has the Jemalloc library. 40*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_VERSION`` 41*9e3b08aeSAndroid Build Coastguard Worker The version of the Jemalloc library which was found. 42*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_INCLUDE_DIRS`` 43*9e3b08aeSAndroid Build Coastguard Worker Include directories needed to use Jemalloc. 44*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_LIBRARIES`` 45*9e3b08aeSAndroid Build Coastguard Worker Libraries needed to link to Jemalloc. 46*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_DEFINITIONS`` 47*9e3b08aeSAndroid Build Coastguard Worker the compiler switches required for using Jemalloc 48*9e3b08aeSAndroid Build Coastguard Worker 49*9e3b08aeSAndroid Build Coastguard WorkerCache Variables 50*9e3b08aeSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^ 51*9e3b08aeSAndroid Build Coastguard Worker 52*9e3b08aeSAndroid Build Coastguard WorkerThe following cache variables may also be set: 53*9e3b08aeSAndroid Build Coastguard Worker 54*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_INCLUDE_DIR`` 55*9e3b08aeSAndroid Build Coastguard Worker The directory containing ``jemalloc.h``. 56*9e3b08aeSAndroid Build Coastguard Worker``Jemalloc_LIBRARY`` 57*9e3b08aeSAndroid Build Coastguard Worker The path to the ``libjemalloc.so``. 58*9e3b08aeSAndroid Build Coastguard Worker 59*9e3b08aeSAndroid Build Coastguard Worker#]=======================================================================] 60*9e3b08aeSAndroid Build Coastguard Worker 61*9e3b08aeSAndroid Build Coastguard Workerfind_package(PkgConfig) 62*9e3b08aeSAndroid Build Coastguard Workerpkg_check_modules(PC_Jemalloc QUIET jemalloc) 63*9e3b08aeSAndroid Build Coastguard Worker 64*9e3b08aeSAndroid Build Coastguard Workerfind_library( 65*9e3b08aeSAndroid Build Coastguard Worker Jemalloc_LIBRARY 66*9e3b08aeSAndroid Build Coastguard Worker NAMES jemalloc 67*9e3b08aeSAndroid Build Coastguard Worker HINTS ${PC_Jemalloc_LIBDIR} ${PC_Jemalloc_LIBRARY_DIRS}) 68*9e3b08aeSAndroid Build Coastguard Worker# Try the value from user if the library is not found. 69*9e3b08aeSAndroid Build Coastguard Workerif(DEFINED Jemalloc_LIBRARIES AND NOT DEFINED Jemalloc_LIBRARY) 70*9e3b08aeSAndroid Build Coastguard Worker set(Jemalloc_LIBRARY ${Jemalloc_LIBRARIES}) 71*9e3b08aeSAndroid Build Coastguard Workerendif() 72*9e3b08aeSAndroid Build Coastguard Workermark_as_advanced(Jemalloc_LIBRARY) 73*9e3b08aeSAndroid Build Coastguard Worker 74*9e3b08aeSAndroid Build Coastguard Workerfind_path( 75*9e3b08aeSAndroid Build Coastguard Worker Jemalloc_INCLUDE_DIR 76*9e3b08aeSAndroid Build Coastguard Worker NAMES jemalloc.h 77*9e3b08aeSAndroid Build Coastguard Worker PATH_SUFFIXES jemalloc 78*9e3b08aeSAndroid Build Coastguard Worker HINTS ${PC_Jemalloc_INCLUDEDIR} ${PC_Jemalloc_INCLUDE_DIRS}) 79*9e3b08aeSAndroid Build Coastguard Worker# Try the value from user if the library is not found. 80*9e3b08aeSAndroid Build Coastguard Workerif(DEFINED Jemalloc_INCLUDE_DIRS AND NOT DEFINED Jemalloc_INCLUDE_DIR) 81*9e3b08aeSAndroid Build Coastguard Worker set(Jemalloc_INCLUDE_DIR ${Jemalloc_INCLUDE_DIRS}) 82*9e3b08aeSAndroid Build Coastguard Workerendif() 83*9e3b08aeSAndroid Build Coastguard Workermark_as_advanced(Jemalloc_INCLUDE_DIR) 84*9e3b08aeSAndroid Build Coastguard Worker 85*9e3b08aeSAndroid Build Coastguard Workerset(Jemalloc_VERSION ${PC_Jemalloc_VERSION}) 86*9e3b08aeSAndroid Build Coastguard Worker 87*9e3b08aeSAndroid Build Coastguard Workerinclude(FindPackageHandleStandardArgs) 88*9e3b08aeSAndroid Build Coastguard Workerfind_package_handle_standard_args( 89*9e3b08aeSAndroid Build Coastguard Worker Jemalloc 90*9e3b08aeSAndroid Build Coastguard Worker REQUIRED_VARS Jemalloc_LIBRARY Jemalloc_INCLUDE_DIR 91*9e3b08aeSAndroid Build Coastguard Worker VERSION_VAR Jemalloc_VERSION) 92*9e3b08aeSAndroid Build Coastguard Worker 93*9e3b08aeSAndroid Build Coastguard Workerif(Jemalloc_FOUND) 94*9e3b08aeSAndroid Build Coastguard Worker set(Jemalloc_LIBRARIES ${Jemalloc_LIBRARY}) 95*9e3b08aeSAndroid Build Coastguard Worker set(Jemalloc_INCLUDE_DIRS ${Jemalloc_INCLUDE_DIR}) 96*9e3b08aeSAndroid Build Coastguard Worker set(Jemalloc_DEFINITIONS ${PC_Jemalloc_CFLAGS_OTHER}) 97*9e3b08aeSAndroid Build Coastguard Workerendif() 98*9e3b08aeSAndroid Build Coastguard Worker 99*9e3b08aeSAndroid Build Coastguard Workerif(Jemalloc_FOUND AND NOT TARGET Jemalloc::Jemalloc) 100*9e3b08aeSAndroid Build Coastguard Worker add_library(Jemalloc::Jemalloc UNKNOWN IMPORTED) 101*9e3b08aeSAndroid Build Coastguard Worker set_target_properties( 102*9e3b08aeSAndroid Build Coastguard Worker Jemalloc::Jemalloc 103*9e3b08aeSAndroid Build Coastguard Worker PROPERTIES IMPORTED_LOCATION "${Jemalloc_LIBRARY}" 104*9e3b08aeSAndroid Build Coastguard Worker INTERFACE_COMPILE_OPTIONS "${PC_Jemalloc_CFLAGS_OTHER}" 105*9e3b08aeSAndroid Build Coastguard Worker INTERFACE_INCLUDE_DIRECTORIES "${Jemalloc_INCLUDE_DIR}") 106*9e3b08aeSAndroid Build Coastguard Workerendif() 107