Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module(name = "com_github_async_simple")

bazel_dep(name = "asio", version = "1.34.2")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "libaio", version = "0.3.113.bcr.0")
bazel_dep(name = "platforms", version = "1.0.0")
Expand Down
49 changes: 49 additions & 0 deletions cmake/Findasio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
include(FetchContent)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(ASIO_PC QUIET asio)
endif()

find_path(
ASIO_INCLUDE_DIR
NAMES asio.hpp
HINTS ${ASIO_PC_INCLUDE_DIRS} /usr/include /usr/local/include
)

if(ASIO_INCLUDE_DIR)
message(STATUS "[Asio] Found system Asio at: ${ASIO_INCLUDE_DIR}")

if(NOT TARGET asio::asio)
add_library(asio::asio INTERFACE IMPORTED GLOBAL)
target_include_directories(asio::asio INTERFACE "${ASIO_INCLUDE_DIR}")
target_compile_definitions(asio::asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
endif()
else()
message(STATUS "[Asio] System Asio not found — fetching via FetchContent")

FetchContent_Declare(
asio
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
GIT_TAG asio-1-34-2
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(asio)

if(NOT TARGET asio::asio)
add_library(asio::asio INTERFACE IMPORTED GLOBAL)
target_include_directories(asio::asio INTERFACE "${asio_SOURCE_DIR}/asio/include")
target_compile_definitions(asio::asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
endif()

set(ASIO_INCLUDE_DIR
"${asio_SOURCE_DIR}/asio/include"
CACHE PATH
"Asio include directory (fetched)"
FORCE
)
endif()

set(ASIO_FOUND TRUE CACHE BOOL "Asio available")
set(ASIO_INCLUDE_DIRS "${ASIO_INCLUDE_DIR}" CACHE PATH "Asio include dirs")
mark_as_advanced(ASIO_INCLUDE_DIR ASIO_INCLUDE_DIRS ASIO_FOUND)
15 changes: 2 additions & 13 deletions demo_example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//bazel/config:copt.bzl", "ASYNC_SIMPLE_COPTS")

cc_library(
name = "asio",
hdrs = glob([
"asio/**/*.hpp",
"asio/**/*.ipp",
]),
includes = ["asio"],
visibility = ["//visibility:public"],
)

cc_library(
name = "hdrs_dep",
hdrs = [
"asio_coro_util.hpp",
"asio_util.hpp",
],
deps = [
":asio",
"//:async_simple",
"//:simple_executors",
"@asio",
],
)

Expand Down Expand Up @@ -73,8 +63,7 @@ cc_library(
name = "http_hdrs_dep",
hdrs = glob([
"http/**/*.hpp",
"io_context_pool.hpp",
]),
]) + ["io_context_pool.hpp"],
visibility = ["//visibility:public"],
deps = [":hdrs_dep"],
)
Expand Down
52 changes: 26 additions & 26 deletions demo_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" AND
NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()

add_executable(CountChar CountChar.cpp)
target_link_libraries(CountChar async_simple)

if (${ASYNC_SIMPLE_BUILD_MODULES})
if(${ASYNC_SIMPLE_BUILD_MODULES})
add_executable(CountCharUsingModules CountCharUsingModules.cpp)
target_link_libraries(CountCharUsingModules async_simple)
endif()
Expand All @@ -15,58 +14,59 @@ add_executable(ReadFiles ReadFiles.cpp)
target_link_libraries(ReadFiles async_simple)

if(NOT ASYNC_SIMPLE_DISABLE_AIO AND LIBAIO_INCLUDE_DIR AND LIBAIO_LIBRARIES)
target_link_libraries(ReadFiles ${LIBAIO_LIBRARIES})
target_link_libraries(ReadFiles ${LIBAIO_LIBRARIES})
endif()

add_custom_command(
TARGET ReadFiles POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/Input
${CMAKE_CURRENT_BINARY_DIR}/Input)
TARGET ReadFiles
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Input
${CMAKE_CURRENT_BINARY_DIR}/Input
)

include_directories(asio)
find_package(asio)

add_executable(async_echo_server async_echo_server.cpp)
target_link_libraries(async_echo_server async_simple)
target_link_libraries(async_echo_server async_simple asio::asio)

add_executable(async_echo_client async_echo_client.cpp)
target_link_libraries(async_echo_client async_simple)
target_link_libraries(async_echo_client async_simple asio::asio)

add_executable(async_multiple_core_echo_server async_multiple_core_echo_server.cpp)
target_link_libraries(async_multiple_core_echo_server async_simple)
target_link_libraries(async_multiple_core_echo_server async_simple asio::asio)

add_executable(block_echo_server block_echo_server.cpp)
target_link_libraries(block_echo_server ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(block_echo_server ${CMAKE_THREAD_LIBS_INIT} asio::asio)

add_executable(block_echo_client block_echo_client.cpp)
target_link_libraries(block_echo_client ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(block_echo_client ${CMAKE_THREAD_LIBS_INIT} asio::asio)

add_executable(http_server http/coroutine_http/http_server.cpp)
target_link_libraries(http_server async_simple)
target_link_libraries(http_server async_simple asio::asio)

add_executable(multiple_core_http_server http/coroutine_http/multiple_core_http_server.cpp)
target_link_libraries(multiple_core_http_server async_simple)
target_link_libraries(multiple_core_http_server async_simple asio::asio)

add_executable(http_client http/coroutine_http/http_client.cpp)
target_link_libraries(http_client async_simple)
target_link_libraries(http_client async_simple asio::asio)

add_executable(block_http_server http/block_http/block_http_server.cpp)
target_link_libraries(block_http_server async_simple)
target_link_libraries(block_http_server async_simple asio::asio)

add_executable(pmr_lazy pmr_lazy.cpp)
target_link_libraries(pmr_lazy async_simple)
target_link_libraries(pmr_lazy async_simple asio::asio)

SET(ENABLE_SSL OFF)
set(ENABLE_SSL OFF)

if (ENABLE_SSL)
if(ENABLE_SSL)
find_package(OpenSSL REQUIRED)
add_definitions(-DENABLE_SSL)
message(STATUS "Use SSL")
endif()

add_executable(smtp_client smtp/smtp_client.cpp)
if (ENABLE_SSL)
target_link_libraries(smtp_client async_simple ${CMAKE_THREAD_LIBS_INIT} OpenSSL::SSL)
else()
target_link_libraries(smtp_client async_simple ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(smtp_client async_simple ${CMAKE_THREAD_LIBS_INIT} asio::asio)
if(ENABLE_SSL)
target_link_libraries(smtp_client OpenSSL::SSL)
endif()
4 changes: 0 additions & 4 deletions demo_example/asio/COPYING

This file was deleted.

23 changes: 0 additions & 23 deletions demo_example/asio/LICENSE_1_0.txt

This file was deleted.

Loading
Loading