|
7 | 7 | # Official repository: https://github.com/cppalliance/capy |
8 | 8 | # |
9 | 9 |
|
10 | | -#------------------------------------------------- |
11 | | -# |
12 | | -# Find or fetch Boost.Asio |
13 | | -# |
14 | | -#------------------------------------------------- |
15 | | -if (NOT TARGET Boost::asio) |
16 | | - # Use BOOST_SRC_DIR if already defined, else check env, else use default |
17 | | - if (NOT DEFINED BOOST_SRC_DIR) |
18 | | - if (DEFINED ENV{BOOST_SRC_DIR}) |
19 | | - set(BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR}" CACHE STRING "Boost source dir") |
20 | | - else () |
21 | | - set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." CACHE STRING "Boost source dir") |
22 | | - endif () |
23 | | - endif () |
24 | | - |
25 | | - # Find absolute BOOST_SRC_DIR |
26 | | - if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR}) |
27 | | - set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}") |
28 | | - endif () |
29 | | - |
30 | | - # Validate BOOST_SRC_DIR |
31 | | - set(BOOST_SRC_DIR_IS_VALID ON) |
32 | | - foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs") |
33 | | - if (NOT EXISTS "${BOOST_SRC_DIR}/${F}") |
34 | | - set(BOOST_SRC_DIR_IS_VALID OFF) |
35 | | - break() |
36 | | - endif () |
37 | | - endforeach () |
38 | | - |
39 | | - if (BOOST_SRC_DIR_IS_VALID) |
40 | | - message(STATUS "Building with valid Boost src dir") |
41 | | - # From BOOST_SRC_DIR |
42 | | - set(BOOST_INCLUDE_LIBRARIES asio) |
43 | | - set(BOOST_EXCLUDE_LIBRARIES capy) |
44 | | - set(PREV_BUILD_TESTING ${BUILD_TESTING}) |
45 | | - set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) |
46 | | - add_subdirectory(${BOOST_SRC_DIR} ${CMAKE_CURRENT_BINARY_DIR}/_deps/boost EXCLUDE_FROM_ALL) |
47 | | - set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) |
48 | | - else () |
49 | | - # Try installed Boost package |
50 | | - find_package(Boost QUIET) |
51 | | - if (Boost_FOUND) |
52 | | - message(STATUS "Using installed Boost package for asio example") |
53 | | - if (NOT TARGET Boost::asio) |
54 | | - add_library(Boost::asio ALIAS Boost::headers) |
55 | | - endif () |
56 | | - else () |
57 | | - # Fallback: FetchContent |
58 | | - message(STATUS "No local Boost found, using FetchContent to download Boost") |
59 | | - include(FetchContent) |
60 | | - |
61 | | - # Policy CMP0135 (introduced in CMake 3.24) controls the timestamp behavior |
62 | | - # for files extracted from archives downloaded via FetchContent/ExternalProject. |
63 | | - # |
64 | | - # OLD behavior: Extracted files keep their original timestamps from the archive. |
65 | | - # This can cause build issues because archive timestamps are often |
66 | | - # older than dependent build files, triggering unnecessary rebuilds |
67 | | - # or causing "file has modification time in the future" warnings. |
68 | | - # |
69 | | - # NEW behavior: Extracted files get the current time (download time) as their |
70 | | - # timestamp, which avoids these timing-related build problems. |
71 | | - # |
72 | | - # We set NEW if the policy exists. On older CMake versions (< 3.24), the policy |
73 | | - # doesn't exist, so this block is skipped and FetchContent works normally. |
74 | | - # This avoids using DOWNLOAD_EXTRACT_TIMESTAMP directly in FetchContent_Declare, |
75 | | - # which would cause a parse error on CMake < 3.24 (unrecognized keyword). |
76 | | - if (POLICY CMP0135) |
77 | | - cmake_policy(SET CMP0135 NEW) |
78 | | - endif() |
79 | | - |
80 | | - set(BOOST_INCLUDE_LIBRARIES asio) |
81 | | - FetchContent_Declare( |
82 | | - boost |
83 | | - URL https://github.com/boostorg/boost/releases/download/boost-1.88.0/boost-1.88.0-cmake.tar.xz |
84 | | - ) |
85 | | - set(PREV_BUILD_TESTING ${BUILD_TESTING}) |
86 | | - set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) |
87 | | - FetchContent_MakeAvailable(boost) |
88 | | - set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) |
89 | | - endif () |
90 | | - endif () |
91 | | -endif () |
92 | | - |
93 | | -#------------------------------------------------- |
94 | | -# |
95 | | -# Example executables |
96 | | -# |
97 | | -#------------------------------------------------- |
98 | | -file(GLOB_RECURSE PFILES CONFIGURE_DEPENDS *.cpp *.hpp |
99 | | - CMakeLists.txt |
100 | | - Jamfile) |
101 | | - |
102 | | -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES}) |
103 | | - |
104 | | -# any_stream example (coroutine-based) |
105 | | -add_executable(capy_example_any_stream |
106 | | - any_stream.cpp |
107 | | - api/capy_streams.cpp |
108 | | - api/capy_streams.hpp) |
109 | | - |
110 | | -set_property(TARGET capy_example_any_stream |
111 | | - PROPERTY FOLDER "examples") |
112 | | - |
113 | | -target_link_libraries(capy_example_any_stream |
114 | | - Boost::capy |
115 | | - Boost::asio) |
116 | | - |
117 | | -# asio_callbacks example (callback-based with uni_stream) |
118 | | -add_executable(capy_example_asio_callbacks |
119 | | - asio_callbacks.cpp |
120 | | - api/capy_streams.cpp |
121 | | - api/capy_streams.hpp |
122 | | - api/uni_stream.hpp) |
123 | | - |
124 | | -set_property(TARGET capy_example_asio_callbacks |
125 | | - PROPERTY FOLDER "examples") |
126 | | - |
127 | | -target_link_libraries(capy_example_asio_callbacks |
128 | | - Boost::capy |
129 | | - Boost::asio) |
130 | | - |
131 | 10 | # use_capy example (use_capy completion token) |
132 | | -add_executable(capy_example_use_capy |
133 | | - use_capy_example.cpp |
134 | | - api/capy_streams.cpp |
135 | | - api/capy_streams.hpp |
136 | | - api/use_capy.hpp) |
| 11 | +add_executable(capy_example_asio_echo_server |
| 12 | + echo_server.cpp) |
137 | 13 |
|
138 | | -set_property(TARGET capy_example_use_capy |
| 14 | +set_property(TARGET capy_example_asio_echo_server |
139 | 15 | PROPERTY FOLDER "examples") |
140 | 16 |
|
141 | | -target_link_libraries(capy_example_use_capy |
| 17 | +target_link_libraries(capy_example_asio_echo_server |
142 | 18 | Boost::capy |
143 | 19 | Boost::asio) |
0 commit comments