From 390cc60ac8fcadeed080e028752e39eeab315767 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Wed, 19 Nov 2014 11:40:49 -0500 Subject: [PATCH] Upgrade Mac and Linux LevelDB 1.12 -> 1.18-bitcoin --- .gitignore | 1 + CMakeLists.txt | 67 +++++++++++++++++++++---------- CMakeModules/FindBerkeleyDB.cmake | 0 CMakeModules/FindGperftools.cmake | 51 +++++++++++++++++++++++ 4 files changed, 98 insertions(+), 21 deletions(-) mode change 100755 => 100644 CMakeModules/FindBerkeleyDB.cmake create mode 100644 CMakeModules/FindGperftools.cmake diff --git a/.gitignore b/.gitignore index ee02e4a1e..f37020f05 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ docs/latex CMakeCache.txt CMakeFiles Makefile +!CMakeModules/* compile_commands.json .ycm_extra_conf.py* diff --git a/CMakeLists.txt b/CMakeLists.txt index c81234fba..bad939591 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,27 +96,48 @@ if( WIN32 ) SET(TCL_LIBS "${TCL_LIBS}${TCL_LIB_PATH}/${TCL_LIB_NAME}g${TCL_LIB_EXT}") SET(TCL_LIBRARY ${TCL_LIBS}) -else( WIN32 ) - # Apple AND Linux Options Here - find_package( ZLIB REQUIRED ) - - #set( LEVEL_DB_DIR "${CMAKE_SOURCE_DIR}/libraries/leveldb" ) - #include( ExternalProject ) - #ExternalProject_Add( LevelDB - #PREFIX "${LEVEL_DB_DIR}" - #SOURCE_DIR "${LEVEL_DB_DIR}" - #BUILD_IN_SOURCE 1 - #CONFIGURE_COMMAND "" - #BUILD_COMMAND "$(MAKE)" - #INSTALL_COMMAND "" - #) - #include_directories( "${LEVEL_DB_DIR}" "${LEVEL_DB_DIR}/include" ) - #add_library( leveldb STATIC IMPORTED ) - #add_dependencies( leveldb LevelDB ) - #set_property(TARGET leveldb PROPERTY IMPORTED_LOCATION "${LEVEL_DB_DIR}/libleveldb.a" ) - - set( LEVEL_DB_DIR vendor/leveldb-1.12.0 ) - add_subdirectory( "${LEVEL_DB_DIR}" ) + +else( WIN32 ) # Apple AND Linux + + set( LEVEL_DB_DIR "${CMAKE_SOURCE_DIR}/libraries/leveldb" ) + + file( GLOB LEVEL_DB_SOURCES + "${LEVEL_DB_DIR}/db/*.cc" + "${LEVEL_DB_DIR}/port/port_posix.cc" + "${LEVEL_DB_DIR}/helpers/memenv/memenv.cc" + "${LEVEL_DB_DIR}/table/*.cc" + "${LEVEL_DB_DIR}/util/*.cc" + ) + foreach( filename ${LEVEL_DB_SOURCES} ) + if( ${filename} MATCHES ".*_test.cc" OR ${filename} MATCHES ".*_bench.cc" OR ${filename} MATCHES ".*_main.cc" ) + list( REMOVE_ITEM LEVEL_DB_SOURCES ${filename} ) + endif() + endforeach() + + add_library( leveldb ${LEVEL_DB_SOURCES} ) + target_include_directories( leveldb PUBLIC "${LEVEL_DB_DIR}" "${LEVEL_DB_DIR}/include" ) + + find_package( Gperftools QUIET ) + if( GPERFTOOLS_FOUND ) + message( STATUS "Found gperftools; compiling LevelDB with TCMalloc") + else() + message( STATUS "Could not find gperftools; compiling LevelDB without TCMalloc") + endif() + + add_definitions( -DLEVELDB_PLATFORM_POSIX -DLEVELDB_ATOMIC_PRESENT ) + if( APPLE ) + add_definitions( -DOS_MACOSX ) + if( GPERFTOOLS_FOUND ) + target_link_libraries( leveldb tcmalloc ) + endif() + else() # Linux + add_definitions( -DOS_LINUX -DCYGWIN ) + if( GPERFTOOLS_FOUND ) + target_link_libraries( leveldb pthread tcmalloc ) + else() + target_link_libraries( leveldb pthread ) + endif() + endif() find_library(READLINE_LIBRARIES NAMES readline) find_path(READLINE_INCLUDE_DIR readline/readline.h) @@ -140,6 +161,10 @@ else( WIN32 ) endif ( FULL_STATIC_BUILD ) endif( APPLE ) + if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp" ) + endif() + if( "${CMAKE_GENERATOR}" STREQUAL "Ninja" ) if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics" ) diff --git a/CMakeModules/FindBerkeleyDB.cmake b/CMakeModules/FindBerkeleyDB.cmake old mode 100755 new mode 100644 diff --git a/CMakeModules/FindGperftools.cmake b/CMakeModules/FindGperftools.cmake new file mode 100644 index 000000000..cd990662c --- /dev/null +++ b/CMakeModules/FindGperftools.cmake @@ -0,0 +1,51 @@ +# Tries to find Gperftools. +# +# Usage of this module as follows: +# +# find_package(Gperftools) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# Gperftools_ROOT_DIR Set this variable to the root installation of +# Gperftools if the module has problems finding +# the proper installation path. +# +# Variables defined by this module: +# +# GPERFTOOLS_FOUND System has Gperftools libs/headers +# GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler) +# GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers + +find_library(GPERFTOOLS_TCMALLOC + NAMES tcmalloc + HINTS ${Gperftools_ROOT_DIR}/lib) + +find_library(GPERFTOOLS_PROFILER + NAMES profiler + HINTS ${Gperftools_ROOT_DIR}/lib) + +find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER + NAMES tcmalloc_and_profiler + HINTS ${Gperftools_ROOT_DIR}/lib) + +find_path(GPERFTOOLS_INCLUDE_DIR + NAMES gperftools/heap-profiler.h + HINTS ${Gperftools_ROOT_DIR}/include) + +set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + Gperftools + DEFAULT_MSG + GPERFTOOLS_LIBRARIES + GPERFTOOLS_INCLUDE_DIR) + +mark_as_advanced( + Gperftools_ROOT_DIR + GPERFTOOLS_TCMALLOC + GPERFTOOLS_PROFILER + GPERFTOOLS_TCMALLOC_AND_PROFILER + GPERFTOOLS_LIBRARIES + GPERFTOOLS_INCLUDE_DIR)