Skip to content

Commit

Permalink
cmake add ENABLE_SHARED, default OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Oct 24, 2024
1 parent 2fa4b37 commit 5be0434
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
2 changes: 2 additions & 0 deletions cmake/Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}" )
#-------------------------------------------------------------

18 changes: 11 additions & 7 deletions mock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_PDB_FILE:tarsmock_shared> 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 $<TARGET_PDB_FILE:tarsmock_shared> DESTINATION bin)
endif()

endif()
21 changes: 12 additions & 9 deletions servant/libservant/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_PDB_FILE:tarsservant_shared> 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 $<TARGET_PDB_FILE:tarsservant_shared> DESTINATION bin)
endif()
endif()
16 changes: 10 additions & 6 deletions tools/tarsparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 $<TARGET_PDB_FILE:tarsparse_shared> DESTINATION bin)
if (WIN32)
install(FILES $<TARGET_PDB_FILE:${TARGETNAME}_shared> DESTINATION bin)
endif()
endif()

FILE(GLOB HEADERS "*.h")
Expand Down
44 changes: 24 additions & 20 deletions util/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_PDB_FILE:tarsutil_shared> 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 $<TARGET_PDB_FILE:tarsutil_shared> DESTINATION bin)
endif()
endif()

IF(WIN32)
Expand Down

0 comments on commit 5be0434

Please sign in to comment.