Skip to content

Commit

Permalink
Add compile options: -Wno-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xia-chu committed Sep 21, 2024
1 parent ac6ae2d commit 6a392de
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ check_struct_has_member("struct mmsghdr" msg_hdr sys/socket.h HAVE_MMSG_HDR)
check_symbol_exists(sendmmsg sys/socket.h HAVE_SENDMMSG_API)
check_symbol_exists(recvmmsg sys/socket.h HAVE_RECVMMSG_API)

if(HAVE_MMSG_HDR)
if (HAVE_MMSG_HDR)
add_definitions(-DHAVE_MMSG_HDR)
endif()
if(HAVE_SENDMMSG_API)
endif ()
if (HAVE_SENDMMSG_API)
add_definitions(-DHAVE_SENDMMSG_API)
endif()
if(HAVE_RECVMMSG_API)
endif ()
if (HAVE_RECVMMSG_API)
add_definitions(-DHAVE_RECVMMSG_API)
endif()
endif ()

# check the socket buffer size set by the upper cmake project, if it is set, use the setting of the upper cmake project, otherwise set it to 256K
# if the socket buffer size is set to 0, it means that the socket buffer size is not set, and the kernel default value is used(just for linux)
if(DEFINED SOCKET_DEFAULT_BUF_SIZE)
if (DEFINED SOCKET_DEFAULT_BUF_SIZE)
if (SOCKET_DEFAULT_BUF_SIZE EQUAL 0)
message(STATUS "Socket default buffer size is not set, use the kernel default value")
else()
else ()
message(STATUS "Socket default buffer size is set to ${SOCKET_DEFAULT_BUF_SIZE}")
endif ()
add_definitions(-DSOCKET_DEFAULT_BUF_SIZE=${SOCKET_DEFAULT_BUF_SIZE})
endif()
endif ()
#加载自定义模块
#Load custom modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand All @@ -42,47 +42,49 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#Set subdirectories
set(SUB_DIR_LIST "Network" "Poller" "Thread" "Util")

if(WIN32)
if (WIN32)
list(APPEND SUB_DIR_LIST "win32")
#防止Windows.h包含Winsock.h
#Prevent Windows.h from including Winsock.h
add_definitions(-DWIN32_LEAN_AND_MEAN)
if (MSVC)
add_compile_options("/utf-8")
endif()
endif ()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
else ()
add_compile_options("-Wno-comment")
endif ()

#安装目录
#Installation directory
if(WIN32)
if (WIN32)
set(INSTALL_PATH_LIB $ENV{HOME}/${PROJECT_NAME}/lib)
set(INSTALL_PATH_INCLUDE $ENV{HOME}/${PROJECT_NAME}/include)
else()
else ()
set(INSTALL_PATH_LIB lib)
set(INSTALL_PATH_INCLUDE include)
endif()
endif ()

foreach(SUB_DIR ${SUB_DIR_LIST})
foreach (SUB_DIR ${SUB_DIR_LIST})
#遍历源文件
#Traverse source file
aux_source_directory(src/${SUB_DIR} SRC_LIST)
#安装头文件至系统目录
#Install header file to system directory
install(DIRECTORY src/${SUB_DIR} DESTINATION ${INSTALL_PATH_INCLUDE} FILES_MATCHING PATTERN "*.h")
endforeach()
endforeach ()

#非苹果平台移除.mm类型的文件
#Remove .mm type files from non-apple platforms
if(NOT APPLE)
if (NOT APPLE)
list(REMOVE_ITEM SRC_LIST "src/Network/Socket_ios.mm")
endif()
endif ()

if(WIN32)
if (WIN32)
set(LINK_LIB_LIST WS2_32 Iphlpapi shlwapi)
else()
else ()
set(LINK_LIB_LIST)
endif()
endif ()


set(ENABLE_OPENSSL ON CACHE BOOL "enable openssl")
Expand All @@ -92,29 +94,29 @@ set(ASAN_USE_DELETE OFF CACHE BOOL "use delele[] or free when asan enabled")
#查找openssl是否安装
#Find out if openssl is installed
find_package(OpenSSL QUIET)
if(OPENSSL_FOUND AND ENABLE_OPENSSL)
if (OPENSSL_FOUND AND ENABLE_OPENSSL)
message(STATUS "找到openssl库:\"${OPENSSL_INCLUDE_DIR}\",ENABLE_OPENSSL宏已打开")
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DENABLE_OPENSSL)
list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})
endif()
list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})
endif ()

#查找mysql是否安装
#Find out if mysql is installed
find_package(MYSQL QUIET)
if(MYSQL_FOUND AND ENABLE_MYSQL)
if (MYSQL_FOUND AND ENABLE_MYSQL)
message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
include_directories(${MYSQL_INCLUDE_DIR})
include_directories(${MYSQL_INCLUDE_DIR}/mysql)
add_definitions(-DENABLE_MYSQL)
list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
endif()
list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
endif ()

#是否使用delete[]替代free,用于解决开启asan后在MacOS上的卡死问题
#use delele[] or free when asan enabled
if(ASAN_USE_DELETE)
if (ASAN_USE_DELETE)
add_definitions(-DASAN_USE_DELETE)
endif()
endif ()

#打印库文件
#Print library files
Expand All @@ -123,20 +125,20 @@ message(STATUS "将链接依赖库:${LINK_LIB_LIST}")
#Enable c++11
set(CMAKE_CXX_STANDARD 11)

if(NOT WIN32)
if (NOT WIN32)
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-predefined-identifier-outside-function)
endif()
endif ()

#编译动态库
#Compile dynamic library
if(NOT IOS AND NOT ANDROID AND NOT WIN32)
if (NOT IOS AND NOT ANDROID AND NOT WIN32)
add_library(${PROJECT_NAME}_shared SHARED ${SRC_LIST})
target_include_directories(${PROJECT_NAME}_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(${PROJECT_NAME}_shared ${LINK_LIB_LIST})
set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
install(TARGETS ${PROJECT_NAME}_shared ARCHIVE DESTINATION ${INSTALL_PATH_LIB} LIBRARY DESTINATION ${INSTALL_PATH_LIB})
endif()
install(TARGETS ${PROJECT_NAME}_shared ARCHIVE DESTINATION ${INSTALL_PATH_LIB} LIBRARY DESTINATION ${INSTALL_PATH_LIB})
endif ()

#编译静态库
#Compile static library
Expand All @@ -152,6 +154,6 @@ install(TARGETS ${PROJECT_NAME}_static ARCHIVE DESTINATION ${INSTALL_PATH_LIB})

#测试程序
#Test program
if(NOT IOS)
if (NOT IOS)
add_subdirectory(tests)
endif()
endif ()

0 comments on commit 6a392de

Please sign in to comment.