-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
203 lines (171 loc) · 6.14 KB
/
CMakeLists.txt
File metadata and controls
203 lines (171 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# ====================================================================
# Vix.cpp - Async module
# - Standalone: find_package(async) works (asyncTargets + asyncConfig.cmake)
# - Umbrella : contributes to VixTargets only (umbrella owns packaging)
# ====================================================================
# Standalone vs Umbrella
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.20)
project(vix_async VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
include(GNUInstallDirs)
# Options + helpers
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AsyncOptions)
include(AsyncWarnings)
# ----------------------------------------------------
# Asio policy (same spirit as p2p)
# - Umbrella: must provide vix::thirdparty_asio
# - Standalone: allow module-local vendored Asio (third_party/asio) OR system headers
# ----------------------------------------------------
function(vix_async_link_asio onto link_scope)
# Umbrella mode
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
if (TARGET vix::thirdparty_asio)
get_target_property(_asio_inc vix::thirdparty_asio INTERFACE_INCLUDE_DIRECTORIES)
if (NOT _asio_inc)
message(FATAL_ERROR "[async] Umbrella build: vix::thirdparty_asio has no INTERFACE_INCLUDE_DIRECTORIES.")
endif()
target_include_directories(${onto} SYSTEM ${link_scope} ${_asio_inc})
target_compile_definitions(${onto} ${link_scope} VIX_ASYNC_WITH_ASIO=1)
return()
endif()
message(FATAL_ERROR "[async] Umbrella build: vix::thirdparty_asio must be provided by umbrella.")
endif()
# Standalone mode: try module-local first
set(_asio_local "${CMAKE_CURRENT_LIST_DIR}/third_party/asio/include")
if (EXISTS "${_asio_local}/asio.hpp")
target_include_directories(${onto} SYSTEM ${link_scope}
$<BUILD_INTERFACE:${_asio_local}>
)
target_compile_definitions(${onto} ${link_scope} VIX_ASYNC_WITH_ASIO=1)
message(STATUS "[async] Asio: using module-local Asio at ${_asio_local}")
return()
endif()
# System Asio (headers-only)
find_path(ASIO_INCLUDE_DIR
NAMES asio.hpp
HINTS
/usr/include
/usr/local/include
$ENV{ASIO_ROOT}/include
$ENV{ASIO_ROOT}
)
if (NOT ASIO_INCLUDE_DIR)
message(FATAL_ERROR
"[async] Asio not found.\n"
"Fix:\n"
" - vendor Asio in modules/async/third_party/asio/include\n"
" - or install standalone Asio headers\n"
" - or build inside Vix umbrella (provides vix::thirdparty_asio)\n"
)
endif()
target_include_directories(${onto} SYSTEM ${link_scope} "${ASIO_INCLUDE_DIR}")
target_compile_definitions(${onto} ${link_scope} VIX_ASYNC_WITH_ASIO=1)
message(STATUS "[async] Asio: using system Asio at ${ASIO_INCLUDE_DIR}")
endfunction()
# Common Asio requirements
function(vix_async_apply_asio_common onto link_scope)
target_compile_definitions(${onto} ${link_scope} ASIO_STANDALONE=1)
if (WIN32)
target_compile_definitions(${onto} ${link_scope} _WIN32_WINNT=0x0A00)
endif()
if (UNIX AND NOT APPLE)
target_link_libraries(${onto} ${link_scope} pthread)
endif()
endfunction()
# ----------------------------------------------------
# Library target
# ----------------------------------------------------
add_library(vix_async)
add_library(vix::async ALIAS vix_async)
target_compile_features(vix_async PUBLIC cxx_std_20)
# Public headers live under include/vix/async/...
target_include_directories(vix_async
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# Sources + headers
file(GLOB_RECURSE VIX_ASYNC_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)
file(GLOB_RECURSE VIX_ASYNC_HEADERS CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/include/vix/async/*.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/vix/async/*.h"
)
target_sources(vix_async
PRIVATE
${VIX_ASYNC_SOURCES}
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
FILES ${VIX_ASYNC_HEADERS}
)
# Asio link (policy)
vix_async_link_asio(vix_async PUBLIC)
vix_async_apply_asio_common(vix_async PUBLIC)
# Warnings / sanitizers (module local)
async_apply_warnings(vix_async)
set_target_properties(vix_async PROPERTIES
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME vix_async
EXPORT_NAME async
)
# ----------------------------------------------------
# Tests / Examples
# ----------------------------------------------------
include(CTest)
if (ASYNC_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if (ASYNC_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# ----------------------------------------------------
# Install + export
# - Standalone: installs asyncTargets + asyncConfig.cmake
# - Umbrella: contributes target to VixTargets only (umbrella owns packaging)
# ----------------------------------------------------
set(_ASYNC_EXPORT_SET "asyncTargets")
if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
set(_ASYNC_EXPORT_SET "VixTargets")
endif()
install(
TARGETS vix_async
EXPORT ${_ASYNC_EXPORT_SET}
FILE_SET HEADERS
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Standalone package exports (only when not built via umbrella)
if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
install(
EXPORT asyncTargets
NAMESPACE vix::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/async
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/asyncConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/asyncConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/asyncConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/async"
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/asyncConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/asyncConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/async
)
endif()