From 4009dbb91976abe15644b27a26baa5eda5be4c70 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Fri, 6 Dec 2019 15:37:36 -0300 Subject: [PATCH] Fix shared build for rocksdb Signed-off-by: Uilian Ries --- recipes/rocksdb/all/CMakeLists.txt | 5 +- recipes/rocksdb/all/conandata.yml | 4 ++ recipes/rocksdb/all/conanfile.py | 25 ++++++-- .../rocksdb/all/patches/0001-build-libs.patch | 60 +++++++++++++++++++ .../rocksdb/all/test_package/CMakeLists.txt | 2 +- .../rocksdb/all/test_package/test_package.cpp | 10 ++-- 6 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 recipes/rocksdb/all/patches/0001-build-libs.patch diff --git a/recipes/rocksdb/all/CMakeLists.txt b/recipes/rocksdb/all/CMakeLists.txt index f5dad38491402..85890863d34b9 100644 --- a/recipes/rocksdb/all/CMakeLists.txt +++ b/recipes/rocksdb/all/CMakeLists.txt @@ -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") diff --git a/recipes/rocksdb/all/conandata.yml b/recipes/rocksdb/all/conandata.yml index 6cb275bea081f..239711c91ec96 100644 --- a/recipes/rocksdb/all/conandata.yml +++ b/recipes/rocksdb/all/conandata.yml @@ -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 \ No newline at end of file diff --git a/recipes/rocksdb/all/conanfile.py b/recipes/rocksdb/all/conanfile.py index 19edcf2111a4c..b61ce0e091018 100644 --- a/recipes/rocksdb/all/conanfile.py +++ b/recipes/rocksdb/all/conanfile.py @@ -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], @@ -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): @@ -46,7 +49,11 @@ 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 @@ -54,10 +61,12 @@ def _configure_cmake(self): 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() @@ -74,8 +83,8 @@ 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")) @@ -83,3 +92,11 @@ def package(self): 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") diff --git a/recipes/rocksdb/all/patches/0001-build-libs.patch b/recipes/rocksdb/all/patches/0001-build-libs.patch new file mode 100644 index 0000000000000..26a3580abc63e --- /dev/null +++ b/recipes/rocksdb/all/patches/0001-build-libs.patch @@ -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 diff --git a/recipes/rocksdb/all/test_package/CMakeLists.txt b/recipes/rocksdb/all/test_package/CMakeLists.txt index 8feed066d06aa..13dabebb26767 100644 --- a/recipes/rocksdb/all/test_package/CMakeLists.txt +++ b/recipes/rocksdb/all/test_package/CMakeLists.txt @@ -1,7 +1,6 @@ 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) @@ -9,3 +8,4 @@ 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) diff --git a/recipes/rocksdb/all/test_package/test_package.cpp b/recipes/rocksdb/all/test_package/test_package.cpp index ba77bb0602177..8584f7677cbbc 100644 --- a/recipes/rocksdb/all/test_package/test_package.cpp +++ b/recipes/rocksdb/all/test_package/test_package.cpp @@ -1,12 +1,12 @@ - -#include - +#include #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; }