@@ -37,38 +37,106 @@ include(GNUInstallDirs)
3737# ----------------------------------------------------
3838# Asio (standalone, header-only)
3939# - Umbrella: must be provided by umbrella as vix::thirdparty_asio
40- # - Standalone: can use vendored copy under third_party/asio/include (or fail)
40+ # - Standalone: try to find a vendored copy by walking up directories:
41+ # - third_party/asio-src/asio/include/asio.hpp (umbrella layout)
42+ # - third_party/asio/include/asio.hpp (legacy layout)
43+ # - modules/p2p/third_party/asio/include/asio.hpp (module-local)
4144# ----------------------------------------------------
4245function (vix_p2p_link_asio onto link_scope )
46+ # -------------------------
47+ # Umbrella mode
48+ # -------------------------
4349 if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
4450 if (TARGET vix::thirdparty_asio)
4551 target_link_libraries (${onto} ${link_scope} vix::thirdparty_asio )
4652 target_compile_definitions (${onto} ${link_scope} VIX_P2P_WITH_ASIO=1 )
47- else ()
48- message (FATAL_ERROR "[p2p] Umbrella build: vix::thirdparty_asio must be provided by umbrella." )
53+ return ()
4954 endif ()
55+ message (FATAL_ERROR "[p2p] Umbrella build: vix::thirdparty_asio must be provided by umbrella." )
56+ endif ()
57+
58+ # -------------------------
59+ # Standalone mode
60+ # -------------------------
61+
62+ # Helper: walk up from a start dir and find asio.hpp under a relative path.
63+ function (_vix_find_asio_upwards out_dir start_dir rel_path )
64+ set (_cur "${start_dir} " )
65+ set (_found "" )
66+
67+ while (TRUE )
68+ if (EXISTS "${_cur} /${rel_path} /asio.hpp" )
69+ set (_found "${_cur} /${rel_path} " )
70+ break ()
71+ endif ()
72+
73+ get_filename_component (_parent "${_cur} " DIRECTORY )
74+ if (_parent STREQUAL _cur)
75+ break ()
76+ endif ()
77+ set (_cur "${_parent} " )
78+ endwhile ()
79+
80+ set (${out_dir} "${_found} " PARENT_SCOPE )
81+ endfunction ()
82+
83+ # 1) module-local (when p2p repo vendors its own Asio)
84+ set (_asio_local_p2p "${CMAKE_CURRENT_LIST_DIR} /third_party/asio/include" )
85+ set (_asio_local_http "${CMAKE_SOURCE_DIR} /third_party/asio/include" ) # if configuring from p2p_http root
86+ if (EXISTS "${_asio_local_p2p} /asio.hpp" )
87+ target_include_directories (${onto} SYSTEM ${link_scope} "${_asio_local_p2p} " )
88+ target_compile_definitions (${onto} ${link_scope} VIX_P2P_WITH_ASIO=1 )
89+ message (STATUS "[p2p] Asio: using module-local Asio at ${_asio_local_p2p} " )
90+ return ()
91+ endif ()
92+ if (EXISTS "${_asio_local_http} /asio.hpp" )
93+ target_include_directories (${onto} SYSTEM ${link_scope} "${_asio_local_http} " )
94+ target_compile_definitions (${onto} ${link_scope} VIX_P2P_WITH_ASIO=1 )
95+ message (STATUS "[p2p] Asio: using local Asio at ${_asio_local_http} " )
5096 return ()
5197 endif ()
5298
53- # Standalone mode (no umbrella)
54- # 1) Prefer vendored Asio inside p2p repo: p2p/third_party/asio/include
55- # 2) Fallback: umbrella-style layout: <root>/third_party/asio/include
56- set (_asio_dir_local "${CMAKE_CURRENT_SOURCE_DIR} /third_party/asio/include" )
57- set (_asio_dir_root "${CMAKE_SOURCE_DIR} /third_party/asio/include" )
99+ # 2) umbrella repo layout: third_party/asio-src/asio/include
100+ set (_asio_up "" )
101+ _vix_find_asio_upwards (_asio_up "${CMAKE_CURRENT_LIST_DIR} " "third_party/asio-src/asio/include" )
102+ if (_asio_up STREQUAL "" )
103+ _vix_find_asio_upwards (_asio_up "${CMAKE_SOURCE_DIR} " "third_party/asio-src/asio/include" )
104+ endif ()
58105
59- if (EXISTS " ${_asio_dir_local} /asio.hpp " )
60- target_include_directories (${onto} SYSTEM ${link_scope} "${_asio_dir_local } " )
106+ if (NOT _asio_up STREQUAL " " )
107+ target_include_directories (${onto} SYSTEM ${link_scope} "${_asio_up } " )
61108 target_compile_definitions (${onto} ${link_scope} VIX_P2P_WITH_ASIO=1 )
62- message (STATUS "[p2p] Asio: using vendored Asio at ${_asio_dir_local} " )
63- elseif (EXISTS "${_asio_dir_root} /asio.hpp" )
64- target_include_directories (${onto} SYSTEM ${link_scope} "${_asio_dir_root} " )
109+ message (STATUS "[p2p] Asio: found umbrella Asio at ${_asio_up} " )
110+ return ()
111+ endif ()
112+
113+ # 3) legacy layout: third_party/asio/include
114+ set (_asio_up_legacy "" )
115+ _vix_find_asio_upwards (_asio_up_legacy "${CMAKE_CURRENT_LIST_DIR} " "third_party/asio/include" )
116+ if (_asio_up_legacy STREQUAL "" )
117+ _vix_find_asio_upwards (_asio_up_legacy "${CMAKE_SOURCE_DIR} " "third_party/asio/include" )
118+ endif ()
119+
120+ if (NOT _asio_up_legacy STREQUAL "" )
121+ target_include_directories (${onto} SYSTEM ${link_scope} "${_asio_up_legacy} " )
65122 target_compile_definitions (${onto} ${link_scope} VIX_P2P_WITH_ASIO=1 )
66- message (STATUS "[p2p] Asio: using root Asio at ${_asio_dir_root} " )
67- else ()
68- message (FATAL_ERROR "[p2p] Asio missing. Provide Asio at ${_asio_dir_local} /asio.hpp (standalone) or ${_asio_dir_root} /asio.hpp." )
123+ message (STATUS "[p2p] Asio: found legacy Asio at ${_asio_up_legacy} " )
124+ return ()
69125 endif ()
126+
127+ message (FATAL_ERROR
128+ "[p2p] Asio missing.\n "
129+ "Searched:\n "
130+ " - ${_asio_local_p2p} /asio.hpp\n "
131+ " - ${_asio_local_http} /asio.hpp\n "
132+ " - <upwards>/third_party/asio-src/asio/include/asio.hpp\n "
133+ " - <upwards>/third_party/asio/include/asio.hpp\n "
134+ "Fix: ensure repo submodule 'third_party/asio-src' is present (umbrella),\n "
135+ "or vendor Asio inside modules/p2p/third_party/asio/include."
136+ )
70137endfunction ()
71138
139+
72140# Global settings
73141set (CMAKE_CXX_STANDARD 20)
74142set (CMAKE_CXX_STANDARD_REQUIRED ON )
0 commit comments