diff --git a/cmake/Common.cmake b/cmake/Common.cmake index 2bdeed60..bd6c8a2c 100755 --- a/cmake/Common.cmake +++ b/cmake/Common.cmake @@ -30,6 +30,7 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) endforeach() option(ONLY_LIB "option for only lib" ON) +option(ENABLE_SHARED "option for enable shared library" OFF) # option(TARS_OPENTRACKING "option for open tracking" OFF) @@ -130,5 +131,6 @@ message("TARS2CPP: ${TARS2CPP}") #message("TARS_OPENTRACKING: ${TARS_OPENTRACKING}") message("ONLY_LIB: ${ONLY_LIB}" ) message("TARS_STD_SHARED_PTR: ${TARS_STD_SHARED_PTR}" ) +message("ENABLE_SHARED: ${ENABLE_SHARED}" ) #------------------------------------------------------------- diff --git a/mock/CMakeLists.txt b/mock/CMakeLists.txt index cfe1eaef..87f601db 100755 --- a/mock/CMakeLists.txt +++ b/mock/CMakeLists.txt @@ -2,18 +2,22 @@ include_directories(../) file(GLOB_RECURSE SRC_FILES *.cpp) add_library(tarsmock STATIC ${SRC_FILES}) -add_library(tarsmock_shared SHARED ${SRC_FILES}) -target_link_libraries(tarsmock_shared tarsservant_shared tarsutil_shared) add_dependencies(tarsmock tarsservant) -add_dependencies(tarsmock_shared tarsservant) + install(DIRECTORY . DESTINATION include/mock FILES_MATCHING PATTERN "*.h") install(TARGETS tarsmock 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(ENABLE_SHARED) + add_library(tarsmock_shared SHARED ${SRC_FILES}) + target_link_libraries(tarsmock_shared tarsservant_shared tarsutil_shared) + add_dependencies(tarsmock_shared tarsmock) + install(TARGETS tarsmock_shared RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + if (WIN32) + install(FILES $ DESTINATION bin) + endif() + +endif() diff --git a/servant/libservant/CMakeLists.txt b/servant/libservant/CMakeLists.txt index 3e46dcd0..9e234e25 100755 --- a/servant/libservant/CMakeLists.txt +++ b/servant/libservant/CMakeLists.txt @@ -16,14 +16,17 @@ install(TARGETS tarsservant LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -add_library(tarsservant_shared SHARED ${DIR_SRCS}) -target_compile_definitions(tarsservant_shared PRIVATE SVT_DLL_EXPORT UTIL_USE_DLL) -target_link_libraries(tarsservant_shared tarsutil_shared tarsparse_shared) +if(ENABLE_SHARED) + add_library(tarsservant_shared SHARED ${DIR_SRCS}) -add_dependencies(tarsservant_shared COPY-SERVENT-TARS) -install(TARGETS tarsservant_shared - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -if (WIN32) - install(FILES $ DESTINATION bin) + target_compile_definitions(tarsservant_shared PRIVATE SVT_DLL_EXPORT UTIL_USE_DLL) + target_link_libraries(tarsservant_shared tarsutil_shared tarsparse_shared) + + add_dependencies(tarsservant_shared tarsservant) + install(TARGETS tarsservant_shared + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + if (WIN32) + install(FILES $ DESTINATION bin) + endif() endif() diff --git a/tools/tarsparse/CMakeLists.txt b/tools/tarsparse/CMakeLists.txt index ec25bf81..4a4181c7 100644 --- a/tools/tarsparse/CMakeLists.txt +++ b/tools/tarsparse/CMakeLists.txt @@ -29,7 +29,6 @@ foreach(LEC_YACC_SRC ${DEPENDS_LEC_YACC_SRC_LIST}) endforeach() add_library(${TARGETNAME} STATIC ${DIR_SRCS} ${DEPENDS_SRC_LIST}) -add_library(${TARGETNAME}_shared SHARED ${DIR_SRCS} ${DEPENDS_SRC_LIST}) if(UNIX) add_dependencies(${TARGETNAME} COPY-LEX-YACC) @@ -39,12 +38,17 @@ install(TARGETS ${TARGETNAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -install(TARGETS ${TARGETNAME}_shared - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) +if(ENABLE_SHARED) + add_library(${TARGETNAME}_shared SHARED ${DIR_SRCS} ${DEPENDS_SRC_LIST}) + add_dependencies(${TARGETNAME}_shared ${TARGETNAME}) + + install(TARGETS ${TARGETNAME}_shared + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -if (WIN32) - install(FILES $ DESTINATION bin) + if (WIN32) + install(FILES $ DESTINATION bin) + endif() endif() FILE(GLOB HEADERS "*.h") diff --git a/util/src/CMakeLists.txt b/util/src/CMakeLists.txt index 6c3b7f99..279f9072 100644 --- a/util/src/CMakeLists.txt +++ b/util/src/CMakeLists.txt @@ -25,32 +25,36 @@ list(APPEND DIR_SRCS ${JUMP_SRC}) list(APPEND DIR_SRCS ${MAKE_SRC}) add_library(tarsutil STATIC ${DIR_SRCS}) -add_library(tarsutil_shared SHARED ${DIR_SRCS}) -add_dependencies(tarsutil thirdparty) -#target_link_libraries(tarsutil_shared mysqlclient) -target_compile_definitions(tarsutil_shared PRIVATE UTIL_DLL_EXPORT) - -if (TARS_SSL) - if (WIN32) - #windows动态编译需添加依赖库 - target_link_libraries(tarsutil_shared ${LIB_SSL}.lib ${LIB_CRYPTO}.lib Crypt32) - #else () - #linux动态编译未验证,暂时屏蔽 - #target_link_libraries(${LIB_TAF_UTIL} ${LIB_SSL}.a ${LIB_CRYPTO}.a) - endif () -endif() -add_dependencies(tarsutil_shared thirdparty) +add_dependencies(tarsutil thirdparty) install(TARGETS tarsutil LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -install(TARGETS tarsutil_shared - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -if (WIN32) - install(FILES $ DESTINATION bin) +if(ENABLE_SHARED) + add_library(tarsutil_shared SHARED ${DIR_SRCS}) + + target_link_libraries(tarsutil_shared libmysql) + target_compile_definitions(tarsutil_shared PRIVATE UTIL_DLL_EXPORT) + + if (TARS_SSL) + if (WIN32) + #windows动态编译需添加依赖库 + target_link_libraries(tarsutil_shared ${LIB_SSL}.lib ${LIB_CRYPTO}.lib Crypt32) + #else () + #linux动态编译未验证,暂时屏蔽 + #target_link_libraries(${LIB_TAF_UTIL} ${LIB_SSL}.a ${LIB_CRYPTO}.a) + endif () + endif() + add_dependencies(tarsutil_shared tarsutil) + + install(TARGETS tarsutil_shared + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + if (WIN32) + install(FILES $ DESTINATION bin) + endif() endif() IF(WIN32)