cmake_minimum_required(VERSION 3.12)
# Please note that cmake support is very preliminary. Autotools-based
# build is the only fully supported build for now.
# Based on configure.ac
project(gperftools VERSION 2.10.0 LANGUAGES C CXX
DESCRIPTION "Performance tools for C++"
HOMEPAGE_URL http://code.google.com/p/gperftools/)
# Update this value for every release!
set(TCMALLOC_SO_VERSION 9.10.5)
set(PROFILER_SO_VERSION 5.5.5)
set(TCMALLOC_AND_PROFILER_SO_VERSION 10.5.6)
# The user can choose not to compile in the heap-profiler, the
# heap-checker, or the cpu-profiler. There's also the possibility
# for a 'fully minimal' compile, which leaves out the stacktrace
# code as well. By default, we include all of these that the
# target system supports.
set(DEFAULT_BUILD_CPU_PROFILER ON)
set(DEFAULT_BUILD_HEAP_PROFILER ON)
set(DEFAULT_BUILD_HEAP_CHECKER ON)
set(DEFAULT_BUILD_DEBUGALLOC ON)
set(DEFAULT_BUILD_MINIMAL OFF)
set(DEFAULT_TCMALLOC_ALIGNMENT 16)
set(NEED_NANOSLEEP ON) # Used later, to decide if to run ACX_NANOSLEEP
set(HOST string(TOLOWER "${CMAKE_SYSTEM_NAME}"))
if(MINGW OR MSVC)
set(DEFAULT_BUILD_MINIMAL ON)
set(DEFAULT_BUILD_DEBUGALLOC OFF)
set(NEED_NANOSLEEP OFF)
elseif(CYGWIN)
set(DEFAULT_BUILD_HEAP_CHECKER OFF)
set(DEFAULT_BUILD_CPU_PROFILER OFF)
elseif(HOST MATCHES "freebsd")
set(DEFAULT_BUILD_HEAP_CHECKER OFF)
elseif(APPLE)
set(DEFAULT_BUILD_HEAP_CHECKER OFF)
endif()
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckVariableExists)
include(CMakeDependentOption)
include(CTest)
include(CPack)
include(GNUInstallDirs)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(DefineTargetVariables)
include(FindObjcopyWithWeaken)
include(PCFromUContext)
define_target_variables()
# Currently only backtrace works on s390.
if(s390 OR OSX)
set(default_enable_libunwind OFF)
set(default_enable_backtrace ON)
else()
set(default_enable_libunwind ON)
set(default_enable_backtrace OFF)
endif()
# Disable libunwind linking on ppc64 by default.
if(PPC64)
set(default_enable_libunwind OFF)
set(default_tcmalloc_pagesize 64)
else()
set(default_enable_libunwind ON)
set(default_tcmalloc_pagesize 8)
endif()
cmake_dependent_option(
GPERFTOOLS_BUILD_CPU_PROFILER "Build cpu-profiler" ${DEFAULT_BUILD_CPU_PROFILER}
"NOT gperftools_build_minimal" OFF)
cmake_dependent_option(
GPERFTOOLS_BUILD_HEAP_PROFILER "Build heap-profiler" ${DEFAULT_BUILD_HEAP_PROFILER}
"NOT gperftools_build_minimal" OFF)
cmake_dependent_option(
GPERFTOOLS_BUILD_HEAP_CHECKER "Build heap-checker" ${DEFAULT_BUILD_HEAP_CHECKER}
"NOT gperftools_build_minimal" OFF)
cmake_dependent_option(
GPERFTOOLS_BUILD_DEBUGALLOC "Build debugalloc" ${DEFAULT_BUILD_DEBUGALLOC}
"NOT gperftools_build_minimal" OFF)
option(
gperftools_build_minimal
"Build only tcmalloc-minimal (and maybe tcmalloc-minimal-debug)"
${DEFAULT_BUILD_MINIMAL})
if(gperftools_build_minimal)
set(GPERFTOOLS_BUILD_CPU_PROFILER OFF)
set(GPERFTOOLS_BUILD_HEAP_PROFILER OFF)
set(GPERFTOOLS_BUILD_HEAP_CHECKER OFF)
endif()
cmake_dependent_option(
gperftools_build_benchmark "Build benchmark" ON "NOT MINGW AND NOT MSVC" OFF)
option(gperftools_enable_stacktrace_via_backtrace
"Enable use of backtrace() for stacktrace capturing (may deadlock)"
${default_enable_backtrace})
option(gperftools_enable_libunwind
"Enable libunwind linking"
${default_enable_libunwind})
set(enable_backtrace ${gperftools_enable_stacktrace_via_backtrace})
set(enable_libunwind ${gperftools_enable_libunwind})
set(gperftools_tcmalloc_pagesize ${default_tcmalloc_pagesize}
CACHE STRING "Set the tcmalloc internal page size")
set_property(CACHE gperftools_tcmalloc_pagesize PROPERTY STRINGS "8" "32" "64")
if(NOT gperftools_tcmalloc_pagesize STREQUAL "8" AND
NOT gperftools_tcmalloc_pagesize STREQUAL "32" AND
NOT gperftools_tcmalloc_pagesize STREQUAL "64")
message(WARNING
"Invalid gperftools_tcmalloc_pagesize (${gperftools_tcmalloc_pagesize}), "
"setting to default value (${default_tcmalloc_pagesize})")
set(gperftools_tcmalloc_pagesize ${default_tcmalloc_pagesize})
endif()
if (gperftools_tcmalloc_pagesize STREQUAL "32" OR
gperftools_tcmalloc_pagesize STREQUAL "64")
set(TCMALLOC_${gperftools_tcmalloc_pagesize}K_PAGES ON)
endif()
set(gperftools_tcmalloc_alignment ${DEFAULT_TCMALLOC_ALIGNMENT}
CACHE STRING "Set the tcmalloc allocation alignment")
set_property(CACHE gperftools_tcmalloc_alignment PROPERTY STRINGS "8" "16")
if(NOT gperftools_tcmalloc_alignment STREQUAL "8" AND
NOT gperftools_tcmalloc_alignment STREQUAL "16")
message(WARNING
"Invalid gperftools_tcmalloc_alignment (${gperftools_tcmalloc_alignment}), "
"setting to default value (${DEFAULT_TCMALLOC_ALIGNMENT})")
set(gperftools_tcmalloc_alignment ${DEFAULT_TCMALLOC_ALIGNMENT})
endif()
if(gperftools_tcmalloc_alignment STREQUAL "8")
set(TCMALLOC_ALIGN_8BYTES ON)
endif()
# AX_CXX_COMPILE_STDCXX(11, ext, mandatory)
if(cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 17) # std::align_val_t
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
# Check if we have an objcopy installed that supports -W
find_objcopy_with_weaken()
# AX_C___ATTRIBUTE__
check_c_source_compiles("#include <stdlib.h>
static void foo(void) __attribute__ ((unused));
void foo(void) { exit(1); }
int main() { return 0; }"
HAVE___ATTRIBUTE__)
set(CMAKE_EXTRA_INCLUDE_FILES "malloc.h")
check_type_size("struct mallinfo" STRUCT_MALLINFO LANGUAGE CXX)
set(CMAKE_EXTRA_INCLUDE_FILES "elf.h")
check_type_size("Elf32_Versym" ELF32_VERSYM LANGUAGE CXX) # for vdso_support.h
set(CMAKE_EXTRA_INCLUDE_FILES)
check_function_exists("sbrk" HAVE_SBRK) # for tcmalloc to get memory
check_function_exists("__sbrk" HAVE_SBRK) # for tcmalloc to get memory
check_function_exists("geteuid" HAVE_GETEUID) # for turning off services when run as root
check_function_exists("fork" HAVE_FORK) # for the pthread_atfork setup
check_include_file("features.h" HAVE_FEATURES_H) # for vdso_support.h, Where __GLIBC__ is defined
check_include_file("malloc.h" HAVE_MALLOC_H) # some systems define stuff there, others not
check_include_file("glob.h" HAVE_GLOB_H) # for heap-profile-table (cleaning up profiles)
check_include_file("execinfo.h" HAVE_EXECINFO_H) # for stacktrace? and heapchecker_unittest
check_include_file("unwind.h" HAVE_UNWIND_H) # for stacktrace
check_include_file("sched.h" HAVE_SCHED_H) # for being nice in our spinlock code
check_include_file("sys/prctl.h" HAVE_SYS_PRCTL_H) # for thread_lister (needed by leak-checker)
check_include_file("linux/ptrace.h" HAVE_LINUX_PTRACE_H) # also needed by leak-checker
check_include_file("sys/syscall.h" HAVE_SYS_SYSCALL_H)
check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) # optional; for forking out to symbolizer
check_include_file("sys/wait.h" HAVE_SYS_WAIT_H) # optional; for forking out to symbolizer
check_include_file("poll.h" HAVE_POLL_H) # optional; for forking out to symbolizer
check_include_file("fcntl.h" HAVE_FCNTL_H) # for tcmalloc_unittest
check_include_file("grp.h" HAVE_GRP_H) # for heapchecker_unittest
check_include_file("pwd.h" HAVE_PWD_H) # for heapchecker_unittest
check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H) # for memalign_unittest.cc
check_include_file("sys/cdefs.h" HAVE_SYS_CDEFS_H) # Where glibc defines __THROW
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
# We also need <ucontext.h>/<sys/ucontext.h>, but we get those from
# AC_PC_FROM_UCONTEXT, below.
# We override a lot of memory allocation routines, not all of which are
# standard. For those the system doesn