Support build with mimalloc (#348)

* Support build with mimalloc

* Use latest stable tag
This commit is contained in:
Dmitry Atamanov
2022-01-07 23:18:25 +05:00
committed by GitHub
parent a176ae353b
commit d942dfbc99

View File

@@ -1,11 +1,30 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(c3c) project(c3c)
include(FetchContent)
include(FeatureSummary) include(FeatureSummary)
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL) set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC) set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
set(C3_LLVM_VERSION "auto" CACHE STRING "Use LLVM version [default: auto]") set(C3_LLVM_VERSION "auto" CACHE STRING "Use LLVM version [default: auto]")
option(C3_USE_MIMALLOC "Use built-in mimalloc" ON)
set(C3_MIMALLOC_TAG "v1.7.3" CACHE STRING "Used version of mimalloc")
if(WIN32)
set(C3_USE_MIMALLOC OFF)
endif()
if(C3_USE_MIMALLOC)
option(MI_BUILD_TESTS OFF)
option(MI_BUILD_SHARED OFF)
option(MI_PADDING OFF)
option(MI_DEBUG_FULL OFF)
FetchContent_Declare(
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
GIT_TAG ${C3_MIMALLOC_TAG}
)
FetchContent_MakeAvailable(mimalloc)
endif()
if(NOT C3_LLVM_VERSION STREQUAL "auto") if(NOT C3_LLVM_VERSION STREQUAL "auto")
if(${C3_LLVM_VERSION} VERSION_LESS 12 OR ${C3_LLVM_VERSION} VERSION_GREATER 14) if(${C3_LLVM_VERSION} VERSION_LESS 12 OR ${C3_LLVM_VERSION} VERSION_GREATER 14)
@@ -192,6 +211,9 @@ if(UNIX)
target_link_libraries(c3c_wrappers ${llvm_libs} ${lld_libs}) target_link_libraries(c3c_wrappers ${llvm_libs} ${lld_libs})
target_link_libraries(c3c m ${llvm_libs} c3c_wrappers ${lld_libs}) target_link_libraries(c3c m ${llvm_libs} c3c_wrappers ${lld_libs})
# target_link_libraries(c3c m ${llvm_libs} c3c_wrappers ${TB_LIB} ${lld_libs}) # target_link_libraries(c3c m ${llvm_libs} c3c_wrappers ${TB_LIB} ${lld_libs})
if(C3_USE_MIMALLOC)
target_link_libraries(c3c m mimalloc-static)
endif()
else() else()
# todo: maybe get this from llvm-config somehow? it should be in LLVM_DIR\..\..\..\bin I think. # todo: maybe get this from llvm-config somehow? it should be in LLVM_DIR\..\..\..\bin I think.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -LIBPATH:C:\\llvm\\llvm\\build\\Release\\lib") # needed for lldCommon.lib set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -LIBPATH:C:\\llvm\\llvm\\build\\Release\\lib") # needed for lldCommon.lib