From 3100950932e854f2ef5836b31b4646060c05fed9 Mon Sep 17 00:00:00 2001 From: ruanshudong Date: Tue, 10 Mar 2020 10:42:12 +0800 Subject: [PATCH] add gtest --- cmake/Thirdparty.cmake | 42 ++++++++++++++++++++++++++++- servant/makefile/tars-tools.cmake | 44 +++++++++++++++---------------- servant/protocol | 2 +- servant/tup/Tars.h | 6 ++--- 4 files changed, 67 insertions(+), 27 deletions(-) diff --git a/cmake/Thirdparty.cmake b/cmake/Thirdparty.cmake index 496166f..b280861 100755 --- a/cmake/Thirdparty.cmake +++ b/cmake/Thirdparty.cmake @@ -52,13 +52,53 @@ set(LIB_HTTP2) set(LIB_SSL) set(LIB_CRYPTO) set(LIB_PROTOBUF) - +set(LIB_GTEST) #------------------------------------------------------------- add_custom_target(thirdparty) include(ExternalProject) +set(LIB_GTEST "libgtest") + +if (WIN32) + + ExternalProject_Add(ADD_${LIB_GTEST} + URL http://cdn.tarsyun.com/src/release-1.10.0.zip + DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download + PREFIX ${CMAKE_BINARY_DIR} + INSTALL_DIR ${CMAKE_SOURCE_DIR} + CONFIGURE_COMMAND cmake . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gtest-lib + BUILD_IN_SOURCE 1 + BUILD_COMMAND cmake --build . --config release + LOG_CONFIGURE 1 + LOG_BUILD 1 + # INSTALL_COMMAND cmake -P ${RUN_PROTOBUF_INSTALL_FILE} + URL_MD5 82358affdd7ab94854c8ee73a180fc53 + ) +else() + ExternalProject_Add(ADD_${LIB_GTEST} + URL http://cdn.tarsyun.com/src/release-1.10.0.tar.gz + DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download + PREFIX ${CMAKE_BINARY_DIR} + INSTALL_DIR ${CMAKE_SOURCE_DIR} + CONFIGURE_COMMAND cmake . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gtest-lib + BUILD_IN_SOURCE 1 + BUILD_COMMAND make + LOG_CONFIGURE 1 + LOG_BUILD 1 + # INSTALL_COMMAND cmake -P ${RUN_PROTOBUF_INSTALL_FILE} + URL_MD5 ecd1fa65e7de707cd5c00bdac56022cd + ) +endif() + +INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gtest/lib DESTINATION thirdparty) +INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gtest/include/ DESTINATION thirdparty/include) + +add_dependencies(thirdparty ADD_${LIB_GTEST}) + if (TARS_PROTOBUF) set(PROTOBUF_DIR_INC "${THIRDPARTY_PATH}/protobuf/include") set(PROTOBUF_DIR_LIB "${THIRDPARTY_PATH}/protobuf/lib") diff --git a/servant/makefile/tars-tools.cmake b/servant/makefile/tars-tools.cmake index 0cd5396..fd7fafc 100644 --- a/servant/makefile/tars-tools.cmake +++ b/servant/makefile/tars-tools.cmake @@ -23,11 +23,11 @@ set(TARS_INC "${TARS_PATH}/include") set(TARS_LIB_DIR "${TARS_PATH}/lib" ) if(WIN32) -set (LIB_TARS_SERVANT "${TARS_LIB_DIR}/tarsservant.lib") -set (LIB_TARS_UTIL "${TARS_LIB_DIR}/tarsutil.lib") + set (LIB_TARS_SERVANT "${TARS_LIB_DIR}/tarsservant.lib") + set (LIB_TARS_UTIL "${TARS_LIB_DIR}/tarsutil.lib") else() -set (LIB_TARS_SERVANT "${TARS_LIB_DIR}/libtarsservant.a") -set (LIB_TARS_UTIL "${TARS_LIB_DIR}/libtarsutil.a") + set (LIB_TARS_SERVANT "${TARS_LIB_DIR}/libtarsservant.a") + set (LIB_TARS_UTIL "${TARS_LIB_DIR}/libtarsutil.a") endif() include_directories(${TARS_INC}) @@ -80,52 +80,52 @@ ENDIF (UNIX) set(TARS_WEB_HOST "http://web.tars.com") -macro(gen_tars TARGET) +function(gen_tars TARGET) file(GLOB_RECURSE TARS_INPUT *.tars) - set(TARS_GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - - set(CLEAN_LIST) if (TARS_INPUT) + foreach(TARS_FILE ${TARS_INPUT}) get_filename_component(TARS_NAME ${TARS_FILE} NAME_WE) + get_filename_component(TARS_PATH ${TARS_FILE} PATH) - set(CUR_TARS_GEN ${TARS_GEN_DIR}/${TARS_NAME}.h) - - set(TARS_GEN ${TARS_GEN} ${CUR_TARS_GEN}) + set(CUR_TARS_GEN ${TARS_PATH}/${TARS_NAME}.h) add_custom_command( OUTPUT ${CUR_TARS_GEN} - WORKING_DIRECTORY ${TARS_GEN_DIR} + WORKING_DIRECTORY ${TARS_PATH} COMMAND ${TARS2CPP} ${TARS_TOOL_FLAG} ${TARS_FILE} + COMMENT "${TARS2CPP} ${TARS_TOOL_FLAG} ${TARS_FILE}" DEPENDS ${TARS2CPP} ${TARS_FILE} ) - list(APPEND CLEAN_LIST ${CUR_TARS_GEN}) + list(APPEND OUT_TARS_H_LIST ${CUR_TARS_GEN}) - endforeach(TARS_FILE ${TARS_INPUT}) + endforeach() - add_custom_target(${TARGET} ALL DEPENDS ${CUR_TARS_GEN}) + add_custom_target(${TARGET} ALL DEPENDS ${OUT_TARS_H_LIST}) + + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${OUT_TARS_H_LIST}") endif() - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_LIST}") - -endmacro() +endfunction() #生成带tars文件的可执行程序 macro(gen_server APP TARGET) include_directories(${PROJECT_SOURCE_DIR}) - gen_tars(tars-${TARGET}) - FILE(GLOB_RECURSE SRC_FILES "*.cc" "*.cpp" ".c") add_executable(${TARGET} ${SRC_FILES}) + file(GLOB_RECURSE TARS_INPUT *.tars) - add_dependencies(${TARGET} tars-${APP}-${TARGET}) + if(TARS_INPUT) + gen_tars(tars-${TARGET}) + add_dependencies(${TARGET} tars-${TARGET}) + endif() if(TARS_SSL) target_link_libraries(${TARGET} ${LIB_SSL} ${LIB_CRYPTO}) @@ -156,7 +156,7 @@ macro(gen_server APP TARGET) WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -P ${RUN_TAR_COMMAND_FILE} COMMENT "call ${RUN_TAR_COMMAND_FILE}") - + add_custom_target(${TARGET}-tar DEPENDS ${TARGET}.tgz ${TARGET}) #make upload ######################################################################### diff --git a/servant/protocol b/servant/protocol index ba7008c..504ebee 160000 --- a/servant/protocol +++ b/servant/protocol @@ -1 +1 @@ -Subproject commit ba7008c400802efbe6860d7c172efdb0595e314c +Subproject commit 504ebee584ac972943a9ffef7b738114300793e4 diff --git a/servant/tup/Tars.h b/servant/tup/Tars.h index 75d2f64..981ecad 100755 --- a/servant/tup/Tars.h +++ b/servant/tup/Tars.h @@ -497,13 +497,13 @@ namespace tars if (tag < 15) { h.tag = tag; - os.writeBuf(&h, sizeof(h)); + os.writeBuf((const char *)&h, sizeof(h)); } else { h.tag = 15; - os.writeBuf(&h, sizeof(h)); - os.writeBuf(&tag, sizeof(tag)); + os.writeBuf((const char *)&h, sizeof(h)); + os.writeBuf((const char *)&tag, sizeof(tag)); } } };