cmake_minimum_required(VERSION 3.6) project(resply VERSION 0.1.0 DESCRIPTION "Modern redis client for C++") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) 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. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extended-offsetof") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") include_directories(include) # https://github.com/chriskohlhoff/asio include_directories($ENV{ASIO_INCLUDE_PATH}) # https://github.com/nlohmann/json # should refer to the directory 'src' of json include_directories($ENV{JSON_INCLUDE_PATH}) # https://github.com/muellan/clipp include_directories($ENV{CLIPP_INCLUDE_PATH}) # https://github.com/gabime/spdlog include_directories($ENV{SPDLOG_INCLUDE_PATH}) # protobuf find_package(Protobuf REQUIRED) include_directories(${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) file(GLOB protos protos/*.proto) protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${protos}) # libresply add_library(libresply OBJECT src/libresply.cc src/resp-parser.cc) target_compile_definitions(libresply PRIVATE RESPLY_VERSION="${PROJECT_VERSION}") add_library(resply-shared SHARED $) add_library(resply-static STATIC $) 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) add_executable(proto-cli src/proto-cli.cc ${PROTO_SRCS}) target_link_libraries(proto-cli ${PROTOBUF_LIBRARIES}) add_executable(grpc-cli src/grpc-cli.cc) # proxy add_executable(proxy src/proxy.cc ${PROTO_SRCS}) target_link_libraries(proxy resply-static ${PROTOBUF_LIBRARIES}) # tests file(GLOB tests_source tests/*.cc) foreach (test_source ${tests_source}) get_filename_component(name ${test_source} NAME_WE) set(tests ${tests} ${name}) add_executable(${name} ${test_source}) target_link_libraries(${name} resply-static) set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests) endforeach () string(STRIP "${tests}" tests) add_custom_target( tests COMMAND for t in ${tests}\; do printf %s \"$$t: \"\; ./tests/$$t && echo success || echo failed\; done 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 ()