mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-07 11:58:41 +03:00
This commit is contained in:
parent
4c87643c29
commit
ae47a2b13e
5 changed files with 224 additions and 14 deletions
|
@ -106,14 +106,15 @@ else()
|
|||
list(APPEND mi_libraries pthread)
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Main targets
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
# shared library
|
||||
add_library(mimalloc SHARED ${mi_sources})
|
||||
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} NO_SONAME "YES" OUTPUT_NAME ${mi_basename} )
|
||||
target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
|
||||
if(MI_OVERRIDE MATCHES "ON")
|
||||
target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE)
|
||||
endif()
|
||||
target_compile_options(mimalloc PRIVATE ${mi_cflags})
|
||||
target_include_directories(mimalloc PRIVATE include PUBLIC $<INSTALL_INTERFACE:${mi_install_dir}/include>)
|
||||
target_link_libraries(mimalloc PUBLIC ${mi_libraries})
|
||||
|
@ -129,10 +130,6 @@ else()
|
|||
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
|
||||
endif()
|
||||
target_compile_definitions(mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
|
||||
if(NOT WIN32 AND MI_OVERRIDE MATCHES "ON")
|
||||
# It is only possible to override malloc on Windows when building as a DLL. (src/alloc-override.c)
|
||||
target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
|
||||
endif()
|
||||
target_compile_options(mimalloc-static PRIVATE ${mi_cflags})
|
||||
target_include_directories(mimalloc-static PRIVATE include PUBLIC $<INSTALL_INTERFACE:${mi_install_dir}/include>)
|
||||
target_link_libraries(mimalloc-static PUBLIC ${mi_libraries})
|
||||
|
@ -149,13 +146,35 @@ install(FILES "$<TARGET_FILE:mimalloc>" DESTINATION lib) # duplicate the .so in
|
|||
# single object file for more predictable static overriding
|
||||
add_library(mimalloc-obj OBJECT src/static.c)
|
||||
target_compile_definitions(mimalloc-obj PRIVATE ${mi_defines})
|
||||
if(NOT WIN32 AND MI_OVERRIDE MATCHES "ON")
|
||||
# It is only possible to override malloc on Windows when building as a DLL. (src/alloc-override.c)
|
||||
target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
|
||||
endif()
|
||||
target_compile_options(mimalloc-obj PRIVATE ${mi_cflags})
|
||||
target_include_directories(mimalloc-obj PRIVATE include PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION}
|
||||
DESTINATION ${mi_install_dir}
|
||||
RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} )
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# API surface testing
|
||||
# -----------------------------------------------------------------------------
|
||||
add_executable(mimalloc-test test/test-api.c)
|
||||
target_compile_definitions(mimalloc-test PRIVATE ${mi_defines})
|
||||
target_compile_options(mimalloc-test PRIVATE ${mi_cflags})
|
||||
target_include_directories(mimalloc-test PRIVATE include)
|
||||
target_link_libraries(mimalloc-test PRIVATE mimalloc-static)
|
||||
|
||||
enable_testing()
|
||||
add_test(test_api, mimalloc-test)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Set override properties
|
||||
# -----------------------------------------------------------------------------
|
||||
if (MI_OVERRIDE MATCHES "ON")
|
||||
target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE)
|
||||
if(NOT WIN32)
|
||||
# It is only possible to override malloc on Windows when building as a DLL. (src/alloc-override.c)
|
||||
target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
|
||||
target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
|
||||
target_compile_definitions(mimalloc-test PRIVATE MI_MALLOC_OVERRIDE)
|
||||
endif()
|
||||
endif()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue