2019-01-15 17:17:55 +03:00
|
|
|
|
cmake_minimum_required(VERSION 3.8)
|
|
|
|
|
project(snmalloc C CXX)
|
|
|
|
|
|
2020-05-06 20:24:45 +03:00
|
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
|
|
|
|
message(STATUS "No build type selected, default to: Release")
|
|
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-03-20 12:17:38 +03:00
|
|
|
|
include(CheckCXXCompilerFlag)
|
2020-04-18 09:58:13 +03:00
|
|
|
|
include(CheckCSourceCompiles)
|
2020-03-20 12:17:38 +03:00
|
|
|
|
|
2019-01-15 17:17:55 +03:00
|
|
|
|
option(USE_SNMALLOC_STATS "Track allocation stats" OFF)
|
2019-08-13 17:37:54 +03:00
|
|
|
|
option(SNMALLOC_CI_BUILD "Disable features not sensible for CI" OFF)
|
2019-04-12 14:32:37 +03:00
|
|
|
|
option(EXPOSE_EXTERNAL_PAGEMAP "Expose the global pagemap" OFF)
|
|
|
|
|
option(EXPOSE_EXTERNAL_RESERVE "Expose an interface to reserve memory using the default memory provider" OFF)
|
2020-01-23 10:08:18 +03:00
|
|
|
|
option(SNMALLOC_RUST_SUPPORT "Build static library for rust" OFF)
|
2020-05-19 08:46:40 +03:00
|
|
|
|
option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON)
|
2020-03-19 15:37:44 +03:00
|
|
|
|
option(SNMALLOC_QEMU_WORKAROUND "Disable using madvise(DONT_NEED) to zero memory on Linux" Off)
|
2020-05-28 18:56:48 +03:00
|
|
|
|
option(SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE "Compile for current machine architecture" Off)
|
2019-02-12 22:08:31 +03:00
|
|
|
|
set(CACHE_FRIENDLY_OFFSET OFF CACHE STRING "Base offset to place linked-list nodes.")
|
2020-05-19 08:46:40 +03:00
|
|
|
|
set(SNMALLOC_STATIC_LIBRARY_PREFIX "sn_" CACHE STRING "Static library function prefix")
|
2019-02-12 22:08:31 +03:00
|
|
|
|
|
2021-01-11 17:06:51 +03:00
|
|
|
|
# malloc.h will error if you include it on FreeBSD, so this test must not
|
|
|
|
|
# unconditionally include it.
|
2020-04-18 09:58:13 +03:00
|
|
|
|
CHECK_C_SOURCE_COMPILES("
|
2021-01-11 17:06:51 +03:00
|
|
|
|
#if __has_include(<malloc_np.h>)
|
|
|
|
|
#include <malloc_np.h>
|
|
|
|
|
#if __has_include(<malloc/malloc.h>)
|
|
|
|
|
#include <malloc/malloc.h>
|
|
|
|
|
#else
|
2020-04-18 09:58:13 +03:00
|
|
|
|
#include <malloc.h>
|
2021-01-11 17:06:51 +03:00
|
|
|
|
#endif
|
2020-04-18 09:58:13 +03:00
|
|
|
|
size_t malloc_usable_size(const void* ptr) { return 0; }
|
|
|
|
|
int main() { return 0; }
|
|
|
|
|
" CONST_QUALIFIED_MALLOC_USABLE_SIZE)
|
|
|
|
|
|
2021-02-19 12:07:42 +03:00
|
|
|
|
if (NOT SNMALLOC_CI_BUILD)
|
2020-02-05 15:47:24 +03:00
|
|
|
|
option(USE_POSIX_COMMIT_CHECKS "Instrument Posix PAL to check for access to unused blocks of memory." Off)
|
|
|
|
|
else ()
|
2021-02-19 12:07:42 +03:00
|
|
|
|
# This is enabled in every bit of CI to detect errors.
|
2020-02-05 15:47:24 +03:00
|
|
|
|
option(USE_POSIX_COMMIT_CHECKS "Instrument Posix PAL to check for access to unused blocks of memory." On)
|
|
|
|
|
endif ()
|
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
# Provide as macro so other projects can reuse
|
|
|
|
|
macro(warnings_high)
|
|
|
|
|
if(MSVC)
|
|
|
|
|
# Force to always compile with W4
|
|
|
|
|
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
|
|
|
|
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
2019-01-15 17:17:55 +03:00
|
|
|
|
endif()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
add_compile_options(/WX /wd4127 /wd4324 /wd4201)
|
2019-02-19 15:34:53 +03:00
|
|
|
|
else()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2021-02-24 15:54:14 +03:00
|
|
|
|
add_compile_options(-Wsign-conversion -Wconversion)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endif ()
|
2019-07-25 22:06:03 +03:00
|
|
|
|
add_compile_options(-Wall -Wextra -Werror -Wundef)
|
2019-01-15 17:17:55 +03:00
|
|
|
|
endif()
|
|
|
|
|
endmacro()
|
|
|
|
|
|
2020-06-18 13:08:33 +03:00
|
|
|
|
macro(oe_simulate target)
|
2020-07-09 15:22:32 +03:00
|
|
|
|
target_compile_definitions(${target} PRIVATE SNMALLOC_USE_SMALL_CHUNKS)
|
2020-06-18 13:08:33 +03:00
|
|
|
|
endmacro()
|
|
|
|
|
|
2019-05-22 15:20:43 +03:00
|
|
|
|
macro(clangformat_targets)
|
|
|
|
|
# The clang-format tool is installed under a variety of different names. Try
|
2020-02-06 12:09:32 +03:00
|
|
|
|
# to find a sensible one. Only look for versions 9 explicitly - we don't
|
2020-01-30 23:31:20 +03:00
|
|
|
|
# know whether our clang-format file will work with newer versions of the
|
2020-02-06 12:09:32 +03:00
|
|
|
|
# tool. It does not work with older versions as AfterCaseLabel is not supported
|
|
|
|
|
# in earlier versions.
|
2020-01-30 23:31:20 +03:00
|
|
|
|
find_program(CLANG_FORMAT NAMES
|
2021-01-07 13:43:14 +03:00
|
|
|
|
clang-format90 clang-format-9)
|
2019-05-22 15:20:43 +03:00
|
|
|
|
|
|
|
|
|
# If we've found a clang-format tool, generate a target for it, otherwise emit
|
|
|
|
|
# a warning.
|
|
|
|
|
if (${CLANG_FORMAT} STREQUAL "CLANG_FORMAT-NOTFOUND")
|
|
|
|
|
message(WARNING "Not generating clangformat target, no clang-format tool found")
|
|
|
|
|
else ()
|
|
|
|
|
message(STATUS "Generating clangformat target using ${CLANG_FORMAT}")
|
2021-03-13 19:17:23 +03:00
|
|
|
|
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.cc src/*.h src/*.hh)
|
2020-09-02 14:41:09 +03:00
|
|
|
|
# clangformat does not yet understand concepts well; for the moment, don't
|
|
|
|
|
# ask it to format them. See https://reviews.llvm.org/D79773
|
2020-11-20 15:56:03 +03:00
|
|
|
|
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "src/[^/]*/[^/]*_concept\.h$")
|
2019-05-22 15:20:43 +03:00
|
|
|
|
add_custom_target(
|
|
|
|
|
clangformat
|
|
|
|
|
COMMAND ${CLANG_FORMAT}
|
|
|
|
|
-i
|
|
|
|
|
${ALL_SOURCE_FILES})
|
|
|
|
|
endif()
|
|
|
|
|
endmacro()
|
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
# The main target for snmalloc
|
|
|
|
|
add_library(snmalloc_lib INTERFACE)
|
|
|
|
|
target_include_directories(snmalloc_lib INTERFACE src/)
|
2020-01-24 16:17:45 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
find_package(Threads REQUIRED COMPONENTS snmalloc_lib)
|
|
|
|
|
target_link_libraries(snmalloc_lib INTERFACE ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
|
target_link_libraries(snmalloc_lib INTERFACE atomic)
|
|
|
|
|
endif()
|
2019-04-23 15:42:10 +03:00
|
|
|
|
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
2019-11-28 12:30:43 +03:00
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
2020-03-08 17:13:49 +03:00
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
2019-04-23 15:42:10 +03:00
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
|
|
|
|
# XXX elseif ARM?
|
|
|
|
|
endif()
|
2020-01-24 16:17:45 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if (WIN32)
|
2019-02-19 15:34:53 +03:00
|
|
|
|
set(WIN8COMPAT FALSE CACHE BOOL "Avoid Windows 10 APIs")
|
|
|
|
|
if (WIN8COMPAT)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DWINVER=0x0603)
|
|
|
|
|
message(STATUS "snmalloc: Avoiding Windows 10 APIs")
|
2019-02-19 15:34:53 +03:00
|
|
|
|
else()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
message(STATUS "snmalloc: Using Windows 10 APIs")
|
|
|
|
|
# VirtualAlloc2 is exposed by mincore.lib, not Kernel32.lib (as the
|
|
|
|
|
# documentation says)
|
|
|
|
|
target_link_libraries(snmalloc_lib INTERFACE mincore)
|
2019-01-17 21:23:06 +03:00
|
|
|
|
endif()
|
2019-01-15 17:17:55 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-01-24 16:17:45 +03:00
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2020-03-17 14:18:24 +03:00
|
|
|
|
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
|
2020-03-13 18:39:49 +03:00
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
2020-03-17 14:18:24 +03:00
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
|
|
|
|
|
target_compile_options(snmalloc_lib INTERFACE -mcx16)
|
2020-03-13 18:39:49 +03:00
|
|
|
|
endif()
|
2020-01-24 16:17:45 +03:00
|
|
|
|
endif ()
|
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
# Have to set this globally, as can't be set on an interface target.
|
2019-01-15 17:17:55 +03:00
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
|
|
|
|
|
if(USE_SNMALLOC_STATS)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DUSE_SNMALLOC_STATS)
|
2019-01-15 17:17:55 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-03-19 15:37:44 +03:00
|
|
|
|
if(SNMALLOC_QEMU_WORKAROUND)
|
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DSNMALLOC_QEMU_WORKAROUND)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-08-13 17:37:54 +03:00
|
|
|
|
if(SNMALLOC_CI_BUILD)
|
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DSNMALLOC_CI_BUILD)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-07-17 15:14:59 +03:00
|
|
|
|
if(CACHE_FRIENDLY_OFFSET)
|
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DCACHE_FRIENDLY_OFFSET=${CACHE_FRIENDLY_OFFSET})
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-02-05 15:47:24 +03:00
|
|
|
|
if(USE_POSIX_COMMIT_CHECKS)
|
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DUSE_POSIX_COMMIT_CHECKS)
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-04-18 09:58:13 +03:00
|
|
|
|
if(CONST_QUALIFIED_MALLOC_USABLE_SIZE)
|
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DMALLOC_USABLE_SIZE_QUALIFIER=const)
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-02-05 15:47:24 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
# To build with just the header library target define SNMALLOC_ONLY_HEADER_LIBRARY
|
|
|
|
|
# in containing Cmake file.
|
|
|
|
|
if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY)
|
2019-01-15 17:17:55 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
warnings_high()
|
2019-02-19 00:29:32 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
if(MSVC)
|
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
|
|
|
|
|
else()
|
2020-06-30 13:01:49 +03:00
|
|
|
|
add_compile_options(-fno-exceptions -fno-rtti -g -fomit-frame-pointer)
|
2020-09-11 19:52:22 +03:00
|
|
|
|
# Static TLS model is unsupported on Haiku.
|
|
|
|
|
# All symbols are always dynamic on haiku and -rdynamic is redundant (and unsupported).
|
2020-06-30 13:01:49 +03:00
|
|
|
|
if (NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
|
|
|
|
add_compile_options(-ftls-model=initial-exec)
|
2020-09-11 19:52:22 +03:00
|
|
|
|
if(SNMALLOC_CI_BUILD OR (${CMAKE_BUILD_TYPE} MATCHES "Debug"))
|
|
|
|
|
# Get better stack traces in CI and Debug.
|
|
|
|
|
target_link_libraries(snmalloc_lib INTERFACE "-rdynamic")
|
|
|
|
|
endif()
|
2020-04-07 17:37:26 +03:00
|
|
|
|
endif()
|
2020-03-20 12:17:38 +03:00
|
|
|
|
|
2020-05-28 18:56:48 +03:00
|
|
|
|
if(SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE)
|
2020-03-20 12:17:38 +03:00
|
|
|
|
check_cxx_compiler_flag(-march=native SUPPORT_MARCH_NATIVE)
|
|
|
|
|
if (SUPPORT_MARCH_NATIVE)
|
|
|
|
|
add_compile_options(-march=native)
|
2020-05-28 18:56:48 +03:00
|
|
|
|
else()
|
|
|
|
|
message(WARNING "Compiler does not support `-march=native` required by SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE")
|
2020-03-20 12:17:38 +03:00
|
|
|
|
endif()
|
2019-04-23 15:42:10 +03:00
|
|
|
|
endif()
|
2020-05-16 14:45:51 +03:00
|
|
|
|
|
|
|
|
|
find_package(Backtrace)
|
|
|
|
|
if(${Backtrace_FOUND})
|
|
|
|
|
target_compile_definitions(snmalloc_lib INTERFACE -DBACKTRACE_HEADER="${Backtrace_HEADER}")
|
|
|
|
|
target_link_libraries(snmalloc_lib INTERFACE ${Backtrace_LIBRARIES})
|
|
|
|
|
target_include_directories(snmalloc_lib INTERFACE ${Backtrace_INCLUD_DIRS})
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-02-19 00:29:32 +03:00
|
|
|
|
endif()
|
2019-04-12 14:32:37 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
macro(subdirlist result curdir)
|
|
|
|
|
file(GLOB children LIST_DIRECTORIES true RELATIVE ${curdir} ${curdir}/*)
|
|
|
|
|
set(dirlist "")
|
|
|
|
|
foreach(child ${children})
|
|
|
|
|
if(IS_DIRECTORY ${curdir}/${child})
|
|
|
|
|
list(APPEND dirlist ${child})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${result} ${dirlist})
|
|
|
|
|
endmacro()
|
2019-01-15 17:17:55 +03:00
|
|
|
|
|
2020-01-23 10:08:18 +03:00
|
|
|
|
macro(add_shim name type)
|
|
|
|
|
add_library(${name} ${type} ${ARGN})
|
2019-05-09 14:32:32 +03:00
|
|
|
|
target_link_libraries(${name} snmalloc_lib)
|
2020-01-23 10:08:18 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
target_compile_definitions(${name} PRIVATE "SNMALLOC_EXPORT=__attribute__((visibility(\"default\")))")
|
|
|
|
|
endif()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
set_target_properties(${name} PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
2019-02-12 01:16:47 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
if(EXPOSE_EXTERNAL_PAGEMAP)
|
2020-01-23 10:08:18 +03:00
|
|
|
|
if(MSVC)
|
|
|
|
|
target_compile_definitions(${name} PRIVATE /DSNMALLOC_EXPOSE_PAGEMAP)
|
|
|
|
|
else()
|
|
|
|
|
target_compile_definitions(${name} PRIVATE -DSNMALLOC_EXPOSE_PAGEMAP)
|
|
|
|
|
endif()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(EXPOSE_EXTERNAL_RESERVE)
|
2020-01-23 10:08:18 +03:00
|
|
|
|
if(MSVC)
|
|
|
|
|
target_compile_definitions(${name} PRIVATE /DSNMALLOC_EXPOSE_RESERVE)
|
|
|
|
|
else()
|
|
|
|
|
target_compile_definitions(${name} PRIVATE -DSNMALLOC_EXPOSE_RESERVE)
|
|
|
|
|
endif()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endif()
|
2019-11-14 18:40:05 +03:00
|
|
|
|
|
|
|
|
|
# Ensure that we do not link against C++ stdlib when compiling shims.
|
2020-01-23 10:08:18 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
|
|
|
|
|
endif()
|
2019-11-14 18:40:05 +03:00
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endmacro()
|
|
|
|
|
|
2020-05-19 08:46:40 +03:00
|
|
|
|
if (SNMALLOC_STATIC_LIBRARY)
|
|
|
|
|
add_shim(snmallocshim-static STATIC src/override/malloc.cc)
|
|
|
|
|
add_shim(snmallocshim-1mib-static STATIC src/override/malloc.cc)
|
2020-07-09 15:22:32 +03:00
|
|
|
|
add_shim(snmallocshim-16mib-static STATIC src/override/malloc.cc)
|
|
|
|
|
target_compile_definitions(snmallocshim-16mib-static PRIVATE SNMALLOC_USE_LARGE_CHUNKS
|
2020-05-19 08:46:40 +03:00
|
|
|
|
SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX})
|
|
|
|
|
target_compile_definitions(snmallocshim-static PRIVATE
|
|
|
|
|
SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX})
|
2020-07-09 15:22:32 +03:00
|
|
|
|
target_compile_definitions(snmallocshim-1mib-static PRIVATE
|
|
|
|
|
SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX})
|
2020-05-19 08:46:40 +03:00
|
|
|
|
endif ()
|
|
|
|
|
|
2020-01-24 16:17:45 +03:00
|
|
|
|
if(NOT WIN32)
|
2020-01-23 10:08:18 +03:00
|
|
|
|
set(SHARED_FILES src/override/new.cc src/override/malloc.cc)
|
|
|
|
|
add_shim(snmallocshim SHARED ${SHARED_FILES})
|
2021-03-13 23:46:49 +03:00
|
|
|
|
add_shim(snmallocshim-checks SHARED ${SHARED_FILES})
|
2020-01-23 10:08:18 +03:00
|
|
|
|
add_shim(snmallocshim-1mib SHARED ${SHARED_FILES})
|
2020-07-09 15:22:32 +03:00
|
|
|
|
add_shim(snmallocshim-16mib SHARED ${SHARED_FILES})
|
2020-10-12 14:16:27 +03:00
|
|
|
|
target_compile_definitions(snmallocshim-16mib PRIVATE SNMALLOC_USE_LARGE_CHUNKS)
|
2021-03-13 23:46:49 +03:00
|
|
|
|
target_compile_definitions(snmallocshim-checks PRIVATE CHECK_CLIENT)
|
2020-06-18 13:08:33 +03:00
|
|
|
|
# Build a shim with some settings from oe.
|
|
|
|
|
add_shim(snmallocshim-oe SHARED ${SHARED_FILES})
|
|
|
|
|
oe_simulate(snmallocshim-oe)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-01-23 10:08:18 +03:00
|
|
|
|
if(SNMALLOC_RUST_SUPPORT)
|
|
|
|
|
add_shim(snmallocshim-rust STATIC src/override/rust.cc)
|
|
|
|
|
add_shim(snmallocshim-1mib-rust STATIC src/override/rust.cc)
|
2020-07-09 15:22:32 +03:00
|
|
|
|
add_shim(snmallocshim-16mib-rust STATIC src/override/rust.cc)
|
|
|
|
|
target_compile_definitions(snmallocshim-16mib-rust PRIVATE SNMALLOC_USE_LARGE_CHUNKS)
|
2020-01-23 10:08:18 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2019-05-09 14:32:32 +03:00
|
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
|
|
set(TESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/test)
|
|
|
|
|
subdirlist(TEST_CATEGORIES ${TESTDIR})
|
|
|
|
|
list(REVERSE TEST_CATEGORIES)
|
|
|
|
|
foreach(TEST_CATEGORY ${TEST_CATEGORIES})
|
|
|
|
|
subdirlist(TESTS ${TESTDIR}/${TEST_CATEGORY})
|
|
|
|
|
foreach(TEST ${TESTS})
|
2020-09-28 12:08:19 +03:00
|
|
|
|
if (WIN32
|
|
|
|
|
OR (CMAKE_SYSTEM_NAME STREQUAL NetBSD)
|
2020-10-02 20:15:28 +03:00
|
|
|
|
OR (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
|
2020-11-18 20:13:21 +03:00
|
|
|
|
OR (CMAKE_SYSTEM_NAME STREQUAL DragonFly)
|
|
|
|
|
OR (CMAKE_SYSTEM_NAME STREQUAL SunOS))
|
2020-09-28 12:08:19 +03:00
|
|
|
|
# Windows does not support aligned allocation well enough
|
|
|
|
|
# for pass through.
|
2020-10-02 20:15:28 +03:00
|
|
|
|
# NetBSD, OpenBSD and DragonFlyBSD do not support malloc*size calls.
|
2020-09-28 12:08:19 +03:00
|
|
|
|
set(FLAVOURS 1;16;oe)
|
|
|
|
|
else()
|
|
|
|
|
set(FLAVOURS 1;16;oe;malloc)
|
|
|
|
|
endif()
|
|
|
|
|
foreach(SUPER_SLAB_SIZE ${FLAVOURS})
|
2019-05-09 14:32:32 +03:00
|
|
|
|
unset(SRC)
|
|
|
|
|
aux_source_directory(${TESTDIR}/${TEST_CATEGORY}/${TEST} SRC)
|
|
|
|
|
set(TESTNAME "${TEST_CATEGORY}-${TEST}-${SUPER_SLAB_SIZE}")
|
|
|
|
|
|
2019-08-13 12:56:54 +03:00
|
|
|
|
add_executable(${TESTNAME} ${SRC})
|
2021-02-19 12:07:42 +03:00
|
|
|
|
|
|
|
|
|
# For all tests enable commit checking.
|
|
|
|
|
target_compile_definitions(${TESTNAME} PRIVATE -DUSE_POSIX_COMMIT_CHECKS)
|
|
|
|
|
|
2020-07-09 15:22:32 +03:00
|
|
|
|
if (${SUPER_SLAB_SIZE} EQUAL 16)
|
|
|
|
|
target_compile_definitions(${TESTNAME} PRIVATE SNMALLOC_USE_LARGE_CHUNKS)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endif()
|
2020-09-28 12:08:19 +03:00
|
|
|
|
if (${SUPER_SLAB_SIZE} STREQUAL "oe")
|
2020-06-18 13:08:33 +03:00
|
|
|
|
oe_simulate(${TESTNAME})
|
|
|
|
|
endif()
|
2020-09-28 12:08:19 +03:00
|
|
|
|
if (${SUPER_SLAB_SIZE} STREQUAL "malloc")
|
|
|
|
|
target_compile_definitions(${TESTNAME} PRIVATE SNMALLOC_PASS_THROUGH)
|
|
|
|
|
endif()
|
2021-01-11 17:06:51 +03:00
|
|
|
|
if(CONST_QUALIFIED_MALLOC_USABLE_SIZE)
|
|
|
|
|
target_compile_definitions(${TESTNAME} PRIVATE -DMALLOC_USABLE_SIZE_QUALIFIER=const)
|
|
|
|
|
endif()
|
2019-06-12 17:04:25 +03:00
|
|
|
|
target_link_libraries(${TESTNAME} snmalloc_lib)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
if (${TEST} MATCHES "release-.*")
|
|
|
|
|
message(STATUS "Adding test: ${TESTNAME} only for release configs")
|
|
|
|
|
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME} CONFIGURATIONS "Release")
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Adding test: ${TESTNAME}")
|
|
|
|
|
add_test(${TESTNAME} ${TESTNAME})
|
|
|
|
|
endif()
|
|
|
|
|
if (${TEST_CATEGORY} MATCHES "perf")
|
2019-08-14 16:21:35 +03:00
|
|
|
|
message(STATUS "Single threaded test: ${TESTNAME}")
|
2019-07-05 15:03:58 +03:00
|
|
|
|
set_tests_properties(${TESTNAME} PROPERTIES PROCESSORS 4)
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endif()
|
2020-01-24 16:17:45 +03:00
|
|
|
|
if(WIN32)
|
2019-08-14 16:21:35 +03:00
|
|
|
|
# On Windows these tests use a lot of memory as it doesn't support
|
|
|
|
|
# lazy commit.
|
|
|
|
|
if (${TEST} MATCHES "two_alloc_types")
|
|
|
|
|
message(STATUS "Single threaded test: ${TESTNAME}")
|
|
|
|
|
set_tests_properties(${TESTNAME} PROPERTIES PROCESSORS 4)
|
|
|
|
|
endif()
|
|
|
|
|
if (${TEST} MATCHES "fixed_region")
|
|
|
|
|
message(STATUS "Single threaded test: ${TESTNAME}")
|
|
|
|
|
set_tests_properties(${TESTNAME} PROPERTIES PROCESSORS 4)
|
|
|
|
|
endif()
|
|
|
|
|
if (${TEST} MATCHES "memory")
|
|
|
|
|
message(STATUS "Single threaded test: ${TESTNAME}")
|
|
|
|
|
set_tests_properties(${TESTNAME} PROPERTIES PROCESSORS 4)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2019-08-11 09:54:09 +03:00
|
|
|
|
if (${TEST_CATEGORY} MATCHES "func")
|
|
|
|
|
target_compile_definitions(${TESTNAME} PRIVATE -DUSE_SNMALLOC_STATS)
|
|
|
|
|
endif ()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
endforeach()
|
2019-01-21 20:53:52 +03:00
|
|
|
|
endforeach()
|
2019-01-15 17:17:55 +03:00
|
|
|
|
endforeach()
|
2019-05-09 14:32:32 +03:00
|
|
|
|
|
2019-05-22 15:20:43 +03:00
|
|
|
|
clangformat_targets()
|
2019-05-18 13:54:35 +03:00
|
|
|
|
endif()
|