[mimalloc] Add new port (fix #6996) (#7011)

* [mimalloc] Add new port (fix #6996)

* [mimalloc] Fix x64-uwp build error

* [mimalloc] Fix interface include directory

* [mimalloc] Add features

* [mimalloc] Make the patch vcpkg friendly

* [mimalloc] Update to 2019-06-25

* [mimalloc] Use vcpkg_check_features

* [mimalloc] Clean
This commit is contained in:
myd7349 2019-07-23 02:16:02 +08:00 committed by Victor Romero
parent 126812d18b
commit 3c418f814d
4 changed files with 147 additions and 0 deletions

13
ports/mimalloc/CONTROL Normal file
View File

@ -0,0 +1,13 @@
Source: mimalloc
Version: 2019-06-25
Description: Compact general purpose allocator with excellent performance
Homepage: https://github.com/microsoft/mimalloc
Feature: asm
Description: Generate assembly files
Feature: override
Description: Override the standard malloc interface
Feature: secure
Description: Use security mitigations (like guard pages and randomization)

View File

@ -0,0 +1,52 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a35e885..76b6f60 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -105,7 +105,7 @@ else()
list(APPEND mi_libraries pthread)
endif()
-
+if(BUILD_SHARED_LIBS)
# shared library
add_library(mimalloc SHARED ${mi_sources})
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} NO_SONAME "YES" OUTPUT_NAME ${mi_basename} )
@@ -116,7 +116,7 @@ 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})
-
+else()
# static library
add_library(mimalloc-static STATIC ${mi_sources})
if(WIN32)
@@ -135,15 +135,18 @@ 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})
+endif()
# install static and shared library, and the include files
-install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_dir} LIBRARY NAMELINK_SKIP)
-install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_dir})
+if(BUILD_SHARED_LIBS)
+install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION lib RUNTIME DESTINATION bin LIBRARY DESTINATION lib NAMELINK_SKIP)
+else()
+install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION lib)
+endif()
install(FILES include/mimalloc.h DESTINATION ${mi_install_dir}/include)
install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_dir}/cmake)
install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_dir}/cmake)
install(EXPORT mimalloc DESTINATION ${mi_install_dir}/cmake)
-install(FILES "$<TARGET_FILE:mimalloc>" DESTINATION lib) # duplicate the .so in the lib directory (unversioned)
# single object file for more predictable static overriding
add_library(mimalloc-obj OBJECT src/static.c)
@@ -154,7 +157,3 @@ if(NOT WIN32 AND MI_OVERRIDE MATCHES "ON")
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} )

View File

@ -0,0 +1,73 @@
include(vcpkg_common_functions)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO microsoft/mimalloc
REF c6c1d5fffd0cf8dcb2ab969cde8fd170af44fdef
SHA512 3b9ce5d7dd70dd5ea56b70833c842068312a739e6131d956fd733e9893441e7e3340b6734bea0b799ac292533b0082975c08facd963961062dac821ccc44f9a9
HEAD_REF master
PATCHES
fix-cmake.patch
)
vcpkg_check_features(
asm MI_SEE_ASM
secure MI_SECURE
override MI_OVERRIDE
)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS_DEBUG
-DMI_CHECK_FULL=ON
OPTIONS_RELEASE
-DMI_CHECK_FULL=OFF
OPTIONS
-DMI_OVERRIDE=${MI_OVERRIDE}
-DMI_INTERPOSE=ON
-DMI_SEE_ASM=${MI_SEE_ASM}
-DMI_USE_CXX=OFF
-DMI_SECURE=${MI_SECURE}
)
vcpkg_install_cmake()
vcpkg_copy_pdbs()
file(GLOB lib_directories RELATIVE ${CURRENT_PACKAGES_DIR}/lib "${CURRENT_PACKAGES_DIR}/lib/${PORT}-*")
list(GET lib_directories 0 lib_install_dir)
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/${lib_install_dir}/cmake)
vcpkg_replace_string(
${CURRENT_PACKAGES_DIR}/share/${PORT}/mimalloc.cmake
"lib/${lib_install_dir}/"
""
)
file(COPY
${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)
file(COPY ${CURRENT_PACKAGES_DIR}/lib/${lib_install_dir}/include DESTINATION ${CURRENT_PACKAGES_DIR})
file(REMOVE_RECURSE
${CURRENT_PACKAGES_DIR}/debug/lib/${lib_install_dir}
${CURRENT_PACKAGES_DIR}/debug/share
${CURRENT_PACKAGES_DIR}/lib/${lib_install_dir}
)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
vcpkg_replace_string(
${CURRENT_PACKAGES_DIR}/include/mimalloc.h
"!defined(MI_SHARED_LIB)"
"0 // !defined(MI_SHARED_LIB)"
)
endif()
# Handle copyright
configure_file(${SOURCE_PATH}/LICENSE ${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright COPYONLY)
# CMake integration test
vcpkg_test_cmake(PACKAGE_NAME ${PORT})

View File

@ -0,0 +1,9 @@
_find_package(${ARGS})
if(TARGET mimalloc AND NOT TARGET mimalloc-static)
add_library(mimalloc-static INTERFACE IMPORTED)
set_target_properties(mimalloc-static PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc)
elseif(TARGET mimalloc-static AND NOT TARGET mimalloc)
add_library(mimalloc INTERFACE IMPORTED)
set_target_properties(mimalloc PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc-static)
endif()