Commit f931fdcf authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

cmakelists improved (options for server and shared lib)

parent a14866a9
......@@ -5,14 +5,25 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g")
set(PROTOBUF_IMPORT_DIRS "${CMAKE_SOURCE_DIR}/src")
option(BUILD_LIBPROFANEDB "Build libprofanedb.so, to embed ProfaneDB" ON)
option(BUILD_PROFANEDB_SERVER "Build ProfaneDB gRPC server" OFF)
find_package(Threads REQUIRED)
find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
find_package(RocksDB REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem)
find_package(Protobuf REQUIRED) # Protobuf does the serialisation for the DB
find_package(RocksDB REQUIRED) # RocksDB is used as storage
find_package(Boost REQUIRED COMPONENTS filesystem) # Boost Filesystem scans the .proto directory
# gRPC is only required by ProfaneDB server
if(BUILD_PROFANEDB_SERVER)
find_package(gRPC REQUIRED)
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(src/profanedb/protobuf)
add_subdirectory(src/profanedb/storage)
add_subdirectory(src/profanedb/server)
add_subdirectory(src/profanedb/protobuf) # Generated Protobuf (& gRPC if neeeded) code
add_subdirectory(src/profanedb/storage) # libprofanedb shared lib, and common interface
# Nothing should depend on code in here, so it can be skipped entirely
if(BUILD_PROFANEDB_SERVER)
add_subdirectory(src/profanedb/server)
endif()
# Protobuf messages should always be generated
file(GLOB Proto "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
PROTOBUF_GENERATE_CPP(PROTO_CC PROTO_H ${Proto})
PROTOBUF_GENERATE_GRPC_CPP(GRPC_CC GRPC_H ${Proto})
add_library(profanedb_protobuf ${PROTO_CC} ${PROTO_H})
add_library(profanedb_grpc ${GRPC_CC} ${GRPC_H})
add_library(profanedb_protobuf ${PROTO_CC} ${PROTO_H} )
target_link_libraries(profanedb_protobuf ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIBRARIES})
target_link_libraries(profanedb_grpc profanedb_protobuf ${GRPC_LIBRARIES})
# If building the shared library, libprofanedb_protobuf.a needs to be PIC to be included
if(BUILD_LIBPROFANEDB)
set_target_properties(profanedb_protobuf PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
# libprofanedb_grpc.a has the service definitions, it's not required by the shared lib
if(BUILD_PROFANEDB_SERVER)
PROTOBUF_GENERATE_GRPC_CPP(GRPC_CC GRPC_H ${Proto})
add_library(profanedb_grpc ${GRPC_CC} ${GRPC_H})
target_link_libraries(profanedb_grpc profanedb_protobuf ${GRPC_LIBRARIES})
endif()
add_executable(profanedb_server main.cpp server.cpp)
# profanedb_grpc contains profanedb_protobuf
# profanedb_storage is linked statically for this executable
target_link_libraries(profanedb_server profanedb_grpc profanedb_storage)
add_library(profanedb_storage db.cpp parser.cpp)
target_link_libraries(profanedb_storage profanedb_protobuf ${ROCKSDB_LIBRARIES} ${Boost_LIBRARIES})
# libprofanedb_storage is used statically by the server,
# built as shared lib here to allow other software to embed it
if(BUILD_LIBPROFANEDB)
add_library(profanedb SHARED db.cpp parser.cpp)
target_link_libraries(profanedb profanedb_protobuf ${ROCKSDB_LIBRARIES} ${Boost_LIBRARIES})
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment