This repository has been archived on 2024-06-25. You can view files and clone it, but cannot push or open issues or pull requests.
resply/CMakeLists.txt

155 lines
5.5 KiB
CMake
Raw Normal View History

2018-01-19 18:31:32 +01:00
cmake_minimum_required(VERSION 3.6)
project(resply VERSION 0.1.0 DESCRIPTION "Modern redis client for C++")
set(CMAKE_CXX_STANDARD 17)
2018-01-19 18:31:32 +01:00
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Threads REQUIRED)
2018-01-19 18:31:32 +01:00
option(BUILD_DOC "Build documentation using doxygen" ON)
add_definitions(-DASIO_STANDALONE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors -Werror -Wall -Wextra")
# Apparently, protobuf uses __builtin_offsetof in a way which clang declares as
# a extension to the language - gcc not. Disable that warning to get it to compile.
2018-02-28 09:17:03 +01:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extended-offsetof")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
2018-01-19 18:31:32 +01:00
include_directories(include)
# https://github.com/chriskohlhoff/asio
include_directories($ENV{ASIO_INCLUDE_PATH})
2018-01-19 18:31:32 +01:00
# https://github.com/nlohmann/json
# should refer to the directory 'src' of json
include_directories($ENV{JSON_INCLUDE_PATH})
2018-01-19 18:31:32 +01:00
# https://github.com/muellan/clipp
include_directories($ENV{CLIPP_INCLUDE_PATH})
2018-01-19 18:31:32 +01:00
# https://github.com/gabime/spdlog
include_directories($ENV{SPDLOG_INCLUDE_PATH})
2018-01-19 18:31:32 +01:00
# protobuf
find_package(Protobuf REQUIRED)
2018-03-06 08:37:44 +01:00
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
2018-01-19 18:31:32 +01:00
2018-03-06 08:37:44 +01:00
include_directories(${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
2018-01-19 18:31:32 +01:00
file(GLOB protos protos/*.proto)
2018-03-06 08:37:44 +01:00
set(PROTO_PATH "${CMAKE_SOURCE_DIR}/protos")
set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}")
set(GRPC_LIBRARIES grpc grpc++_unsecure)
foreach(proto ${protos})
get_filename_component(proto_name ${proto} NAME_WE)
add_custom_command(
OUTPUT "${GENERATED_PROTOBUF_PATH}/${proto_name}.pb.h"
"${GENERATED_PROTOBUF_PATH}/${proto_name}.pb.cc"
"${GENERATED_PROTOBUF_PATH}/${proto_name}.grpc.pb.h"
"${GENERATED_PROTOBUF_PATH}/${proto_name}.grpc.pb.cc"
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS "--proto_path=${PROTO_PATH}"
"--cpp_out=${GENERATED_PROTOBUF_PATH}"
"${proto}"
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS "--proto_path=${PROTO_PATH}"
"--grpc_out=${GENERATED_PROTOBUF_PATH}"
"--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}"
"${proto}"
)
list(APPEND GENERATED_PROTOBUF_FILES
"${GENERATED_PROTOBUF_PATH}/${proto_name}.pb.h"
"${GENERATED_PROTOBUF_PATH}/${proto_name}.pb.cc"
)
list(APPEND GENERATED_GRPC_FILES
"${GENERATED_PROTOBUF_PATH}/${proto_name}.grpc.pb.h"
"${GENERATED_PROTOBUF_PATH}/${proto_name}.grpc.pb.cc"
)
endforeach(proto)
# Fix compilation of gRPC files
set_source_files_properties(${GENERATED_GRPC_FILES} PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
2018-01-19 18:31:32 +01:00
# libresply
2018-01-25 23:39:12 +01:00
add_library(libresply OBJECT src/libresply.cc src/resp-parser.cc)
2018-01-19 18:31:32 +01:00
target_compile_definitions(libresply PRIVATE RESPLY_VERSION="${PROJECT_VERSION}")
add_library(resply-shared SHARED $<TARGET_OBJECTS:libresply>)
add_library(resply-static STATIC $<TARGET_OBJECTS:libresply>)
set_target_properties(resply-static PROPERTIES OUTPUT_NAME resply)
set_target_properties(resply-shared PROPERTIES OUTPUT_NAME resply)
install(TARGETS resply-shared DESTINATION lib)
install(TARGETS resply-static DESTINATION lib)
install(FILES include/resply.h DESTINATION include)
# cli
add_executable(resply-cli src/resply-cli.cc)
target_link_libraries(resply-cli resply-static ${CMAKE_THREAD_LIBS_INIT})
2018-01-19 18:31:32 +01:00
2018-03-06 08:37:44 +01:00
add_executable(proto-cli src/proto-cli.cc ${GENERATED_PROTOBUF_FILES})
2018-01-19 18:31:32 +01:00
target_link_libraries(proto-cli ${PROTOBUF_LIBRARIES})
2018-03-06 08:37:44 +01:00
add_executable(grpc-cli src/grpc-cli.cc ${GENERATED_PROTOBUF_FILES} ${GENERATED_GRPC_FILES})
target_link_libraries(grpc-cli ${PROTOBUF_LIBRARIES} ${GRPC_LIBRARIES})
2018-01-19 18:31:32 +01:00
# proxy
2018-03-06 08:37:44 +01:00
add_executable(proxy src/proxy.cc ${GENERATED_PROTOBUF_FILES} ${GENERATED_GRPC_FILES})
target_link_libraries(proxy resply-static ${PROTOBUF_LIBRARIES} ${GRPC_LIBRARIES})
2018-01-19 18:31:32 +01:00
# tests
file(GLOB tests_source tests/*.cc)
foreach (test_source ${tests_source})
get_filename_component(name ${test_source} NAME_WE)
2018-01-20 00:20:55 +01:00
set(tests ${tests} ${name})
2018-01-19 18:31:32 +01:00
add_executable(${name} ${test_source})
target_link_libraries(${name} resply-static ${CMAKE_THREAD_LIBS_INIT})
2018-01-19 18:31:32 +01:00
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
endforeach ()
2018-01-20 00:20:55 +01:00
string(STRIP "${tests}" tests)
2018-01-19 18:31:32 +01:00
add_custom_target(
tests
COMMAND for t in ${tests}\; do printf %s \"$$t: \"\; ./tests/$$t > /dev/null\; [ $$? == 1 ] && echo success || echo failed\; done
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${tests}
COMMENT "Running tests")
add_custom_target(
tests-verbose
COMMAND for t in ${tests}\; do echo -- Running $$t ...\; ./tests/$$t\; [ $$? == 1 ] && echo -- Test $$t succeeded || echo Test $$t failed\; done
2018-01-19 18:31:32 +01:00
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${tests}
COMMENT "Running tests")
# documentation
find_package(Doxygen)
if (BUILD_DOC AND DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(
doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
else ()
message("Doxygen need to be installed to generate the doxygen documentation")
endif ()