From 26d99a8df6fbc6b53b35e4d8800e064bdfc4deff Mon Sep 17 00:00:00 2001 From: ruanshudong Date: Sun, 27 Oct 2024 21:17:47 +0800 Subject: [PATCH] fix windows enableshard and ssl compiler error --- cmake/BuildTarsCpp.cmake | 4 ---- cmake/Thirdparty.cmake | 8 ++++++-- mock/CMakeLists.txt | 20 ++++++++++---------- mock/DbHandle.cpp | 8 ++++---- mock/DbHandle.h | 18 +++++++++--------- servant/CMakeLists.txt | 11 ++++++++++- tools/CMakeLists.txt | 3 +++ util/src/CMakeLists.txt | 5 ++++- 8 files changed, 46 insertions(+), 31 deletions(-) diff --git a/cmake/BuildTarsCpp.cmake b/cmake/BuildTarsCpp.cmake index b12af256..d58bc22b 100755 --- a/cmake/BuildTarsCpp.cmake +++ b/cmake/BuildTarsCpp.cmake @@ -98,10 +98,6 @@ macro(build_tars_server MODULE DEPS) target_link_libraries(${MODULE} ${LIB_HTTP2} ${LIB_PROTOBUF}) endif() -# if(TARS_GPERF) -# target_link_libraries(${MODULE} ${LIB_GPERF}) -# endif(TARS_GPERF) - SET(MODULE-TGZ "${CMAKE_BINARY_DIR}/${MODULE}.tgz") SET(RUN_DEPLOY_COMMAND_FILE "${PROJECT_BINARY_DIR}/run-deploy-${MODULE}.cmake") FILE(WRITE ${RUN_DEPLOY_COMMAND_FILE} "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/deploy/${MODULE})\n") diff --git a/cmake/Thirdparty.cmake b/cmake/Thirdparty.cmake index 366056ae..8d2cce95 100755 --- a/cmake/Thirdparty.cmake +++ b/cmake/Thirdparty.cmake @@ -255,7 +255,7 @@ if (TARS_GZIP) link_directories(${GZIP_DIR_LIB}) if (WIN32) - set(LIB_GZIP "libz") + set(LIB_GZIP "zlib") ExternalProject_Add(ADD_${LIB_GZIP} URL http://cdn.tarsyun.com/src/zlib-1.2.11.tar.gz @@ -302,7 +302,11 @@ if (TARS_HTTP2) link_directories(${NGHTTP2_DIR_LIB}) link_directories(${NGHTTP2_DIR_LIB64}) - set(LIB_HTTP2 "nghttp2_static") + if(ENABLE_SHARED) + set(LIB_HTTP2 "nghttp2") + else() + set(LIB_HTTP2 "nghttp2_static") + endif() if (WIN32) ExternalProject_Add(ADD_${LIB_HTTP2} diff --git a/mock/CMakeLists.txt b/mock/CMakeLists.txt index b1627906..f200f5a7 100755 --- a/mock/CMakeLists.txt +++ b/mock/CMakeLists.txt @@ -9,16 +9,16 @@ install(DIRECTORY . DESTINATION include/mock FILES_MATCHING PATTERN "*.h") install(TARGETS tarsmock RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -if(ENABLE_SHARED) - add_library(tarsmock_shared SHARED ${SRC_FILES}) - target_compile_definitions(tarsmock_shared PRIVATE SVT_USE_DLL UTIL_USE_DLL) - target_link_libraries(tarsmock_shared tarsservant_shared tarsutil_shared) - add_dependencies(tarsmock_shared tarsservant_shared) +# if(ENABLE_SHARED) +# add_library(tarsmock_shared SHARED ${SRC_FILES}) +# target_compile_definitions(tarsmock_shared PRIVATE SVT_USE_DLL UTIL_USE_DLL) +# target_link_libraries(tarsmock_shared tarsservant_shared tarsutil_shared) +# add_dependencies(tarsmock_shared tarsservant_shared) - install(TARGETS tarsmock_shared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +# install(TARGETS tarsmock_shared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) - if (WIN32) - install(FILES $ DESTINATION bin) - endif() +# if (WIN32) +# install(FILES $ DESTINATION bin) +# endif() -endif() +# endif() diff --git a/mock/DbHandle.cpp b/mock/DbHandle.cpp index b2efef07..a8ac1661 100755 --- a/mock/DbHandle.cpp +++ b/mock/DbHandle.cpp @@ -8,12 +8,12 @@ static ObjectsCache _objectsCache; -CDbHandle::SetDivisionCache CDbHandle::_setDivisionCache; -std::map CDbHandle::_mapGroupPriority; -std::mutex CDbHandle::_mutex; +static CDbHandle::SetDivisionCache _setDivisionCache; +static std::map _mapGroupPriority; +static std::mutex _mutex; //key-ip, value-组编号 -map CDbHandle::_groupIdMap; +map _groupIdMap; //key-group_name, value-组编号 //map CDbHandle::_groupNameMap; diff --git a/mock/DbHandle.h b/mock/DbHandle.h index dfa97b07..6c315c94 100755 --- a/mock/DbHandle.h +++ b/mock/DbHandle.h @@ -26,7 +26,7 @@ typedef map ObjectsCache; */ class UTIL_DLL_API CDbHandle { -private: +public: struct GroupPriorityEntry { std::string sGroupID; @@ -199,14 +199,14 @@ class UTIL_DLL_API CDbHandle vector getEpsByGroupId(const vector & vecEps, const GroupUseSelect GroupSelect, const set & setGroupID, ostringstream & os); -protected: +// protected: - static std::mutex _mutex; - //set划分缓存 - static SetDivisionCache _setDivisionCache; - //优先级的序列 - static std::map _mapGroupPriority; - //分组信息 - static map _groupIdMap; +// UTIL_DLL_API static std::mutex _mutex; +// //set划分缓存 +// UTIL_DLL_API static SetDivisionCache _setDivisionCache; +// //优先级的序列 +// UTIL_DLL_API static std::map _mapGroupPriority; +// //分组信息 +// UTIL_DLL_API static map _groupIdMap; }; diff --git a/servant/CMakeLists.txt b/servant/CMakeLists.txt index eec543f4..1b629ec6 100644 --- a/servant/CMakeLists.txt +++ b/servant/CMakeLists.txt @@ -37,13 +37,22 @@ macro(complice_tars OUT_DEPENDS_LIST HEADER INCLUDE) set(TARS_IN ${FILE}) set(TARS_H ${NAME_WE}.h) + if(ENABLE_SHARED AND TARS_SSL) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS tars2cpp ${FILE} + COMMAND ${CMAKE_COMMAND} -E env PATH=${CMAKE_BINARY_DIR}/src/openssl/bin/ ${TARS2CPP} --with-tars ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN} + COMMENT "${TARS2CPP} --with-tars ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN}") + else() add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS tars2cpp ${FILE} COMMAND ${TARS2CPP} --with-tars ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN} COMMENT "${TARS2CPP} --with-tars ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN}") - + endif() + list(APPEND DEPENDS_LIST ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H}) #设置需要清除的文件 diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 9bfb929a..b07e6e7e 100755 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -19,6 +19,9 @@ function(tars2language TARGET) target_link_libraries(${TARGET} tarsutil tarsparse) + if(TARS_SSL AND ENABLE_SHARED) + target_link_libraries(${TARGET} ${LIB_SSL} ${LIB_CRYPTO}) + endif() install(TARGETS ${TARGET} RUNTIME DESTINATION tools) endfunction() diff --git a/util/src/CMakeLists.txt b/util/src/CMakeLists.txt index 9e52e9e6..f6cc731e 100644 --- a/util/src/CMakeLists.txt +++ b/util/src/CMakeLists.txt @@ -48,8 +48,11 @@ if(ENABLE_SHARED) endif() if(TARS_HTTP2) - target_link_libraries(tarsutil_shared nghttp2) + target_link_libraries(tarsutil_shared nghttp2) endif() + if(TARS_GZIP) + target_link_libraries(tarsutil_shared ${LIB_GZIP}) + endif() add_dependencies(tarsutil_shared thirdparty) install(TARGETS tarsutil_shared