Skip to content

Commit 29954b8

Browse files
riversand963facebook-github-bot
authored andcommitted
Add initial CMake support to plugin (facebook#9214)
Summary: Not a CMake expert, and the current CMake build support added by this PR is unlikely the best way of doing it. Sending out the PR to demonstrate it can work. Pull Request resolved: facebook#9214 Test Plan: Will need to update https://github.com/ajkr/dedupfs with CMake build. Also, PR facebook#9170 and PR facebook#9206 both include CMake support for their plugins, and can be used as a proof of concept. Reviewed By: ajkr Differential Revision: D32738273 Pulled By: riversand963 fbshipit-source-id: da87fb4377c716bbbd577a69763b48d22483f845
1 parent 552256c commit 29954b8

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,31 @@ list(APPEND SOURCES
938938
utilities/transactions/lock/range/range_tree/lib/util/dbt.cc
939939
utilities/transactions/lock/range/range_tree/lib/util/memarena.cc)
940940

941+
message(STATUS "ROCKSDB_PLUGINS: ${ROCKSDB_PLUGINS}")
942+
if ( ROCKSDB_PLUGINS )
943+
string(REPLACE " " ";" PLUGINS ${ROCKSDB_PLUGINS})
944+
foreach (plugin ${PLUGINS})
945+
add_subdirectory("plugin/${plugin}")
946+
foreach (src ${${plugin}_SOURCES})
947+
list(APPEND SOURCES plugin/${plugin}/${src})
948+
set_source_files_properties(
949+
plugin/${plugin}/${src}
950+
PROPERTIES COMPILE_FLAGS "${${plugin}_COMPILE_FLAGS}")
951+
endforeach()
952+
foreach (path ${${plugin}_INCLUDE_PATHS})
953+
include_directories(${path})
954+
endforeach()
955+
foreach (lib ${${plugin}_LIBS})
956+
list(APPEND THIRDPARTY_LIBS ${lib})
957+
endforeach()
958+
foreach (link_path ${${plugin}_LINK_PATHS})
959+
link_directories(AFTER ${link_path})
960+
endforeach()
961+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${${plugin}_CMAKE_SHARED_LINKER_FLAGS}")
962+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${${plugin}_CMAKE_EXE_LINKER_FLAGS}")
963+
endforeach()
964+
endif()
965+
941966
if(HAVE_SSE42 AND NOT MSVC)
942967
set_source_files_properties(
943968
util/crc32c.cc

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ ROCKSDB_PLUGIN_SOURCES = $(foreach plugin, $(ROCKSDB_PLUGINS), $(foreach source,
251251
ROCKSDB_PLUGIN_HEADERS = $(foreach plugin, $(ROCKSDB_PLUGINS), $(foreach header, $($(plugin)_HEADERS), plugin/$(plugin)/$(header)))
252252
ROCKSDB_PLUGIN_PKGCONFIG_REQUIRES = $(foreach plugin, $(ROCKSDB_PLUGINS), $($(plugin)_PKGCONFIG_REQUIRES))
253253
PLATFORM_LDFLAGS += $(foreach plugin, $(ROCKSDB_PLUGINS), $($(plugin)_LDFLAGS))
254+
CXXFLAGS += $(foreach plugin, $(ROCKSDB_PLUGINS), $($(plugin)_CXXFLAGS))
254255

255256
ifneq ($(ROCKSDB_PLUGIN_PKGCONFIG_REQUIRES),)
256257
LDFLAGS := $(LDFLAGS) $(shell pkg-config --libs $(ROCKSDB_PLUGIN_PKGCONFIG_REQUIRES))

plugin/README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@ External plugins will be linked according to their name into a subdirectory of "
1212

1313
### Build standard
1414

15-
Currently the only supported build system is make. In the plugin directory, files ending in the .mk extension can define the following variables.
15+
Currently the only supported build system are make and cmake.
16+
17+
For make, files in the plugin directory ending in the .mk extension can define the following variables.
1618

1719
* `$(PLUGIN_NAME)_SOURCES`: these files will be compiled and linked with RocksDB. They can access RocksDB public header files.
1820
* `$(PLUGIN_NAME)_HEADERS`: these files will be installed in the RocksDB header directory. Their paths will be prefixed by "rocksdb/plugin/$(PLUGIN_NAME)/".
1921
* `$(PLUGIN_NAME)_LDFLAGS`: these flags will be passed to the final link step. For example, library dependencies can be propagated here, or symbols can be forcibly included, e.g., for static registration.
22+
* `$(PLUGIN_NAME)_CXXFLAGS`: these flags will be passed to the compiler. For example, they can specify locations of header files in non-standard locations.
2023

2124
Users will run the usual make commands from the RocksDB directory, specifying the plugins to include in a space-separated list in the variable `ROCKSDB_PLUGINS`.
2225

26+
For CMake, the CMakeLists.txt file in the plugin directory can define the following variables.
27+
28+
* `${PLUGIN_NAME}_SOURCES`: these files will be compiled and linked with RocksDB. They can access RocksDB public header files.
29+
* `${PLUGIN_NAME}_COMPILE_FLAGS`: these flags will be passed to the compiler. For example, they can specify locations of header files in non-standard locations.
30+
* `${PLUGIN_NAME}_INCLUDE_PATHS`: paths to directories to search for plugin-specific header files during compilation.
31+
* `${PLUGIN_NAME}_LIBS`: list of library names required to build the plugin, e.g. `dl`, `java`, `jvm`, `rados`, etc. CMake will generate proper flags for linking.
32+
* `${PLUGIN_NAME}_LINK_PATHS`: list of paths for the linker to search for required libraries in additional to standard locations.
33+
* `${PLUGIN_NAME}_CMAKE_SHARED_LINKER_FLAGS` additional linker flags used to generate shared libraries. For example, symbols can be forcibly included, e.g., for static registration.
34+
* `${PLUGIN_NAME}_CMAKE_EXE_LINKER_FLAGS`: additional linker flags used to generate executables. For example, symbols can be forcibly included, e.g., for static registration.
35+
36+
Users will run the usual cmake commands, specifying the plugins to include in a space-separated list in the command line variable `ROCKSDB_PLUGINS` when invoking cmake.
37+
```
38+
cmake .. -DROCKSDB_PLUGINS="dedupfs hdfs rados"
39+
```
40+
2341
### Example
2442

2543
For a working example, see [Dedupfs](https://github.com/ajkr/dedupfs).

0 commit comments

Comments
 (0)