Jemalloc.cmake 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Download and build Jemalloc
  2. set(JEMALLOC_VERSION 5.3.0)
  3. set(JEMALLOC_NAME jemalloc-${JEMALLOC_VERSION})
  4. set(JEMALLOC_TAR_PATH ${DEP_ROOT_DIR}/${JEMALLOC_NAME}.tar.bz2)
  5. list(APPEND jemalloc_CONFIG_ARGS --disable-initial-exec-tls)
  6. #list(APPEND jemalloc_CONFIG_ARGS --without-export)
  7. if (ENABLE_JEMALLOC_STAT)
  8. list(APPEND jemalloc_CONFIG_ARGS --enable-stats)
  9. message(STATUS "Jemalloc stats enabled")
  10. else ()
  11. list(APPEND jemalloc_CONFIG_ARGS --disable-stats)
  12. message(STATUS "Jemalloc stats disabled")
  13. endif ()
  14. list(APPEND jemalloc_CONFIG_ARGS --disable-libdl)
  15. #list(APPEND jemalloc_CONFIG_ARGS --disable-cxx)
  16. #list(APPEND jemalloc_CONFIG_ARGS --with-jemalloc-prefix=je_)
  17. #list(APPEND jemalloc_CONFIG_ARGS --enable-debug)
  18. if(NOT EXISTS ${JEMALLOC_TAR_PATH})
  19. set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/${JEMALLOC_NAME}.tar.bz2)
  20. message(STATUS "Downloading ${JEMALLOC_NAME} from ${JEMALLOC_URL}")
  21. file(DOWNLOAD ${JEMALLOC_URL} ${JEMALLOC_TAR_PATH} SHOW_PROGRESS STATUS JEMALLOC_DOWNLOAD_STATUS LOG JEMALLOC_DOWNLOAD_LOG)
  22. list(GET JEMALLOC_DOWNLOAD_STATUS 0 JEMALLOC_DOWNLOAD_STATUS_CODE)
  23. if(NOT JEMALLOC_DOWNLOAD_STATUS_CODE EQUAL 0)
  24. file(REMOVE ${JEMALLOC_TAR_PATH})
  25. message(STATUS "${JEMALLOC_DOWNLOAD_LOG}")
  26. message(FATAL_ERROR "${JEMALLOC_NAME} download failed! error is ${JEMALLOC_DOWNLOAD_STATUS}")
  27. return()
  28. endif ()
  29. endif()
  30. SET( DIR_CONTAINING_JEMALLOC ${DEP_ROOT_DIR}/${JEMALLOC_NAME} )
  31. if(NOT EXISTS ${DIR_CONTAINING_JEMALLOC})
  32. message(STATUS "Extracting jemalloc...")
  33. execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${JEMALLOC_TAR_PATH} WORKING_DIRECTORY ${DEP_ROOT_DIR})
  34. endif()
  35. if(NOT EXISTS ${DIR_CONTAINING_JEMALLOC}/Makefile)
  36. message("Configuring jemalloc locally...")
  37. # Builds with "--with-jemalloc-prefix=je_" on OSX
  38. # SET( BASH_COMMAND_TO_RUN bash -l -c "cd ${DIR_CONTAINING_JEMALLOC} && ./configure ${jemalloc_CONFIG_ARGS}" )
  39. #
  40. # EXECUTE_PROCESS( COMMAND ${BASH_COMMAND_TO_RUN}
  41. # WORKING_DIRECTORY ${DIR_CONTAINING_JEMALLOC} RESULT_VARIABLE JEMALLOC_CONFIGURE )
  42. execute_process(COMMAND ./configure ${jemalloc_CONFIG_ARGS} WORKING_DIRECTORY ${DIR_CONTAINING_JEMALLOC} RESULT_VARIABLE JEMALLOC_CONFIGURE)
  43. if(NOT JEMALLOC_CONFIGURE EQUAL 0)
  44. message(FATAL_ERROR "${JEMALLOC_NAME} configure failed!")
  45. message("${JEMALLOC_CONFIGURE}")
  46. endif()
  47. endif()
  48. if(NOT EXISTS ${DIR_CONTAINING_JEMALLOC}/lib/libjemalloc.a)
  49. message("Building jemalloc locally...")
  50. execute_process(COMMAND make "build_lib_static" WORKING_DIRECTORY ${DIR_CONTAINING_JEMALLOC})
  51. if(NOT EXISTS ${DIR_CONTAINING_JEMALLOC}/lib/libjemalloc.a)
  52. message(FATAL_ERROR "${JEMALLOC_NAME} build failed!")
  53. endif()
  54. endif()