57 lines
1.3 KiB
CMake
57 lines
1.3 KiB
CMake
add_library(asio_interface INTERFACE)
|
|
|
|
set(asio_root "${CMAKE_CURRENT_LIST_DIR}/asio-asio-1-38-0")
|
|
set(asio_include "${asio_root}/include")
|
|
|
|
target_include_directories(asio_interface INTERFACE
|
|
"${asio_include}"
|
|
)
|
|
|
|
target_compile_definitions(asio_interface INTERFACE
|
|
ASIO_STANDALONE
|
|
ASIO_SEPARATE_COMPILATION
|
|
ASIO_NO_TS_EXECUTORS
|
|
ASIO_NO_DYNAMIC_BUFFER_V1
|
|
)
|
|
if (WIN32)
|
|
target_compile_definitions(asio_interface INTERFACE _WIN32_WINNT=0x0602)
|
|
endif()
|
|
|
|
# 这个 Linux kernel header 路径不要在 Windows 下加
|
|
if (UNIX AND NOT APPLE)
|
|
target_include_directories(asio_interface INTERFACE
|
|
/usr/src/linux-headers-5.15.0-136-generic/include/generated/uapi
|
|
)
|
|
endif()
|
|
|
|
set(asio_srcs
|
|
"${asio_root}/src/asio.cpp"
|
|
)
|
|
|
|
find_package(OpenSSL QUIET)
|
|
|
|
if (OpenSSL_FOUND)
|
|
message(STATUS "OpenSSL found: enable Asio SSL")
|
|
|
|
list(APPEND asio_srcs
|
|
"${asio_root}/src/asio_ssl.cpp"
|
|
)
|
|
else()
|
|
message(WARNING "OpenSSL not found: Asio SSL disabled, asio_ssl.cpp will not be compiled")
|
|
endif()
|
|
|
|
add_library(asio_object STATIC
|
|
${asio_srcs}
|
|
)
|
|
target_compile_features(asio_object PRIVATE cxx_std_20)
|
|
|
|
target_link_libraries(asio_object PUBLIC
|
|
asio_interface
|
|
)
|
|
|
|
if (OpenSSL_FOUND)
|
|
target_link_libraries(asio_object PUBLIC
|
|
OpenSSL::SSL
|
|
OpenSSL::Crypto
|
|
)
|
|
endif() |