Skip to content

Commit

Permalink
Merge pull request #1 from uilianries/rocksdb-646
Browse files Browse the repository at this point in the history
fix: shared build for rocksdb
  • Loading branch information
gocarlos authored Dec 7, 2019
2 parents a4f8114 + 4009dbb commit ceae9ba
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 12 deletions.
5 changes: 3 additions & 2 deletions recipes/rocksdb/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
cmake_minimum_required(VERSION 2.8.12)
PROJECT(conancmakewrapper)

message(STATUS "Conan CMake Wrapper")
set(CMAKE_VERBOSE_MAKEFILE ON)

include("${CMAKE_SOURCE_DIR}/conanbuildinfo.cmake")
CONAN_BASIC_SETUP()

include("CMakeListsOriginal.cmake")
add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/rocksdb/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ sources:
"6.4.6":
sha256: 540BBF9369A31E0891FCB4056A36FFA439C59FC179AA0B1F46E3478417F97643
url: https://github.com/facebook/rocksdb/archive/v6.4.6.tar.gz
patches:
"6.4.6":
- base_path: source_subfolder
patch_file: patches/0001-build-libs.patch
25 changes: 21 additions & 4 deletions recipes/rocksdb/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RocksDB(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"lite": [True, False],
"with_gflags": [True, False],
"with_snappy": [True, False],
"with_lz4": [True, False],
Expand All @@ -23,13 +24,15 @@ class RocksDB(ConanFile):
default_options = {
"shared": False,
"fPIC": False,
"lite": False,
"with_snappy": False,
"with_lz4": False,
"with_zlib": False,
"with_zstd": False,
"with_gflags": False
}
generators = ["cmake", "cmake_find_package", "cmake_paths"]
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = ["cmake"]

@property
def _source_subfolder(self):
Expand All @@ -46,18 +49,24 @@ def source(self):

def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["WITH_MD_LIBRARY"] = self.settings.compiler == "Visual Studio" and "MD" in self.settings.compiler.runtime
cmake.definitions["ROCKSDB_INSTALL_ON_WINDOWS"] = self.settings.os == "Windows"
cmake.definitions["ROCKSDB_LITE"] = self.options.lite
cmake.definitions["WITH_TESTS"] = False
cmake.definitions["WITH_TOOLS"] = False
cmake.definitions["WITH_GFLAGS"] = self.options.with_gflags
cmake.definitions["WITH_SNAPPY"] = self.options.with_snappy
cmake.definitions["WITH_LZ4"] = self.options.with_lz4
cmake.definitions["WITH_ZLIB"] = self.options.with_zlib
cmake.definitions["WITH_ZSTD"] = self.options.with_zstd
# not available yet in CCI
cmake.definitions["WITH_JEMALLOC"] = False
cmake.configure(source_folder=self._source_subfolder)
cmake.configure()
return cmake

def build(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -74,12 +83,20 @@ def requirements(self):
self.requires("zstd/1.3.8")

def package(self):
self.copy(pattern="LICENSE*", dst="licenses",
src=self._source_subfolder)
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
self.copy("LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.name = "RocksDB"
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["Shlwapi.lib", "Rpcrt4.lib"]
if self.options.shared:
self.cpp_info.defines = ["ROCKSDB_DLL", "ROCKSDB_LIBRARY_EXPORTS"]
elif self.settings.os == "Linux":
self.cpp_info.system_libs = ["pthread", "m"]
if self.options.lite:
self.cpp_info.defines.append("ROCKSDB_LITE")
60 changes: 60 additions & 0 deletions recipes/rocksdb/all/patches/0001-build-libs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7266f3b..b8f6397 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -772,6 +772,7 @@ else()
set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
set(LIBS ${ROCKSDB_SHARED_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})

+ if (BUILD_SHARED_LIBS)
add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES})
target_link_libraries(${ROCKSDB_SHARED_LIB}
${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
@@ -781,18 +782,23 @@ else()
SOVERSION ${ROCKSDB_VERSION_MAJOR}
CXX_STANDARD 11
OUTPUT_NAME "rocksdb")
+ endif()
endif()

+if (NOT BUILD_SHARED_LIBS)
add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES})
target_link_libraries(${ROCKSDB_STATIC_LIB}
${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
+endif()

if(WIN32)
+ if (BUILD_SHARED_LIBS)
add_library(${ROCKSDB_IMPORT_LIB} SHARED ${SOURCES})
target_link_libraries(${ROCKSDB_IMPORT_LIB}
${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS")
+ endif()
if(MSVC)
set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES
COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb")
@@ -839,6 +845,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)

install(DIRECTORY include/rocksdb COMPONENT devel DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

+ if (NOT BUILD_SHARED_LIBS)
install(
TARGETS ${ROCKSDB_STATIC_LIB}
EXPORT RocksDBTargets
@@ -846,6 +853,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
+ else()

install(
TARGETS ${ROCKSDB_SHARED_LIB}
@@ -856,6 +864,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
+ endif()

install(
EXPORT RocksDBTargets
2 changes: 1 addition & 1 deletion recipes/rocksdb/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 2.8.12)
project(test_package)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE TRUE)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
10 changes: 5 additions & 5 deletions recipes/rocksdb/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

#include <cassert>

#include <cstdlib>
#include "rocksdb/db.h"

int main() {
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "./testdb", &db);
assert(status.ok());
rocksdb::Status status = rocksdb::DB::Open(options, "testdb", &db);
status.ok();

return EXIT_SUCCESS;
}

0 comments on commit ceae9ba

Please sign in to comment.