88# Official repository: https://github.com/cppalliance/corosio
99#
1010
11- #-------------------------------------------------
12- #
13- # Project
14- #
15- #-------------------------------------------------
1611cmake_minimum_required (VERSION 3.8...3.31 )
1712set (BOOST_COROSIO_VERSION 1)
1813if (BOOST_SUPERPROJECT_VERSION)
@@ -23,155 +18,63 @@ set(BOOST_COROSIO_IS_ROOT OFF)
2318if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
2419 set (BOOST_COROSIO_IS_ROOT ON )
2520endif ()
26- set (__ignore__ ${CMAKE_C_COMPILER} )
2721
28- #-------------------------------------------------
29- #
30- # Options
31- #
32- #-------------------------------------------------
33- if (BOOST_COROSIO_IS_ROOT)
22+ if (BOOST_COROSIO_IS_ROOT)
3423 include (CTest )
35- endif ()
24+ endif ()
3625option (BOOST_COROSIO_BUILD_TESTS "Build boost::corosio tests" ${BUILD_TESTING} )
3726option (BOOST_COROSIO_BUILD_PERF "Build boost::corosio performance tools" ${BOOST_COROSIO_IS_ROOT} )
3827option (BOOST_COROSIO_BUILD_EXAMPLES "Build boost::corosio examples" ${BOOST_COROSIO_IS_ROOT} )
39- option (BOOST_COROSIO_BUILD_DOCS "Build boost::corosio documentation" OFF )
4028option (BOOST_COROSIO_MRDOCS_BUILD "Building for MrDocs documentation generation" OFF )
4129
42- # Check if environment variable BOOST_SRC_DIR is set
43- if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR})
44- set (DEFAULT_BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR} " )
45- else ()
46- set (DEFAULT_BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../.." )
47- endif ()
48- set (BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use when running CMake from this directory" )
49-
50- #-------------------------------------------------
51- #
52- # Boost modules
53- #
54- #-------------------------------------------------
55- # corosio depends on capy
56- set (BOOST_COROSIO_DEPENDENCIES
57- Boost::capy)
58-
59- foreach (BOOST_COROSIO_DEPENDENCY ${BOOST_COROSIO_DEPENDENCIES} )
60- if (BOOST_COROSIO_DEPENDENCY MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$" )
61- list (APPEND BOOST_COROSIO_INCLUDE_LIBRARIES ${CMAKE_MATCH_1} )
62- endif ()
63- endforeach ()
64-
65- # Include asio which is needed by corosio's benchmarks
66- if (BOOST_COROSIO_BUILD_TESTS)
67- list (APPEND BOOST_COROSIO_INCLUDE_LIBRARIES asio)
68- endif ()
69-
70- # Include asio for benchmarks (comparison benchmarks)
71- if (BOOST_COROSIO_BUILD_PERF)
72- list (APPEND BOOST_COROSIO_INCLUDE_LIBRARIES asio)
73- endif ()
74-
75- # Complete dependency list
76- set (BOOST_INCLUDE_LIBRARIES ${BOOST_COROSIO_INCLUDE_LIBRARIES} )
77- set (BOOST_EXCLUDE_LIBRARIES corosio)
78-
79- #-------------------------------------------------
80- #
81- # Add Boost Subdirectory
82- #
83- #-------------------------------------------------
84- if (BOOST_COROSIO_IS_ROOT)
85- set (CMAKE_FOLDER Dependencies)
86- # Find absolute BOOST_SRC_DIR
87- if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR} )
88- set (BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR} /${BOOST_SRC_DIR} " )
89- endif ()
90-
91- # Validate BOOST_SRC_DIR
92- set (BOOST_SRC_DIR_IS_VALID ON )
93- foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs" )
94- if (NOT EXISTS "${BOOST_SRC_DIR} /${F} " )
95- message (STATUS "${BOOST_SRC_DIR} /${F} does not exist. Fallback to find_package." )
96- set (BOOST_SRC_DIR_IS_VALID OFF )
97- break ()
98- endif ()
99- endforeach ()
100-
101- # Create Boost interface targets
102- if (BOOST_SRC_DIR_IS_VALID)
103- # From BOOST_SRC_DIR
104- if (BUILD_SHARED_LIBS )
105- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
106- endif ()
107- set (PREV_BUILD_TESTING ${BUILD_TESTING} )
108- set (BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE )
109- add_subdirectory (${BOOST_SRC_DIR} Dependencies/boost EXCLUDE_FROM_ALL )
110- set (BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE )
111- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR} /tools/cmake/include" )
112- else ()
113- # Try installed Boost package first
114- find_package (Boost QUIET )
115- if (Boost_FOUND)
116- message (STATUS "Using installed Boost package" )
117- foreach (BOOST_INCLUDE_LIBRARY ${BOOST_COROSIO_INCLUDE_LIBRARIES} )
118- if (NOT TARGET Boost::${BOOST_INCLUDE_LIBRARY} )
119- add_library (Boost::${BOOST_INCLUDE_LIBRARY} ALIAS Boost::headers )
120- endif ()
121- endforeach ()
122- else ()
123- # Fallback: FetchContent to download Boost and capy
124- message (STATUS "No local Boost found, using FetchContent to download dependencies" )
125- include (FetchContent )
126-
127- # capy is not in Boost repo - exclude it from BOOST_INCLUDE_LIBRARIES
128- # before fetching Boost, then fetch capy separately
129- list (REMOVE_ITEM BOOST_INCLUDE_LIBRARIES capy)
130-
131- FetchContent_Declare (
132- boost
133- URL https://github.com/boostorg/boost/releases/download/boost-1.90.0/boost-1.90.0-cmake.tar.xz
134- DOWNLOAD_EXTRACT_TIMESTAMP TRUE
135- )
136-
137- FetchContent_Declare (
138- capy
139- GIT_REPOSITORY https://github.com/cppalliance/capy.git
140- GIT_TAG master
141- GIT_SHALLOW TRUE
142- )
143-
144- # Fetch Boost first
145- message (STATUS "Fetching Boost (this may take a while on first run)..." )
146- set (PREV_BUILD_TESTING ${BUILD_TESTING} )
147- set (BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE )
148- FetchContent_MakeAvailable (boost)
149- set (BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE )
30+ if (NOT TARGET Boost::capy)
31+ find_package (boost_capy QUIET )
32+ endif ()
33+ if (NOT TARGET Boost::capy)
34+ include (FetchContent )
15035
151- # Fetch capy from cppalliance/capy (not part of Boost)
152- message (STATUS "Fetching capy..." )
153- set (BOOST_CAPY_BUILD_TESTS OFF CACHE BOOL "" FORCE )
154- set (BOOST_CAPY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
155- FetchContent_MakeAvailable (capy)
36+ # Match capy branch to corosio's current branch when possible
37+ if (NOT DEFINED CACHE{BOOST_COROSIO_CAPY_TAG})
38+ execute_process (
39+ COMMAND git rev-parse --abbrev-ref HEAD
40+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
41+ OUTPUT_VARIABLE _corosio_branch
42+ OUTPUT_STRIP_TRAILING_WHITESPACE
43+ ERROR_QUIET
44+ RESULT_VARIABLE _git_result )
45+ if (_git_result EQUAL 0 AND _corosio_branch)
46+ execute_process (
47+ COMMAND git ls-remote --heads
48+ https://github.com/cppalliance/capy.git
49+ ${_corosio_branch}
50+ OUTPUT_VARIABLE _capy_has_branch
51+ OUTPUT_STRIP_TRAILING_WHITESPACE
52+ ERROR_QUIET )
53+ if (_capy_has_branch)
54+ set (_default_capy_tag "${_corosio_branch} " )
55+ endif ()
56+ endif ()
57+ if (NOT DEFINED _default_capy_tag)
58+ set (_default_capy_tag "develop" )
59+ endif ()
60+ endif ()
61+ set (BOOST_COROSIO_CAPY_TAG "${_default_capy_tag} " CACHE STRING
62+ "Git tag/branch for capy when fetching via FetchContent" )
15663
157- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${boost_SOURCE_DIR} /tools/cmake/include" )
158- endif ()
159- endif ()
160- unset (CMAKE_FOLDER)
161- endif ()
64+ message (STATUS "Fetching capy..." )
65+ set (BOOST_CAPY_BUILD_TESTS OFF CACHE BOOL "" FORCE )
66+ set (BOOST_CAPY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
67+ FetchContent_Declare (
68+ capy
69+ GIT_REPOSITORY https://github.com/cppalliance/capy.git
70+ GIT_TAG ${BOOST_COROSIO_CAPY_TAG}
71+ GIT_SHALLOW TRUE
72+ )
73+ FetchContent_MakeAvailable (capy)
74+ endif ()
16275
163- #-------------------------------------------------
164- #
165- # Threading support
166- #
167- #-------------------------------------------------
16876find_package (Threads REQUIRED )
16977
170- #-------------------------------------------------
171- #
172- # corosio library
173- #
174- #-------------------------------------------------
17578set_property (GLOBAL PROPERTY USE_FOLDERS ON )
17679file (GLOB_RECURSE BOOST_COROSIO_HEADERS CONFIGURE_DEPENDS
17780 "${CMAKE_CURRENT_SOURCE_DIR} /include/boost/corosio/*.hpp"
@@ -186,12 +89,13 @@ source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src/corosio/src" PREFIX "src" FIL
18689
18790function (boost_corosio_setup_properties target )
18891 target_compile_features (${target} PUBLIC cxx_std_20 )
189- target_include_directories (${target} PUBLIC "${PROJECT_SOURCE_DIR} /include" )
92+ target_include_directories (${target} PUBLIC
93+ $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /include >)
19094 target_include_directories (${target} PRIVATE
191- " $ {PROJECT_SOURCE_DIR} /src/corosio" )
95+ $< BUILD_INTERFACE : $ {PROJECT_SOURCE_DIR} /src /corosio > )
19296 target_link_libraries (${target}
19397 PUBLIC
194- ${BOOST_COROSIO_DEPENDENCIES}
98+ Boost::capy
19599 Threads::Threads
196100 $<$<PLATFORM_ID :Windows >:ws2_32 >)
197101 target_compile_definitions (${target}
@@ -209,11 +113,6 @@ function(boost_corosio_setup_properties target)
209113 $<$<CXX_COMPILER_ID :GNU >:-fcoroutines >)
210114endfunction ()
211115
212- #-------------------------------------------------
213- #
214- # MrDocs Build (minimal for documentation)
215- #
216- #-------------------------------------------------
217116if (BOOST_COROSIO_MRDOCS_BUILD)
218117 file (WRITE "${CMAKE_CURRENT_BINARY_DIR} /mrdocs.cpp"
219118 "#include <boost/corosio.hpp>\n " )
@@ -227,12 +126,8 @@ endif()
227126add_library (boost_corosio ${BOOST_COROSIO_HEADERS} ${BOOST_COROSIO_SOURCES} )
228127add_library (Boost::corosio ALIAS boost_corosio )
229128boost_corosio_setup_properties (boost_corosio )
129+ set_target_properties (boost_corosio PROPERTIES EXPORT_NAME corosio )
230130
231- #-------------------------------------------------
232- #
233- # WolfSSL
234- #
235- #-------------------------------------------------
236131list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
237132find_package (WolfSSL )
238133# MinGW's linker is single-pass and order-sensitive; system libs must follow
@@ -253,6 +148,7 @@ if (WolfSSL_FOUND)
253148 add_library (boost_corosio_wolfssl ${BOOST_COROSIO_WOLFSSL_HEADERS} ${BOOST_COROSIO_WOLFSSL_SOURCES} )
254149 add_library (Boost::corosio_wolfssl ALIAS boost_corosio_wolfssl )
255150 boost_corosio_setup_properties (boost_corosio_wolfssl )
151+ set_target_properties (boost_corosio_wolfssl PROPERTIES EXPORT_NAME corosio_wolfssl )
256152 target_link_libraries (boost_corosio_wolfssl PUBLIC boost_corosio )
257153 # PUBLIC ensures WolfSSL is linked into final executables (static lib deps don't embed)
258154 target_link_libraries (boost_corosio_wolfssl PUBLIC WolfSSL::WolfSSL )
@@ -268,11 +164,6 @@ if (WolfSSL_FOUND)
268164 target_compile_definitions (boost_corosio_wolfssl PUBLIC BOOST_COROSIO_HAS_WOLFSSL )
269165endif ()
270166
271- #-------------------------------------------------
272- #
273- # OpenSSL
274- #
275- #-------------------------------------------------
276167find_package (OpenSSL )
277168# MinGW's linker is single-pass and order-sensitive; system libs must follow
278169# the static libraries that reference them. Add as interface dependencies so
@@ -292,6 +183,7 @@ if (OpenSSL_FOUND)
292183 add_library (boost_corosio_openssl ${BOOST_COROSIO_OPENSSL_HEADERS} ${BOOST_COROSIO_OPENSSL_SOURCES} )
293184 add_library (Boost::corosio_openssl ALIAS boost_corosio_openssl )
294185 boost_corosio_setup_properties (boost_corosio_openssl )
186+ set_target_properties (boost_corosio_openssl PROPERTIES EXPORT_NAME corosio_openssl )
295187 target_link_libraries (boost_corosio_openssl PUBLIC boost_corosio )
296188 # PUBLIC ensures OpenSSL is linked into final executables (static lib deps don't embed)
297189 target_link_libraries (boost_corosio_openssl PUBLIC OpenSSL::SSL OpenSSL::Crypto )
@@ -303,29 +195,72 @@ if (OpenSSL_FOUND)
303195 target_compile_definitions (boost_corosio_openssl PUBLIC BOOST_COROSIO_HAS_OPENSSL )
304196endif ()
305197
306- #-------------------------------------------------
307- #
308- # Tests
309- #
310- #-------------------------------------------------
198+ # Install
199+ set (_corosio_install_targets boost_corosio)
200+ if (TARGET boost_corosio_openssl)
201+ list (APPEND _corosio_install_targets boost_corosio_openssl)
202+ endif ()
203+ if (TARGET boost_corosio_wolfssl)
204+ list (APPEND _corosio_install_targets boost_corosio_wolfssl)
205+ endif ()
206+
207+ if (BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13)
208+ boost_install (
209+ TARGETS ${_corosio_install_targets}
210+ VERSION ${BOOST_SUPERPROJECT_VERSION}
211+ HEADER_DIRECTORY include )
212+ elseif (boost_capy_FOUND)
213+ include (GNUInstallDirs )
214+ include (CMakePackageConfigHelpers )
215+
216+ # Set INSTALL_INTERFACE for standalone installs (boost_install handles
217+ # this for superproject builds, including versioned-layout paths)
218+ foreach (_t IN LISTS _corosio_install_targets)
219+ target_include_directories (${_t} PUBLIC
220+ $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >)
221+ endforeach ()
222+
223+ set (BOOST_COROSIO_INSTALL_CMAKEDIR
224+ ${CMAKE_INSTALL_LIBDIR} /cmake/boost_corosio)
225+
226+ install (TARGETS ${_corosio_install_targets}
227+ EXPORT boost_corosio-targets
228+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
229+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
230+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
231+ install (DIRECTORY include/
232+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
233+ install (EXPORT boost_corosio-targets
234+ NAMESPACE Boost::
235+ DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR} )
236+
237+ configure_package_config_file (
238+ cmake/boost_corosio-config.cmake.in
239+ ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config.cmake
240+ INSTALL_DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR} )
241+ write_basic_package_version_file (
242+ ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config-version.cmake
243+ COMPATIBILITY SameMajorVersion )
244+
245+ set (_corosio_config_files
246+ ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config.cmake
247+ ${CMAKE_CURRENT_BINARY_DIR} /boost_corosio-config-version.cmake)
248+ if (WolfSSL_FOUND)
249+ list (APPEND _corosio_config_files
250+ ${CMAKE_CURRENT_SOURCE_DIR} /cmake/FindWolfSSL.cmake)
251+ endif ()
252+ install (FILES ${_corosio_config_files}
253+ DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR} )
254+ endif ()
255+
311256if (BOOST_COROSIO_BUILD_TESTS)
312257 add_subdirectory (test )
313258endif ()
314259
315- #-------------------------------------------------
316- #
317- # Examples
318- #
319- #-------------------------------------------------
320260if (BOOST_COROSIO_BUILD_EXAMPLES)
321261 add_subdirectory (example )
322262endif ()
323263
324- #-------------------------------------------------
325- #
326- # Performance tools
327- #
328- #-------------------------------------------------
329264if (BOOST_COROSIO_BUILD_PERF)
330265 add_subdirectory (perf )
331266endif ()
0 commit comments