Skip to content

Instantly share code, notes, and snippets.

@bassam
Created October 10, 2016 04:03
Show Gist options
  • Save bassam/e82c8ddb52c20fa19b660a261f5e8731 to your computer and use it in GitHub Desktop.
Save bassam/e82c8ddb52c20fa19b660a261f5e8731 to your computer and use it in GitHub Desktop.
# OSD/ObjectStore
# make rocksdb statically
if(NOT ALLOCATOR STREQUAL "jemalloc")
set(ROCKSDB_JEMALLOC "DISABLE_JEMALLOC=1")
endif()
set(ROCKSDB_EXTRA_CXXFLAG "-fPIC -Wno-unused-variable")
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
set(ROCKSDB_EXTRA_CXXFLAG "${ROCKSDB_EXTRA_CXXFLAG} -DNDEBUG")
endif(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
set(ROCKSDB_CXX "${CMAKE_CXX_COMPILER}")
if (WITH_CCACHE AND CCACHE_FOUND)
set(ROCKSDB_CXX "ccache ${CMAKE_CXX_COMPILER}")
endif(WITH_CCACHE AND CCACHE_FOUND)
set(ROCKSDB_AR "${CMAKE_AR}")
# we use an external project and copy the sources to bin directory to ensure
# that object files are built outside of the source tree.
include(ExternalProject)
ExternalProject_Add(rocksdb_ext
URL "${CMAKE_SOURCE_DIR}/src/rocksdb"
PREFIX "external"
PATCH_COMMAND ""
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND PORTABLE=1 ${ROCKSDB_JEMALLOC} $(MAKE) CXX=${ROCKSDB_CXX} AR=${ROCKSDB_AR} EXTRA_CXXFLAGS=${ROCKSDB_EXTRA_CXXFLAG} static_lib
BUILD_IN_SOURCE 1
INSTALL_COMMAND "")
# force rocksdb make to be called on each time
ExternalProject_Add_Step(rocksdb_ext forcebuild DEPENDEES configure DEPENDERS build ALWAYS 1)
ExternalProject_Get_Property(rocksdb_ext source_dir)
set(ROCKSDB_INCLUDE_DIR ${source_dir}/include)
# add a imported library for librocksdb.a
add_library(rocksdb STATIC IMPORTED)
add_dependencies(rocksdb rocksdb_ext)
set_property(TARGET rocksdb PROPERTY IMPORTED_LOCATION "${source_dir}/librocksdb.a")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment