diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake deleted file mode 100644 index 9050290d5..000000000 --- a/cmake/FindJemalloc.cmake +++ /dev/null @@ -1,103 +0,0 @@ -# Try to find jemalloc library -# -# Use this module as: -# find_package(Jemalloc) -# -# or: -# find_package(Jemalloc REQUIRED) -# -# This will define the following variables: -# -# Jemalloc_FOUND True if the system has the jemalloc library. -# Jemalloc_INCLUDE_DIRS Include directories needed to use jemalloc. -# Jemalloc_LIBRARIES Libraries needed to link to jemalloc. -# -# The following cache variables may also be set: -# -# Jemalloc_INCLUDE_DIR The directory containing jemalloc/jemalloc.h. -# Jemalloc_LIBRARY The path to the jemalloc static library. - -#find_path(Jemalloc_INCLUDE_DIR NAMES jemalloc/jemalloc.h PATH_SUFFIXES include) - -#find_library(Jemalloc_LIBRARY NAMES libjemalloc.a PATH_SUFFIXES lib) - -if(Jemalloc_INCLUDE_DIR) - message(STATUS "find jemalloc: ${Jemalloc_INCLUDE_DIR}") -else() - message(WARNING "find jemalloc not found!") -endif() - -# Check and print where libjemalloc.a was found -if(Jemalloc_LIBRARY) - message(STATUS "find jemalloc: libjemalloc.a found at: ${Jemalloc_LIBRARY}") -else() - message(WARNING "libjemalloc.a not found!") -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Jemalloc - FOUND_VAR Jemalloc_FOUND - REQUIRED_VARS - Jemalloc_LIBRARY - Jemalloc_INCLUDE_DIR -) - - - -message(STATUS "JEMALLOC FOUND ${Jemalloc_FOUND}") - - - -if(Jemalloc_FOUND) - set(Jemalloc_LIBRARIES ${Jemalloc_LIBRARY}) - set(Jemalloc_INCLUDE_DIRS ${Jemalloc_INCLUDE_DIR}) -else() - if(Jemalloc_FIND_REQUIRED) - message(FATAL_ERROR "Cannot find jemalloc!") - else() - message(WARNING "jemalloc is not found!") - endif() -endif() - -if(Jemalloc_FOUND AND NOT TARGET Jemalloc::Jemalloc) - message(STATUS "JEMALLOC NOT TARGET") - - add_library(Jemalloc::Jemalloc UNKNOWN IMPORTED) - set_target_properties(Jemalloc::Jemalloc - PROPERTIES - IMPORTED_LOCATION "${Jemalloc_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${Jemalloc_INCLUDE_DIR}" - ) -endif() - -mark_as_advanced( - Jemalloc_INCLUDE_DIR - Jemalloc_LIBRARY -) - -# set(JEMALLOC_ROOT "/opt/toolchain-vExperiment/") - -# message(STATUS "Using JEMALLOC_ROOT: ${JEMALLOC_ROOT}") - -# find_path(Jemalloc_INCLUDE_DIR -# NAMES jemalloc/jemalloc.h -# HINTS "${JEMALLOC_ROOT}/include" -# NO_DEFAULT_PATH) - -# find_library(Jemalloc_LIBRARY -# NAMES libjemalloc.a -# HINTS "${JEMALLOC_ROOT}/lib" -# NO_DEFAULT_PATH) - -# if(Jemalloc_INCLUDE_DIR) -# message(STATUS "jemalloc.h found at: ${Jemalloc_INCLUDE_DIR}") -# else() -# message(WARNING "jemalloc.h not found!") -# endif() - -# # Check and print where libjemalloc.a was found -# if(Jemalloc_LIBRARY) -# message(STATUS "libjemalloc.a found at: ${Jemalloc_LIBRARY}") -# else() -# message(WARNING "libjemalloc.a not found!") -# endif() diff --git a/cmake/Findjemalloc.cmake b/cmake/Findjemalloc.cmake new file mode 100644 index 000000000..1e24f0f30 --- /dev/null +++ b/cmake/Findjemalloc.cmake @@ -0,0 +1,67 @@ +# Try to find jemalloc library +# +# Use this module as: +# find_package(jemalloc) +# +# or: +# find_package(jemalloc REQUIRED) +# +# This will define the following variables: +# +# JEMALLOC_FOUND True if the system has the jemalloc library. +# Jemalloc_INCLUDE_DIRS Include directories needed to use jemalloc. +# Jemalloc_LIBRARIES Libraries needed to link to jemalloc. +# +# The following cache variables may also be set: +# +# Jemalloc_INCLUDE_DIR The directory containing jemalloc/jemalloc.h. +# Jemalloc_LIBRARY The path to the jemalloc static library. + + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(jemalloc + FOUND_VAR JEMALLOC_FOUND + REQUIRED_VARS + JEMALLOC_LIBRARY + JEMALLOC_INCLUDE_DIR +) + +if(JEMALLOC_INCLUDE_DIR) + message(STATUS "Found jemalloc include dir: ${JEMALLOC_INCLUDE_DIR}") +else() + message(WARNING "jemalloc not found!") +endif() + +if(JEMALLOC_LIBRARY) + message(STATUS "Found jemalloc library: ${JEMALLOC_LIBRARY}") +else() + message(WARNING "jemalloc library not found!") +endif() + +if(JEMALLOC_FOUND) + set(Jemalloc_LIBRARIES ${JEMALLOC_LIBRARY}) + set(Jemalloc_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) +else() + if(Jemalloc_FIND_REQUIRED) + message(FATAL_ERROR "Cannot find jemalloc!") + else() + message(WARNING "jemalloc is not found!") + endif() +endif() + +if(JEMALLOC_FOUND AND NOT TARGET Jemalloc::Jemalloc) + message(STATUS "JEMALLOC NOT TARGET") + + add_library(Jemalloc::Jemalloc UNKNOWN IMPORTED) + set_target_properties(Jemalloc::Jemalloc + PROPERTIES + IMPORTED_LOCATION "${JEMALLOC_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${JEMALLOC_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + JEMALLOC_INCLUDE_DIR + JEMALLOC_LIBRARY +) diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index a4c51e57d..411b180ab 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -15,7 +15,6 @@ set(GFLAGS_NOTHREADS OFF) # NOTE: config/generate.py depends on the gflags help XML format. find_package(gflags REQUIRED) find_package(fmt 8.0.1) -#find_package(Jemalloc REQUIRED) find_package(ZLIB 1.2.11 REQUIRED) set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}) @@ -100,14 +99,14 @@ macro(import_external_library name type library_location include_dir) endmacro(import_external_library) -macro(jemalloc_external_library name type library_location include_dir) +macro(set_path_external_library name type library_location include_dir) string(TOUPPER ${name} _upper_name) - set(${name}_LIBRARY ${library_location} CACHE FILEPATH + set(${_upper_name}_LIBRARY ${library_location} CACHE FILEPATH "Path to ${name} library" FORCE) - set(${name}_INCLUDE_DIR ${include_dir} CACHE FILEPATH + set(${_upper_name}_INCLUDE_DIR ${include_dir} CACHE FILEPATH "Path to ${name} include directory" FORCE) mark_as_advanced(${name}_LIBRARY ${name}_INCLUDE_DIR) -endmacro(jemalloc_external_library) +endmacro(set_path_external_library) # setup antlr @@ -277,22 +276,7 @@ import_header_library(ctre ${CMAKE_CURRENT_SOURCE_DIR}) set(ABSL_PROPAGATE_CXX_STD ON) add_subdirectory(absl EXCLUDE_FROM_ALL) -# set jemalloc -jemalloc_external_library(Jemalloc STATIC - ${CMAKE_CURRENT_SOURCE_DIR}/Jemalloc/lib/libjemalloc.a - ${CMAKE_CURRENT_SOURCE_DIR}/Jemalloc/include/) - -message(STATUS "jemalloc.h searched in: ${CMAKE_CURRENT_SOURCE_DIR}") - -if(Jemalloc_INCLUDE_DIR) - message(STATUS "jemalloc.h found at: ${Jemalloc_INCLUDE_DIR}") -else() - message(WARNING "jemalloc.h not found!") -endif() - -# Check and print where libjemalloc.a was found -if(Jemalloc_LIBRARY) - message(STATUS "libjemalloc.a found at: ${Jemalloc_LIBRARY}") -else() - message(WARNING "libjemalloc.a not found!") -endif() +# set Jemalloc +set_path_external_library(jemalloc STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc/lib/libjemalloc.a + ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc/include/) diff --git a/libs/setup.sh b/libs/setup.sh index 62b72ec65..638c1b9f2 100755 --- a/libs/setup.sh +++ b/libs/setup.sh @@ -6,7 +6,6 @@ local_cache_host=${MGDEPS_CACHE_HOST_PORT:-mgdeps-cache:8000} working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "${working_dir}" -echo $wokring_dir # Clones a git repository and optionally cherry picks additional commits. The # function will try to preserve any local changes in the repo. @@ -256,17 +255,14 @@ cd .. absl_ref="20230125.3" repo_clone_try_double "${primary_urls[absl]}" "${secondary_urls[absl]}" "absl" "$absl_ref" -jemalloc_dir="$wokring_dir/../build/" - # jemalloc ea6b3e973b477b8061e0076bb257dbd7f3faa756 -JEMALLOC_COMMIT_HASH="ea6b3e973b477b8061e0076bb257dbd7f3faa756" JEMALLOC_COMMIT_VERSION="5.2.1" -repo_clone_try_double "${secondary_urls[jemalloc]}" "${secondary_urls[jemalloc]}" "Jemalloc" "$JEMALLOC_COMMIT_VERSION" -pushd Jemalloc -#git checkout ea6b3e973b477b8061e0076bb257dbd7f3faa756 +repo_clone_try_double "${secondary_urls[jemalloc]}" "${secondary_urls[jemalloc]}" "jemalloc" "$JEMALLOC_COMMIT_VERSION" + +# this is hack for cmake in libs to set path, and for FindJemalloc to use Jemalloc_INCLUDE_DIR +pushd jemalloc -#make distclean ./autogen.sh MALLOC_CONF="retain:false,percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:5000,dirty_decay_ms:5000" \ ./configure \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 598f22715..f19d66d8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -156,12 +156,3 @@ install(TARGETS mg_import_csv RUNTIME DESTINATION bin) # ---------------------------------------------------------------------------- # Memgraph CSV Import Tool Executable # ---------------------------------------------------------------------------- - -# find_package(Jemalloc REQUIRED) -# add_executable(arenas arenas.cpp) - -# target_link_libraries(arenas mg-utils Jemalloc::Jemalloc) -# target_compile_definitions(arenas PRIVATE USE_JEMALLOC=1) -#target_link_libraries(arenas mg-storage-v2) - -# install(TARGETS arenas RUNTIME DESTINATION bin) diff --git a/src/memory/CMakeLists.txt b/src/memory/CMakeLists.txt index 219730cd4..bf3cbb23b 100644 --- a/src/memory/CMakeLists.txt +++ b/src/memory/CMakeLists.txt @@ -4,7 +4,7 @@ set(memory_src_files -find_package(Jemalloc REQUIRED) +find_package(jemalloc REQUIRED) add_library(mg-memory STATIC ${memory_src_files}) target_link_libraries(mg-memory mg-utils fmt)