2019-06-20 02:26:12 +03:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
|
|
|
project(mimalloc-test C CXX)
|
|
|
|
|
2021-11-15 02:32:21 +03:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
2019-06-20 02:26:12 +03:00
|
|
|
# Set default build type
|
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
|
|
|
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")
|
|
|
|
message(STATUS "No build type selected, default to *** Debug ***")
|
|
|
|
set(CMAKE_BUILD_TYPE "Debug")
|
|
|
|
else()
|
|
|
|
message(STATUS "No build type selected, default to *** Release ***")
|
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Import mimalloc (if installed)
|
2021-02-01 00:51:19 +03:00
|
|
|
find_package(mimalloc 1.7 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
|
2021-12-15 19:33:14 +03:00
|
|
|
message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR} (${MIMALLOC_VERSION_DIR})")
|
2019-06-20 02:26:12 +03:00
|
|
|
|
2019-07-23 02:11:06 +03:00
|
|
|
# overriding with a dynamic library
|
2019-06-20 02:26:12 +03:00
|
|
|
add_executable(dynamic-override main-override.c)
|
|
|
|
target_link_libraries(dynamic-override PUBLIC mimalloc)
|
|
|
|
|
|
|
|
add_executable(dynamic-override-cxx main-override.cpp)
|
|
|
|
target_link_libraries(dynamic-override-cxx PUBLIC mimalloc)
|
2019-07-08 23:37:41 +03:00
|
|
|
|
2019-07-23 02:11:06 +03:00
|
|
|
|
2019-07-22 11:36:16 +03:00
|
|
|
# overriding with a static object file works reliable as the symbols in the
|
|
|
|
# object file have priority over those in library files
|
2021-12-15 05:29:14 +03:00
|
|
|
add_executable(static-override-obj main-override.c ${MIMALLOC_OBJECT_DIR}/mimalloc.o)
|
2021-05-22 01:15:50 +03:00
|
|
|
target_include_directories(static-override-obj PUBLIC ${MIMALLOC_INCLUDE_DIR})
|
2019-07-22 11:36:16 +03:00
|
|
|
target_link_libraries(static-override-obj PUBLIC pthread)
|
|
|
|
|
2019-07-23 02:11:06 +03:00
|
|
|
|
2019-07-22 11:36:16 +03:00
|
|
|
# overriding with a static library works too if using the `mimalloc-override.h`
|
2019-07-23 02:11:06 +03:00
|
|
|
# header to redefine malloc/free. (the library already overrides new/delete)
|
2019-07-22 11:36:16 +03:00
|
|
|
add_executable(static-override-static main-override-static.c)
|
|
|
|
target_link_libraries(static-override-static PUBLIC mimalloc-static)
|
|
|
|
|
|
|
|
|
|
|
|
# overriding with a static library: this may not work if the library is linked too late
|
2019-07-23 02:11:06 +03:00
|
|
|
# on the command line after the C runtime library; but we cannot control that well in CMake
|
2019-07-08 23:37:41 +03:00
|
|
|
add_executable(static-override main-override.c)
|
|
|
|
target_link_libraries(static-override PUBLIC mimalloc-static)
|
|
|
|
|
|
|
|
add_executable(static-override-cxx main-override.cpp)
|
|
|
|
target_link_libraries(static-override-cxx PUBLIC mimalloc-static)
|