88# Official repository: https://github.com/cppalliance/corosio
99#
1010
11- cmake_minimum_required (VERSION 3.8 ...3.31 )
12- set (BOOST_COROSIO_VERSION 1)
13- if (BOOST_SUPERPROJECT_VERSION)
11+ cmake_minimum_required (VERSION 3.14 ...3.31 )
12+
13+ if (BOOST_SUPERPROJECT_VERSION)
1414 set (BOOST_COROSIO_VERSION ${BOOST_SUPERPROJECT_VERSION} )
15- endif ()
15+ else ()
16+ set (BOOST_COROSIO_VERSION 1)
17+ endif ()
18+
1619project (boost_corosio VERSION "${BOOST_COROSIO_VERSION} " LANGUAGES CXX )
17- set (BOOST_COROSIO_IS_ROOT OFF )
18- if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
19- set (BOOST_COROSIO_IS_ROOT ON )
20- endif ()
2120
22- if (BOOST_COROSIO_IS_ROOT)
21+ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
22+ set (BOOST_COROSIO_IS_ROOT ON )
2323 include (CTest )
24+ else ()
25+ set (BOOST_COROSIO_IS_ROOT OFF )
2426endif ()
27+
2528option (BOOST_COROSIO_BUILD_TESTS "Build boost::corosio tests" ${BUILD_TESTING} )
2629option (BOOST_COROSIO_BUILD_PERF "Build boost::corosio performance tools" ${BOOST_COROSIO_IS_ROOT} )
2730option (BOOST_COROSIO_BUILD_EXAMPLES "Build boost::corosio examples" ${BOOST_COROSIO_IS_ROOT} )
2831option (BOOST_COROSIO_MRDOCS_BUILD "Building for MrDocs documentation generation" OFF )
2932
30- # Resolve sibling deps from boost tree via a single add_subdirectory call
31- if (BOOST_COROSIO_IS_ROOT)
32- set (_boost_sibling_libs)
33- if (NOT TARGET Boost::capy AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /../capy/CMakeLists.txt" )
34- list (APPEND _boost_sibling_libs capy)
35- endif ()
36- if (BOOST_COROSIO_BUILD_PERF AND NOT TARGET Boost::asio
37- AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /../asio/CMakeLists.txt" )
38- list (APPEND _boost_sibling_libs asio)
39- endif ()
40- if (_boost_sibling_libs)
41- set (BOOST_INCLUDE_LIBRARIES "${_boost_sibling_libs} " )
42- set (BOOST_EXCLUDE_LIBRARIES corosio)
43- set (CMAKE_FOLDER _deps)
44- add_subdirectory (../.. ${CMAKE_CURRENT_BINARY_DIR} /deps/boost EXCLUDE_FROM_ALL )
45- unset (CMAKE_FOLDER)
46- endif ()
47- unset (_boost_sibling_libs)
48- endif ()
49- if (NOT TARGET Boost::capy)
50- find_package (boost_capy QUIET )
51- endif ()
52- if (NOT TARGET Boost::capy)
53- include (FetchContent )
54-
55- # Match capy branch to corosio's current branch when possible
56- if (NOT DEFINED CACHE{BOOST_COROSIO_CAPY_TAG})
57- execute_process (
58- COMMAND git rev-parse --abbrev-ref HEAD
59- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
60- OUTPUT_VARIABLE _corosio_branch
61- OUTPUT_STRIP_TRAILING_WHITESPACE
62- ERROR_QUIET
63- RESULT_VARIABLE _git_result )
64- if (_git_result EQUAL 0 AND _corosio_branch)
65- execute_process (
66- COMMAND git ls-remote --heads
67- https://github.com/cppalliance/capy.git
68- ${_corosio_branch}
69- OUTPUT_VARIABLE _capy_has_branch
70- OUTPUT_STRIP_TRAILING_WHITESPACE
71- ERROR_QUIET )
72- if (_capy_has_branch)
73- set (_default_capy_tag "${_corosio_branch} " )
74- endif ()
75- endif ()
76- if (NOT DEFINED _default_capy_tag)
77- set (_default_capy_tag "develop" )
78- endif ()
79- endif ()
80- set (BOOST_COROSIO_CAPY_TAG "${_default_capy_tag} " CACHE STRING
81- "Git tag/branch for capy when fetching via FetchContent" )
82-
83- message (STATUS "Fetching capy..." )
84- set (BOOST_CAPY_BUILD_TESTS OFF CACHE BOOL "" FORCE )
85- set (BOOST_CAPY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
86- FetchContent_Declare (
87- capy
88- GIT_REPOSITORY https://github.com/cppalliance/capy.git
89- GIT_TAG ${BOOST_COROSIO_CAPY_TAG}
90- GIT_SHALLOW TRUE
91- )
92- FetchContent_MakeAvailable (capy)
93- endif ()
33+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
34+ include (CorosioBuild )
9435
95- find_package ( Threads REQUIRED )
36+ corosio_resolve_deps ( )
9637
9738set_property (GLOBAL PROPERTY USE_FOLDERS ON )
9839file (GLOB_RECURSE BOOST_COROSIO_HEADERS CONFIGURE_DEPENDS
@@ -106,172 +47,52 @@ source_group("" FILES "include/boost/corosio.hpp")
10647source_group (TREE "${CMAKE_CURRENT_SOURCE_DIR} /include/boost/corosio" PREFIX "include" FILES ${BOOST_COROSIO_HEADERS} )
10748source_group (TREE "${CMAKE_CURRENT_SOURCE_DIR} /src/corosio/src" PREFIX "src" FILES ${BOOST_COROSIO_SOURCES} )
10849
109- function (boost_corosio_setup_properties target )
110- target_compile_features (${target} PUBLIC cxx_std_20 )
111- target_include_directories (${target} PUBLIC
112- $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /include >)
113- target_include_directories (${target} PRIVATE
114- $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /src /corosio >)
115- target_link_libraries (${target}
116- PUBLIC
117- Boost::capy
118- Threads::Threads
119- $<$<PLATFORM_ID :Windows >:ws2_32 >)
120- target_compile_definitions (${target}
121- PUBLIC
122- BOOST_COROSIO_NO_LIB
123- $<$<PLATFORM_ID :Windows >:_WIN32_WINNT =0x0A00 >)
124- target_compile_definitions (${target} PRIVATE BOOST_COROSIO_SOURCE )
125- if (BUILD_SHARED_LIBS )
126- target_compile_definitions (${target} PUBLIC BOOST_COROSIO_DYN_LINK )
127- else ()
128- target_compile_definitions (${target} PUBLIC BOOST_COROSIO_STATIC_LINK )
129- endif ()
130- target_compile_options (${target}
131- PRIVATE
132- $<$<CXX_COMPILER_ID :GNU >:-fcoroutines >)
133- endfunction ()
134-
135- if (BOOST_COROSIO_MRDOCS_BUILD)
136- file (WRITE "${CMAKE_CURRENT_BINARY_DIR} /mrdocs.cpp"
137- "#include <boost/corosio.hpp>\n "
138- "#include <boost/corosio/native/native.hpp>\n " )
139- add_library (boost_corosio_mrdocs "${CMAKE_CURRENT_BINARY_DIR} /mrdocs.cpp" )
140- boost_corosio_setup_properties (boost_corosio_mrdocs )
141- target_compile_definitions (boost_corosio_mrdocs PUBLIC BOOST_COROSIO_MRDOCS )
142- set_target_properties (boost_corosio_mrdocs PROPERTIES EXPORT_COMPILE_COMMANDS ON )
143- return ()
144- endif ()
145-
14650add_library (boost_corosio ${BOOST_COROSIO_HEADERS} ${BOOST_COROSIO_SOURCES} )
14751add_library (Boost::corosio ALIAS boost_corosio )
148- boost_corosio_setup_properties (boost_corosio )
52+ target_compile_features (boost_corosio PUBLIC cxx_std_20 )
53+ target_include_directories (boost_corosio
54+ PUBLIC
55+ $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /include >
56+ PRIVATE
57+ $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /src /corosio >)
58+ target_link_libraries (boost_corosio
59+ PUBLIC
60+ Boost::capy
61+ Threads::Threads
62+ $<$<PLATFORM_ID :Windows >:ws2_32 >)
63+ target_compile_definitions (boost_corosio
64+ PUBLIC
65+ BOOST_COROSIO_NO_LIB
66+ $<$<PLATFORM_ID :Windows >:_WIN32_WINNT =0x0A00 >
67+ $<IF :$<BOOL :${BUILD_SHARED_LIBS} >,BOOST_COROSIO_DYN_LINK ,BOOST_COROSIO_STATIC_LINK >
68+ PRIVATE
69+ BOOST_COROSIO_SOURCE )
70+ target_compile_options (boost_corosio
71+ PRIVATE
72+ $<$<CXX_COMPILER_ID :GNU >:-fcoroutines >)
14973set_target_properties (boost_corosio PROPERTIES EXPORT_NAME corosio )
15074
151- list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
152- find_package (WolfSSL )
153- # MinGW's linker is single-pass and order-sensitive; system libs must follow
154- # the static libraries that reference them. Add as interface dependencies so
155- # CMake's dependency ordering places them after WolfSSL in the link command.
156- if (MINGW AND TARGET WolfSSL::WolfSSL)
157- set_property (TARGET WolfSSL::WolfSSL APPEND PROPERTY
158- INTERFACE_LINK_LIBRARIES ws2_32 crypt32 )
159- endif ()
160- if (WolfSSL_FOUND)
161- set (BOOST_COROSIO_WOLFSSL_HEADERS
162- "${CMAKE_CURRENT_SOURCE_DIR} /include/boost/corosio/wolfssl_stream.hpp" )
163- file (GLOB_RECURSE BOOST_COROSIO_WOLFSSL_SOURCES CONFIGURE_DEPENDS
164- "${CMAKE_CURRENT_SOURCE_DIR} /src/wolfssl/src/*.hpp"
165- "${CMAKE_CURRENT_SOURCE_DIR} /src/wolfssl/src/*.cpp" )
166- source_group (TREE "${CMAKE_CURRENT_SOURCE_DIR} /include/boost/corosio" PREFIX "include" FILES ${BOOST_COROSIO_WOLFSSL_HEADERS} )
167- source_group (TREE "${CMAKE_CURRENT_SOURCE_DIR} /src/wolfssl/src" PREFIX "src" FILES ${BOOST_COROSIO_WOLFSSL_SOURCES} )
168- add_library (boost_corosio_wolfssl ${BOOST_COROSIO_WOLFSSL_HEADERS} ${BOOST_COROSIO_WOLFSSL_SOURCES} )
169- add_library (Boost::corosio_wolfssl ALIAS boost_corosio_wolfssl )
170- boost_corosio_setup_properties (boost_corosio_wolfssl )
171- set_target_properties (boost_corosio_wolfssl PROPERTIES EXPORT_NAME corosio_wolfssl )
172- target_link_libraries (boost_corosio_wolfssl PUBLIC boost_corosio )
173- # PUBLIC ensures WolfSSL is linked into final executables (static lib deps don't embed)
174- target_link_libraries (boost_corosio_wolfssl PUBLIC WolfSSL::WolfSSL )
175- # WolfSSL on Windows needs crypt32 for certificate store access.
176- # For MinGW, this is handled via WolfSSL::WolfSSL's interface deps (link order matters).
177- if (WIN32 AND NOT MINGW)
178- target_link_libraries (boost_corosio_wolfssl PUBLIC crypt32 )
179- endif ()
180- # WolfSSL on macOS uses Apple Security framework for certificate validation
181- if (APPLE )
182- target_link_libraries (boost_corosio_wolfssl PUBLIC "-framework CoreFoundation" "-framework Security" )
183- endif ()
184- target_compile_definitions (boost_corosio_wolfssl PUBLIC BOOST_COROSIO_HAS_WOLFSSL )
185- endif ()
186-
187- find_package (OpenSSL )
188- # MinGW's linker is single-pass and order-sensitive; system libs must follow
189- # the static libraries that reference them. Add as interface dependencies so
190- # CMake's dependency ordering places them after OpenSSL in the link command.
191- if (MINGW AND TARGET OpenSSL::Crypto)
192- set_property (TARGET OpenSSL::Crypto APPEND PROPERTY
193- INTERFACE_LINK_LIBRARIES ws2_32 crypt32 )
194- endif ()
195- if (OpenSSL_FOUND)
196- set (BOOST_COROSIO_OPENSSL_HEADERS
197- "${CMAKE_CURRENT_SOURCE_DIR} /include/boost/corosio/openssl_stream.hpp" )
198- file (GLOB_RECURSE BOOST_COROSIO_OPENSSL_SOURCES CONFIGURE_DEPENDS
199- "${CMAKE_CURRENT_SOURCE_DIR} /src/openssl/src/*.hpp"
200- "${CMAKE_CURRENT_SOURCE_DIR} /src/openssl/src/*.cpp" )
201- source_group (TREE "${CMAKE_CURRENT_SOURCE_DIR} /include/boost/corosio" PREFIX "include" FILES ${BOOST_COROSIO_OPENSSL_HEADERS} )
202- source_group (TREE "${CMAKE_CURRENT_SOURCE_DIR} /src/openssl/src" PREFIX "src" FILES ${BOOST_COROSIO_OPENSSL_SOURCES} )
203- add_library (boost_corosio_openssl ${BOOST_COROSIO_OPENSSL_HEADERS} ${BOOST_COROSIO_OPENSSL_SOURCES} )
204- add_library (Boost::corosio_openssl ALIAS boost_corosio_openssl )
205- boost_corosio_setup_properties (boost_corosio_openssl )
206- set_target_properties (boost_corosio_openssl PROPERTIES EXPORT_NAME corosio_openssl )
207- target_link_libraries (boost_corosio_openssl PUBLIC boost_corosio )
208- # PUBLIC ensures OpenSSL is linked into final executables (static lib deps don't embed)
209- target_link_libraries (boost_corosio_openssl PUBLIC OpenSSL::SSL OpenSSL::Crypto )
210- # OpenSSL on Windows needs ws2_32 and crypt32 for socket and cert APIs.
211- # For MinGW, this is handled via OpenSSL::Crypto's interface deps (link order matters).
212- if (WIN32 AND NOT MINGW)
213- target_link_libraries (boost_corosio_openssl PUBLIC ws2_32 crypt32 )
214- endif ()
215- target_compile_definitions (boost_corosio_openssl PUBLIC BOOST_COROSIO_HAS_OPENSSL )
216- endif ()
217-
218- # Install
219- set (_corosio_install_targets boost_corosio)
220- if (TARGET boost_corosio_openssl)
221- list (APPEND _corosio_install_targets boost_corosio_openssl)
222- endif ()
223- if (TARGET boost_corosio_wolfssl)
224- list (APPEND _corosio_install_targets boost_corosio_wolfssl)
75+ if (BOOST_COROSIO_MRDOCS_BUILD)
76+ corosio_setup_mrdocs ()
77+ return ()
22578endif ()
22679
227- if (BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13)
228- boost_install (
229- TARGETS ${_corosio_install_targets}
230- VERSION ${BOOST_SUPERPROJECT_VERSION}
231- HEADER_DIRECTORY include )
232- elseif (boost_capy_FOUND)
233- include (GNUInstallDirs )
234- include (CMakePackageConfigHelpers )
235-
236- # Set INSTALL_INTERFACE for standalone installs (boost_install handles
237- # this for superproject builds, including versioned-layout paths)
238- foreach (_t IN LISTS _corosio_install_targets)
239- target_include_directories (${_t} PUBLIC
240- $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >)
241- endforeach ()
242-
243- set (BOOST_COROSIO_INSTALL_CMAKEDIR
244- ${CMAKE_INSTALL_LIBDIR} /cmake/boost_corosio)
80+ corosio_find_tls_provider (wolfssl
81+ PACKAGE WolfSSL
82+ LINK_TARGETS WolfSSL::WolfSSL
83+ MINGW_TARGET WolfSSL::WolfSSL
84+ MINGW_LIBS ws2_32 crypt32
85+ WIN32_LIBS crypt32
86+ FRAMEWORKS CoreFoundation Security )
24587
246- install (TARGETS ${_corosio_install_targets}
247- EXPORT boost_corosio-targets
248- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
249- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
250- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
251- install (DIRECTORY include/
252- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
253- install (EXPORT boost_corosio-targets
254- NAMESPACE Boost::
255- DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR} )
88+ corosio_find_tls_provider (openssl
89+ PACKAGE OpenSSL
90+ LINK_TARGETS OpenSSL::SSL OpenSSL::Crypto
91+ MINGW_TARGET OpenSSL::Crypto
92+ MINGW_LIBS ws2_32 crypt32
93+ WIN32_LIBS ws2_32 crypt32 )
25694
257- configure_package_config_file (
258- cmake/boost_corosio-config.cmake.in
259- ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config.cmake
260- INSTALL_DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR} )
261- write_basic_package_version_file (
262- ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config-version.cmake
263- COMPATIBILITY SameMajorVersion )
264-
265- set (_corosio_config_files
266- ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config.cmake
267- ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config-version.cmake)
268- if (WolfSSL_FOUND)
269- list (APPEND _corosio_config_files
270- ${CMAKE_CURRENT_SOURCE_DIR} /cmake/FindWolfSSL.cmake)
271- endif ()
272- install (FILES ${_corosio_config_files}
273- DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR} )
274- endif ()
95+ corosio_install ()
27596
27697if (BOOST_COROSIO_BUILD_TESTS)
27798 add_subdirectory (test )
@@ -281,15 +102,6 @@ if (BOOST_COROSIO_BUILD_EXAMPLES)
281102 add_subdirectory (example )
282103endif ()
283104
284- if (BOOST_COROSIO_IS_ROOT AND BOOST_COROSIO_BUILD_PERF AND NOT TARGET Boost::asio)
285- find_package (Boost 1.84 QUIET COMPONENTS asio )
286- if (TARGET Boost::asio)
287- message (STATUS "Found system Boost.Asio — comparison benchmarks enabled" )
288- else ()
289- message (STATUS "Boost.Asio not found — comparison benchmarks disabled" )
290- endif ()
291- endif ()
292-
293105if (BOOST_COROSIO_BUILD_PERF)
294106 add_subdirectory (perf )
295107endif ()
0 commit comments