From 540b9c3320f90af5062b71c4d2744c1ae78e084f Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Fri, 9 Jun 2023 15:44:16 -0500 Subject: [PATCH] Add support for jemalloc in CMake build It looks like jemalloc is only included in libtscore. Detecting support of jemalloc is one of the prerequisites for building traffic_layout, which in turn is necessary to run autests. --- CMakeLists.txt | 4 +++ cmake/Findjemalloc.cmake | 49 ++++++++++++++++++++++++++++ include/tscore/ink_config.h.cmake.in | 1 + src/tscore/CMakeLists.txt | 1 + 4 files changed, 55 insertions(+) create mode 100644 cmake/Findjemalloc.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 097b155861e..33ee78465e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,10 @@ CHECK_INCLUDE_FILE(arpa/nameser_compat.h HAVE_ARPA_NAMESER_COMPAT_H) CHECK_INCLUDE_FILE(siginfo.h HAVE_SIGINFO_H) # Find libraries +find_package(jemalloc) +if(jemalloc_FOUND) + set(TS_HAS_JEMALLOC TRUE) +endif() find_package(hwloc) if(hwloc_FOUND) set(TS_USE_HWLOC TRUE) diff --git a/cmake/Findjemalloc.cmake b/cmake/Findjemalloc.cmake new file mode 100644 index 00000000000..ec5b1f06a27 --- /dev/null +++ b/cmake/Findjemalloc.cmake @@ -0,0 +1,49 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + +# Findjemalloc.cmake +# +# This will define the following variables +# +# jemalloc_FOUND +# jemalloc_LIBRARY +# jemalloc_INCLUDE_DIRS +# +# and the following imported targets +# +# jemalloc::jemalloc +# + +find_library(jemalloc_LIBRARY NAMES jemalloc) +find_path(jemalloc_INCLUDE_DIR NAMES jemalloc.h PATH_SUFFIXES jemalloc) + +mark_as_advanced(jemalloc_FOUND jemalloc_LIBRARY jemalloc_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(jemalloc + REQUIRED_VARS jemalloc_LIBRARY jemalloc_INCLUDE_DIR +) + +if(jemalloc_FOUND) + set(jemalloc_INCLUDE_DIRS ${jemalloc_INCLUDE_DIR}) +endif() + +if(jemalloc_FOUND AND NOT TARGET jemalloc::jemalloc) + add_library(jemalloc::jemalloc INTERFACE IMPORTED) + target_include_directories(jemalloc::jemalloc INTERFACE ${jemalloc_INCLUDE_DIRS}) + target_link_libraries(jemalloc::jemalloc INTERFACE ${jemalloc_LIBRARY}) +endif() diff --git a/include/tscore/ink_config.h.cmake.in b/include/tscore/ink_config.h.cmake.in index a4980bf9b58..37cfcd501ae 100644 --- a/include/tscore/ink_config.h.cmake.in +++ b/include/tscore/ink_config.h.cmake.in @@ -104,6 +104,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@; #define TS_MAX_HOST_NAME_LEN @TS_MAX_HOST_NAME_LEN@ /* Feature Flags */ +#cmakedefine01 TS_HAS_JEMALLOC #cmakedefine01 TS_USE_EPOLL #cmakedefine01 TS_USE_HWLOC #cmakedefine01 TS_USE_KQUEUE diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt index 312ed926777..49016f1ffb9 100644 --- a/src/tscore/CMakeLists.txt +++ b/src/tscore/CMakeLists.txt @@ -108,6 +108,7 @@ target_include_directories(tscore PRIVATE ) target_link_libraries(tscore PUBLIC + $<$:jemalloc::jemalloc> $<$:hwloc::hwloc> libswoc ${OPENSSL_LIBRARIES}