| 1 |
# ############################################################################## |
| 2 |
# Options |
| 3 |
|
| 4 |
include(Pj/Option) |
| 5 |
include(CMakeDependentOption) |
| 6 |
|
| 7 |
# Floating point support |
| 8 |
option(PJLIB_WITH_FLOATING_POINT "Enable floating point support" ON) |
| 9 |
|
| 10 |
# I/O queue backend |
| 11 |
pj_option(PJLIB_WITH_IOQUEUE "I/O Queue implementation backend" |
| 12 |
DEFAULT select |
| 13 |
ALLOWED_VALUES select kqueue epoll iocp |
| 14 |
) |
| 15 |
|
| 16 |
# Use `libuuid` for `UUID` handling implementation |
| 17 |
cmake_dependent_option(PJLIB_WITH_LIBUUID |
| 18 |
"Enable libuuid (Linux only)" ON |
| 19 |
"LINUX" OFF |
| 20 |
) |
| 21 |
|
| 22 |
# Enable SSL support with the selected implementation backend |
| 23 |
pj_option(PJLIB_WITH_SSL "Enable SSL support" |
| 24 |
DEFAULT openssl |
| 25 |
ALLOWED_VALUES openssl gnutls mbedtls darwin apple schannel |
| 26 |
) |
| 27 |
|
| 28 |
# ############################################################################## |
| 29 |
# Target |
| 30 |
|
| 31 |
add_library(pjlib |
| 32 |
src/pj/activesock.c |
| 33 |
src/pj/addr_resolv_sock.c |
| 34 |
src/pj/array.c |
| 35 |
src/pj/atomic_queue.cpp |
| 36 |
src/pj/atomic_slist.c |
| 37 |
src/pj/config.c |
| 38 |
src/pj/ctype.c |
| 39 |
src/pj/errno.c |
| 40 |
src/pj/except.c |
| 41 |
src/pj/fifobuf.c |
| 42 |
src/pj/guid.c |
| 43 |
src/pj/hash.c |
| 44 |
src/pj/ioqueue_dummy.c |
| 45 |
src/pj/ioqueue_epoll.c |
| 46 |
src/pj/ioqueue_kqueue.c |
| 47 |
src/pj/ioqueue_select.c |
| 48 |
src/pj/ip_helper_generic.c |
| 49 |
src/pj/list.c |
| 50 |
src/pj/lock.c |
| 51 |
src/pj/log.c |
| 52 |
src/pj/log_writer_stdout.c |
| 53 |
src/pj/os_info.c |
| 54 |
src/pj/os_time_common.c |
| 55 |
src/pj/os_timestamp_common.c |
| 56 |
src/pj/pool.c |
| 57 |
src/pj/pool_buf.c |
| 58 |
src/pj/pool_caching.c |
| 59 |
src/pj/pool_dbg.c |
| 60 |
src/pj/pool_policy_malloc.c |
| 61 |
src/pj/rand.c |
| 62 |
src/pj/rbtree.c |
| 63 |
src/pj/sock_bsd.c |
| 64 |
src/pj/sock_common.c |
| 65 |
src/pj/sock_qos_common.c |
| 66 |
src/pj/sock_qos_bsd.c |
| 67 |
src/pj/sock_qos_darwin.c |
| 68 |
src/pj/sock_select.c |
| 69 |
src/pj/ssl_sock_common.c |
| 70 |
src/pj/ssl_sock_darwin.c |
| 71 |
src/pj/ssl_sock_dump.c |
| 72 |
src/pj/ssl_sock_gtls.c |
| 73 |
src/pj/ssl_sock_mbedtls.c |
| 74 |
src/pj/ssl_sock_ossl.c |
| 75 |
src/pj/string.c |
| 76 |
src/pj/timer.c |
| 77 |
src/pj/types.c |
| 78 |
src/pj/unittest.c |
| 79 |
) |
| 80 |
|
| 81 |
# Ensure generated headers are found before source headers |
| 82 |
target_include_directories(pjlib |
| 83 |
PUBLIC |
| 84 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> |
| 85 |
) |
| 86 |
|
| 87 |
# headers |
| 88 |
target_sources(pjlib |
| 89 |
PUBLIC |
| 90 |
FILE_SET HEADERS |
| 91 |
BASE_DIRS |
| 92 |
include |
| 93 |
FILES |
| 94 |
include/pjlib.h |
| 95 |
include/pj/activesock.h |
| 96 |
include/pj/addr_resolv.h |
| 97 |
include/pj/argparse.h |
| 98 |
include/pj/array.h |
| 99 |
include/pj/assert.h |
| 100 |
include/pj/atomic_queue.h |
| 101 |
include/pj/atomic_slist.h |
| 102 |
include/pj/compat/assert.h |
| 103 |
include/pj/compat/cc_armcc.h |
| 104 |
include/pj/compat/cc_clang.h |
| 105 |
include/pj/compat/cc_codew.h |
| 106 |
include/pj/compat/cc_gcc.h |
| 107 |
include/pj/compat/cc_gcce.h |
| 108 |
include/pj/compat/cc_msvc.h |
| 109 |
include/pj/compat/cc_mwcc.h |
| 110 |
include/pj/compat/ctype.h |
| 111 |
include/pj/compat/errno.h |
| 112 |
include/pj/compat/high_precision.h |
| 113 |
include/pj/compat/limits.h |
| 114 |
include/pj/compat/m_alpha.h |
| 115 |
include/pj/compat/m_armv4.h |
| 116 |
include/pj/compat/m_i386.h |
| 117 |
include/pj/compat/m_m68k.h |
| 118 |
include/pj/compat/m_powerpc.h |
| 119 |
include/pj/compat/m_sparc.h |
| 120 |
include/pj/compat/m_x86_64.h |
| 121 |
include/pj/compat/malloc.h |
| 122 |
include/pj/compat/os_darwinos.h |
| 123 |
include/pj/compat/os_linux.h |
| 124 |
include/pj/compat/os_palmos.h |
| 125 |
include/pj/compat/os_rtems.h |
| 126 |
include/pj/compat/os_sunos.h |
| 127 |
include/pj/compat/os_symbian.h |
| 128 |
include/pj/compat/os_win32.h |
| 129 |
include/pj/compat/os_win32_wince.h |
| 130 |
include/pj/compat/os_winphone8.h |
| 131 |
include/pj/compat/os_winuwp.h |
| 132 |
include/pj/compat/rand.h |
| 133 |
include/pj/compat/setjmp.h |
| 134 |
include/pj/compat/size_t.h |
| 135 |
include/pj/compat/socket.h |
| 136 |
include/pj/compat/stdarg.h |
| 137 |
include/pj/compat/stdfileio.h |
| 138 |
include/pj/compat/string.h |
| 139 |
include/pj/compat/time.h |
| 140 |
include/pj/config.h |
| 141 |
include/pj/ctype.h |
| 142 |
include/pj/doxygen.h |
| 143 |
include/pj/errno.h |
| 144 |
include/pj/except.h |
| 145 |
include/pj/fifobuf.h |
| 146 |
include/pj/file_access.h |
| 147 |
include/pj/file_io.h |
| 148 |
include/pj/guid.h |
| 149 |
include/pj/hash.h |
| 150 |
include/pj/ioqueue.h |
| 151 |
include/pj/ip_helper.h |
| 152 |
include/pj/limits.h |
| 153 |
include/pj/list.h |
| 154 |
include/pj/list_i.h |
| 155 |
include/pj/lock.h |
| 156 |
include/pj/log.h |
| 157 |
include/pj/math.h |
| 158 |
include/pj/os.h |
| 159 |
include/pj/pool.h |
| 160 |
include/pj/pool_alt.h |
| 161 |
include/pj/pool_buf.h |
| 162 |
include/pj/pool_i.h |
| 163 |
include/pj/rand.h |
| 164 |
include/pj/rbtree.h |
| 165 |
include/pj/sock.h |
| 166 |
include/pj/sock_qos.h |
| 167 |
include/pj/sock_select.h |
| 168 |
include/pj/ssl_sock.h |
| 169 |
include/pj/string.h |
| 170 |
include/pj/string_i.h |
| 171 |
include/pj/timer.h |
| 172 |
include/pj/types.h |
| 173 |
include/pj/unicode.h |
| 174 |
include/pj/unittest.h |
| 175 |
) |
| 176 |
|
| 177 |
# system APIs |
| 178 |
if(WIN32 OR CYGWIN OR MINGW) |
| 179 |
target_sources(pjlib |
| 180 |
PRIVATE |
| 181 |
src/pj/file_io_win32.c |
| 182 |
src/pj/guid_win32.c |
| 183 |
src/pj/os_core_win32.c |
| 184 |
src/pj/os_error_win32.c |
| 185 |
src/pj/os_time_win32.c |
| 186 |
src/pj/os_timestamp_win32.c |
| 187 |
src/pj/sock_qos_bsd.c |
| 188 |
src/pj/unicode_win32.c |
| 189 |
) |
| 190 |
else() |
| 191 |
target_sources(pjlib |
| 192 |
PRIVATE |
| 193 |
src/pj/file_access_unistd.c |
| 194 |
src/pj/file_io_ansi.c |
| 195 |
src/pj/os_core_unix.c |
| 196 |
src/pj/os_error_unix.c |
| 197 |
src/pj/os_time_unix.c |
| 198 |
src/pj/os_timestamp_posix.c |
| 199 |
) |
| 200 |
endif() |
| 201 |
|
| 202 |
# Apple-specific |
| 203 |
if(APPLE) |
| 204 |
target_sources(pjlib |
| 205 |
PRIVATE |
| 206 |
src/pj/os_core_darwin.m |
| 207 |
src/pj/ssl_sock_apple.m |
| 208 |
$<$<BOOL:${IOS}>:src/pj/os_info_iphone.m> |
| 209 |
) |
| 210 |
endif() |
| 211 |
|
| 212 |
# UUID |
| 213 |
if(ANDROID) |
| 214 |
target_sources(pjlib PRIVATE src/pj/guid_android.c) |
| 215 |
elseif(APPLE) |
| 216 |
target_sources(pjlib PRIVATE src/pj/guid_darwin.c) |
| 217 |
elseif(BSD) |
| 218 |
target_sources(pjlib PRIVATE src/pj/guid_bsd.c) |
| 219 |
elseif(WIN32 OR CYGWIN OR MINGW) |
| 220 |
target_sources(pjlib PRIVATE src/pj/file_access_win32.c) |
| 221 |
elseif(NOT PJLIB_WITH_LIBUUID) |
| 222 |
target_sources(pjlib PRIVATE src/pj/guid_simple.c) |
| 223 |
endif() |
| 224 |
|
| 225 |
# ############################################################################## |
| 226 |
# Dependencies |
| 227 |
|
| 228 |
# win32 |
| 229 |
include(CheckIncludeFile) |
| 230 |
if(WIN32 OR CYGWIN OR MINGW) |
| 231 |
check_include_file(winsock.h PJ_HAS_WINSOCK_H) |
| 232 |
check_include_file(winsock2.h PJ_HAS_WINSOCK2_H) |
| 233 |
check_include_file(mswsock.h PJ_HAS_MSWSOCK_H) |
| 234 |
check_include_file(ws2tcpip.h PJ_HAS_WS2TCPIP_H) |
| 235 |
|
| 236 |
target_link_libraries(pjlib PRIVATE ole32 winmm) |
| 237 |
if(PJ_HAS_WINSOCK2_H) |
| 238 |
target_link_libraries(pjlib PRIVATE ws2_32) |
| 239 |
elseif(PJ_HAS_WINSOCK_H) |
| 240 |
target_link_libraries(pjlib PRIVATE wsock32) |
| 241 |
endif() |
| 242 |
endif() |
| 243 |
|
| 244 |
# apple |
| 245 |
if(APPLE) |
| 246 |
find_library(CoreFoundation_LIBRARY CoreFoundation) |
| 247 |
if (CoreFoundation_LIBRARY) |
| 248 |
target_link_libraries(pjlib PRIVATE "${CoreFoundation_LIBRARY}") |
| 249 |
endif() |
| 250 |
endif() |
| 251 |
|
| 252 |
# math library |
| 253 |
if(NOT (WIN32 OR CYGWIN OR MINGW)) |
| 254 |
find_library(MATH_LIBRARY m) |
| 255 |
if(MATH_LIBRARY) |
| 256 |
target_link_libraries(pjlib PUBLIC m) |
| 257 |
elseif(PJLIB_WITH_FLOATING_POINT) |
| 258 |
pj_force_set(PJLIB_WITH_FLOATING_POINT OFF "math library not found") |
| 259 |
endif() |
| 260 |
endif() |
| 261 |
|
| 262 |
# threading library |
| 263 |
find_package(Threads) |
| 264 |
if(Threads_FOUND) |
| 265 |
target_link_libraries(pjlib PRIVATE Threads::Threads) |
| 266 |
endif() |
| 267 |
|
| 268 |
# uuid |
| 269 |
if(PJLIB_WITH_LIBUUID) |
| 270 |
find_package(UUID) |
| 271 |
if(UUID_FOUND) |
| 272 |
target_link_libraries(pjlib PRIVATE UUID::UUID) |
| 273 |
target_sources(pjlib PRIVATE src/pj/guid_uuid.c) |
| 274 |
else() |
| 275 |
pj_force_set(PJLIB_WITH_LIBUUID OFF "libuuid not found") |
| 276 |
target_sources(pjlib PRIVATE src/pj/guid_simple.c) |
| 277 |
endif() |
| 278 |
endif() |
| 279 |
|
| 280 |
# ssl |
| 281 |
add_library(pjlib-ssl INTERFACE) # a target to expose SSL deps |
| 282 |
if(PJLIB_WITH_SSL STREQUAL "openssl") |
| 283 |
find_package(OpenSSL COMPONENTS Crypto SSL MODULE) |
| 284 |
if(NOT OPENSSL_FOUND) |
| 285 |
find_package(OpenSSL COMPONENTS Crypto SSL CONFIG) |
| 286 |
endif() |
| 287 |
if(OPENSSL_FOUND) |
| 288 |
target_link_libraries(pjlib-ssl INTERFACE OpenSSL::Crypto OpenSSL::SSL) |
| 289 |
else() |
| 290 |
pj_force_set(PJLIB_WITH_SSL "" "OpenSSL not found") |
| 291 |
endif() |
| 292 |
elseif(PJLIB_WITH_SSL STREQUAL "gnutls") |
| 293 |
find_package(GnuTLS REQUIRED) |
| 294 |
target_link_libraries(pjlib-ssl INTERFACE GnuTLS::GnuTLS) |
| 295 |
elseif(PJLIB_WITH_SSL STREQUAL "mbedtls") |
| 296 |
find_package(MbedTLS CONFIG REQUIRED) |
| 297 |
target_link_libraries(pjlib-ssl |
| 298 |
INTERFACE |
| 299 |
MbedTLS::mbedtls |
| 300 |
MbedTLS::mbedcrypto |
| 301 |
MbedTLS::mbedx509 |
| 302 |
) |
| 303 |
elseif(PJLIB_WITH_SSL STREQUAL "darwin") |
| 304 |
message(FATAL_ERROR "TODO") |
| 305 |
elseif(PJLIB_WITH_SSL STREQUAL "darwin") |
| 306 |
message(FATAL_ERROR "TODO") |
| 307 |
elseif(PJLIB_WITH_SSL STREQUAL "apple") |
| 308 |
message(FATAL_ERROR "TODO") |
| 309 |
elseif(PJLIB_WITH_SSL STREQUAL "schannel") |
| 310 |
message(FATAL_ERROR "TODO") |
| 311 |
endif() |
| 312 |
target_link_libraries(pjlib PRIVATE pjlib-ssl) |
| 313 |
|
| 314 |
# ############################################################################## |
| 315 |
# Configuration |
| 316 |
|
| 317 |
# Do not attempt to guess default configuration |
| 318 |
target_compile_definitions(pjlib PUBLIC PJ_AUTOCONF=1) |
| 319 |
|
| 320 |
# architecture |
| 321 |
block(SCOPE_FOR VARIABLES) |
| 322 |
include(Pj/DetectArch) |
| 323 |
pj_detect_arch(arch) |
| 324 |
|
| 325 |
# architecture name |
| 326 |
set(PJ_M_NAME "${arch}") |
| 327 |
|
| 328 |
# architecture macros |
| 329 |
target_compile_definitions(pjlib PUBLIC |
| 330 |
$<$<STREQUAL:${arch},"i386">:PJ_M_I386=1> |
| 331 |
$<$<STREQUAL:${arch},"x86_64">:PJ_M_X86_64=1> |
| 332 |
$<$<STREQUAL:${arch},"ia64">:PJ_M_IA64=1> |
| 333 |
$<$<STREQUAL:${arch},"m68k">:PJ_M_M68K=1> |
| 334 |
$<$<STREQUAL:${arch},"alpha">:PJ_M_ALPHA=1> |
| 335 |
$<$<STREQUAL:${arch},"mips64">:PJ_M_MIPS=1> |
| 336 |
$<$<STREQUAL:${arch},"mips">:PJ_M_MIPS=1> |
| 337 |
$<$<STREQUAL:${arch},"sparc">:PJ_M_SPARC=1> |
| 338 |
$<$<STREQUAL:${arch},"arm64">:PJ_M_ARM64=1> |
| 339 |
$<$<STREQUAL:${arch},"armv7">:PJ_M_ARMV7=1> |
| 340 |
$<$<STREQUAL:${arch},"armv4">:PJ_M_ARMV4=1> |
| 341 |
$<$<STREQUAL:${arch},"powerpc">:PJ_M_POWERPC=1> |
| 342 |
$<$<STREQUAL:${arch},"nios2">:PJ_M_NIOS2=1> |
| 343 |
) |
| 344 |
|
| 345 |
# endianness detection |
| 346 |
include(TestBigEndian) |
| 347 |
test_big_endian(WORDS_BIGENDIAN) |
| 348 |
|
| 349 |
# floating point support |
| 350 |
if(PJLIB_WITH_FLOATING_POINT) |
| 351 |
set(PJ_HAS_FLOATING_POINT 1) |
| 352 |
else() |
| 353 |
set(PJ_HAS_FLOATING_POINT 0) |
| 354 |
endif() |
| 355 |
|
| 356 |
# write configured header |
| 357 |
configure_file( |
| 358 |
include/pj/compat/m_auto.h.cm |
| 359 |
include/pj/compat/m_auto.h |
| 360 |
@ONLY |
| 361 |
) |
| 362 |
endblock() |
| 363 |
|
| 364 |
# operating system |
| 365 |
block(SCOPE_FOR VARIABLES) |
| 366 |
# |
| 367 |
# os detection |
| 368 |
# |
| 369 |
|
| 370 |
string(TOLOWER ${CMAKE_SYSTEM_NAME} PJ_OS_NAME) |
| 371 |
|
| 372 |
if(ANDROID) |
| 373 |
set(PJ_ANDROID 1) |
| 374 |
elseif(WIN32 OR CYGWIN OR MINGW) |
| 375 |
set(PJ_WIN32 1) |
| 376 |
set(PJ_WIN32_WINNT 0x0501) |
| 377 |
set(WIN32_LEAN_AND_MEAN 1) |
| 378 |
set(NOMINMAX 1) |
| 379 |
|
| 380 |
if(CMAKE_SYSTEM_NAME MATCHES "_64-w64-mingw" |
| 381 |
OR CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64") |
| 382 |
set(PJ_WIN64 1) |
| 383 |
endif() |
| 384 |
elseif(APPLE) |
| 385 |
set(PJ_DARWINOS 1) |
| 386 |
elseif(LINUX) |
| 387 |
set(PJ_LINUX 1) |
| 388 |
elseif(BSD) |
| 389 |
set(PJ_BSD 1) |
| 390 |
else() |
| 391 |
# manual system name checks |
| 392 |
string(TOLOWER "${CMAKE_SYSTEM_NAME}" _system_name_lower) |
| 393 |
if(PJ_OS_NAME MATCHES "rtems") |
| 394 |
set(PJ_RTEMS 1) |
| 395 |
elseif(PJ_OS_NAME STREQUAL "sunos|solaris") |
| 396 |
set(PJ_SUNOS 1) |
| 397 |
endif() |
| 398 |
endif() |
| 399 |
|
| 400 |
set(PJ_HAS_ERRNO_VAR 1) |
| 401 |
set(PJ_HAS_HIGH_RES_TIMER 1) |
| 402 |
set(PJ_HAS_MALLOC 1) |
| 403 |
set(PJ_NATIVE_STRING_IS_UNICODE 0) |
| 404 |
set(PJ_ATOMIC_VALUE_TYPE "long") |
| 405 |
|
| 406 |
if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 407 |
set(PJ_POOL_ALIGNMENT 8) |
| 408 |
else() |
| 409 |
set(PJ_POOL_ALIGNMENT 4) |
| 410 |
endif() |
| 411 |
|
| 412 |
# |
| 413 |
# headers |
| 414 |
# |
| 415 |
|
| 416 |
check_include_file(arpa/inet.h PJ_HAS_ARPA_INET_H) |
| 417 |
check_include_file(assert.h PJ_HAS_ASSERT_H) |
| 418 |
check_include_file(ctype.h PJ_HAS_CTYPE_H) |
| 419 |
|
| 420 |
if(WIN32 OR CYGWIN OR MINGW) |
| 421 |
set(PJ_HAS_ERRNO_H 0) |
| 422 |
else() |
| 423 |
check_include_file(errno.h PJ_HAS_ERRNO_H) |
| 424 |
endif() |
| 425 |
|
| 426 |
check_include_file(fcntl.h PJ_HAS_FCNTL_H) |
| 427 |
check_include_file(ifaddrs.h PJ_HAS_IFADDRS_H) |
| 428 |
check_include_file(limits.h PJ_HAS_LIMITS_H) |
| 429 |
check_include_file(linux/socket.h PJ_HAS_LINUX_SOCKET_H) |
| 430 |
check_include_file(malloc.h PJ_HAS_MALLOC_H) |
| 431 |
check_include_file(netdb.h PJ_HAS_NETDB_H) |
| 432 |
check_include_file(netinet/in_systm.h PJ_HAS_NETINET_IN_SYSTM_H) |
| 433 |
check_include_file(netinet/in.h PJ_HAS_NETINET_IN_H) |
| 434 |
check_include_file(netinet/ip.h PJ_HAS_NETINET_IP_H) |
| 435 |
check_include_file(netinet/tcp.h PJ_HAS_NETINET_TCP_H) |
| 436 |
check_include_file(net/if.h PJ_HAS_NET_IF_H) |
| 437 |
check_include_file(semaphore.h PJ_HAS_SEMAPHORE_H) |
| 438 |
check_include_file(setjmp.h PJ_HAS_SETJMP_H) |
| 439 |
check_include_file(stdarg.h PJ_HAS_STDARG_H) |
| 440 |
check_include_file(stddef.h PJ_HAS_STDDEF_H) |
| 441 |
check_include_file(stdio.h PJ_HAS_STDIO_H) |
| 442 |
check_include_file(stdint.h PJ_HAS_STDINT_H) |
| 443 |
check_include_file(stdlib.h PJ_HAS_STDLIB_H) |
| 444 |
check_include_file(string.h PJ_HAS_STRING_H) |
| 445 |
check_include_file(inttypes.h PJ_HAS_INTTYPES_H) |
| 446 |
check_include_file(sys/ioctl.h PJ_HAS_SYS_IOCTL_H) |
| 447 |
check_include_file(sys/select.h PJ_HAS_SYS_SELECT_H) |
| 448 |
check_include_file(sys/socket.h PJ_HAS_SYS_SOCKET_H) |
| 449 |
check_include_file(sys/time.h PJ_HAS_SYS_TIME_H) |
| 450 |
check_include_file(sys/timeb.h PJ_HAS_SYS_TIMEB_H) |
| 451 |
check_include_file(sys/types.h PJ_HAS_SYS_TYPES_H) |
| 452 |
check_include_file(sys/filio.h PJ_HAS_SYS_FILIO_H) |
| 453 |
check_include_file(sys/sockio.h PJ_HAS_SYS_SOCKIO_H) |
| 454 |
check_include_file(sys/utsname.h PJ_HAS_SYS_UTSNAME_H) |
| 455 |
check_include_file(time.h PJ_HAS_TIME_H) |
| 456 |
check_include_file(unistd.h PJ_HAS_UNISTD_H) |
| 457 |
check_include_file(execinfo.h PJ_HAS_EXECINFO_H) |
| 458 |
|
| 459 |
if(ANDROID) |
| 460 |
set(PJ_HAS_ANDROID_ALARM_H 1) |
| 461 |
endif() |
| 462 |
|
| 463 |
# |
| 464 |
# functions |
| 465 |
# |
| 466 |
|
| 467 |
include(CheckSymbolExists) |
| 468 |
check_symbol_exists(localtime_r time.h PJ_HAS_LOCALTIME_R) |
| 469 |
check_symbol_exists(getifaddrs ifaddrs.h PJ_HAS_IFADDRS_H) |
| 470 |
check_symbol_exists(inet_aton arpa/inet.h PJ_SOCK_HAS_INET_ATON) |
| 471 |
check_symbol_exists(inet_pton arpa/inet.h PJ_SOCK_HAS_INET_PTON) |
| 472 |
check_symbol_exists(inet_ntop arpa/inet.h PJ_SOCK_HAS_INET_NTOP) |
| 473 |
check_symbol_exists(getaddrinfo netdb.h PJ_SOCK_HAS_GETADDRINFO) |
| 474 |
check_symbol_exists(socketpair sys/socket.h PJ_SOCK_HAS_SOCKETPAIR) |
| 475 |
|
| 476 |
# |
| 477 |
# compilation checks |
| 478 |
# |
| 479 |
|
| 480 |
include(CheckSourceCompiles) |
| 481 |
|
| 482 |
# determine if sockaddr_in has sin_len member |
| 483 |
check_source_compiles(C [=[ |
| 484 |
#include <sys/types.h> |
| 485 |
#include <sys/socket.h> |
| 486 |
#include <netinet/in.h> |
| 487 |
#include <arpa/inet.h> |
| 488 |
|
| 489 |
int main(void) { |
| 490 |
struct sockaddr_in a; |
| 491 |
a.sin_len=0; |
| 492 |
return 0; |
| 493 |
} |
| 494 |
]=] PJ_SOCKADDR_HAS_LEN) |
| 495 |
|
| 496 |
# determine if socklen_t is available |
| 497 |
check_source_compiles(C [=[ |
| 498 |
#include <sys/types.h> |
| 499 |
#include <sys/socket.h> |
| 500 |
|
| 501 |
int main(void) { |
| 502 |
socklen_t xxx = 0; |
| 503 |
return 0; |
| 504 |
} |
| 505 |
]=] PJ_HAS_SOCKLEN_T) |
| 506 |
|
| 507 |
# determine if IPV6_V6ONLY is available |
| 508 |
check_source_compiles(C [=[ |
| 509 |
#include <sys/socket.h> |
| 510 |
#include <netinet/in.h> |
| 511 |
|
| 512 |
int main(void) { |
| 513 |
int opt = IPV6_V6ONLY; |
| 514 |
return 0; |
| 515 |
} |
| 516 |
]=] PJ_SOCK_HAS_IPV6_V6ONLY) |
| 517 |
|
| 518 |
# determine if SO_ERROR is available |
| 519 |
if(WIN32 OR CYGWIN OR MINGW) |
| 520 |
set(PJ_HAS_SO_ERROR 1) |
| 521 |
else() |
| 522 |
check_source_compiles(C [=[ |
| 523 |
#include <sys/types.h> |
| 524 |
#include <sys/socket.h> |
| 525 |
#include <netinet/in.h> |
| 526 |
#include <arpa/inet.h> |
| 527 |
|
| 528 |
int main(void) { |
| 529 |
int i=SO_ERROR; |
| 530 |
return 0; |
| 531 |
} |
| 532 |
]=] PJ_HAS_SO_ERROR) |
| 533 |
endif() |
| 534 |
|
| 535 |
# |
| 536 |
# pthread capabilities |
| 537 |
# |
| 538 |
|
| 539 |
if(UNIX) |
| 540 |
check_include_file(pthread.h PJ_HAS_PTHREAD_H) |
| 541 |
check_include_file(pthread_np.h PJ_HAS_PTHREAD_NP_H) |
| 542 |
endif() |
| 543 |
|
| 544 |
if(PJ_HAS_PTHREAD_H) |
| 545 |
# determine if RW-mutex is available |
| 546 |
check_source_compiles(C [=[ |
| 547 |
#include <pthread.h> |
| 548 |
|
| 549 |
int main(void) { |
| 550 |
pthread_rwlock_t *x; |
| 551 |
return 0; |
| 552 |
} |
| 553 |
]=] _has_pthread_rwlock) |
| 554 |
|
| 555 |
# if rwmutex is not detected, check again but this time with |
| 556 |
# _POSIX_READER_WRITER_LOCKS defined (newlib needs this) |
| 557 |
if(NOT _has_pthread_rwlock) |
| 558 |
check_source_compiles(C [=[ |
| 559 |
#include <pthread.h> |
| 560 |
|
| 561 |
int main(void) { |
| 562 |
pthread_rwlock_t *x; |
| 563 |
return 0; |
| 564 |
} |
| 565 |
]=] _has_pthread_rwlock) |
| 566 |
endif() |
| 567 |
|
| 568 |
if(_has_pthread_rwlock) |
| 569 |
set(PJ_EMULATE_RWMUTEX 0) |
| 570 |
else() |
| 571 |
set(PJ_EMULATE_RWMUTEX 1) |
| 572 |
endif() |
| 573 |
|
| 574 |
unset(_has_pthread_rwlock) |
| 575 |
|
| 576 |
# do we have pthread_mutexattr_settype()? |
| 577 |
check_source_compiles(C [=[ |
| 578 |
#include <pthread.h> |
| 579 |
|
| 580 |
int main(void) { |
| 581 |
pthread_mutexattr_settype(0, PTHREAD_MUTEX_FAST_NP); |
| 582 |
return 0; |
| 583 |
} |
| 584 |
]=] PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE) |
| 585 |
|
| 586 |
# does pthread_mutexattr_t has "recursive" member? |
| 587 |
check_source_compiles(C [=[ |
| 588 |
#include <pthread.h> |
| 589 |
|
| 590 |
int main(void) { |
| 591 |
pthread_mutexattr_t attr; |
| 592 |
attr.recursive=1; |
| 593 |
return 0; |
| 594 |
} |
| 595 |
]=] PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE) |
| 596 |
endif() |
| 597 |
|
| 598 |
|
| 599 |
if(PJ_HAS_PTHREAD_NP_H) |
| 600 |
check_symbol_exists(pthread_setname_np pthread_np.h |
| 601 |
PJ_HAS_PTHREAD_SETNAME_NP |
| 602 |
) |
| 603 |
check_symbol_exists(pthread_set_name_np pthread_np.h |
| 604 |
PJ_HAS_PTHREAD_SET_NAME_NP |
| 605 |
) |
| 606 |
endif() |
| 607 |
|
| 608 |
# |
| 609 |
# manual checks |
| 610 |
# |
| 611 |
|
| 612 |
# Determine if select() requires nfds to be filled up with |
| 613 |
# correct value (max_fd+1). If zero, nfds will be filled up with |
| 614 |
# PJ_FD_SETSIZE |
| 615 |
if(PJ_RTEMS) |
| 616 |
set(PJ_SELECT_NEEDS_NFDS 1) |
| 617 |
else() |
| 618 |
set(PJ_SELECT_NEEDS_NFDS 0) |
| 619 |
endif() |
| 620 |
|
| 621 |
# Determine if pj_thread_create() should enforce thread stack size when |
| 622 |
# creating thread. Default is zero, to allow OS to allocate appropriate |
| 623 |
# thread's stack size. |
| 624 |
if(PJ_RTEMS) |
| 625 |
set(PJ_THREAD_SET_STACK_SIZE 1) |
| 626 |
else() |
| 627 |
set(PJ_THREAD_SET_STACK_SIZE 0) |
| 628 |
endif() |
| 629 |
|
| 630 |
# Determine if pj_thread_create() should allocate thread's stack from |
| 631 |
# the pool. Default is zero, to let OS allocate thread's stack. |
| 632 |
if(PJ_RTEMS) |
| 633 |
set(PJ_THREAD_ALLOCATE_STACK 1) |
| 634 |
else() |
| 635 |
set(PJ_THREAD_ALLOCATE_STACK 0) |
| 636 |
endif() |
| 637 |
|
| 638 |
# This value specifies the value set in errno by the OS when a non-blocking |
| 639 |
# socket recv() can not return immediate data. |
| 640 |
if(WIN32 OR CYGWIN OR MINGW) |
| 641 |
set(PJ_BLOCKING_ERROR_VAL WSAEWOULDBLOCK) |
| 642 |
else() |
| 643 |
set(PJ_BLOCKING_ERROR_VAL EAGAIN) |
| 644 |
endif() |
| 645 |
|
| 646 |
# This value specifies the value set in errno by the OS when a non-blocking |
| 647 |
# socket connect() can not get connected immediately. |
| 648 |
if(WIN32 OR CYGWIN OR MINGW) |
| 649 |
set(PJ_BLOCKING_CONNECT_ERROR_VAL WSAEWOULDBLOCK) |
| 650 |
else() |
| 651 |
set(PJ_BLOCKING_CONNECT_ERROR_VAL EINPROGRESS) |
| 652 |
endif() |
| 653 |
|
| 654 |
# |
| 655 |
# configuration checks |
| 656 |
# |
| 657 |
|
| 658 |
# i/o queue implementation |
| 659 |
if(NOT PJLIB_WITH_IOQUEUE STREQUAL "") |
| 660 |
string(TOUPPER "PJ_IOQUEUE_IMP_${PJLIB_WITH_IOQUEUE}" PJ_IOQUEUE_IMP) |
| 661 |
else() |
| 662 |
set(PJ_IOQUEUE_IMP "PJ_IOQUEUE_IMP_NONE") |
| 663 |
endif() |
| 664 |
|
| 665 |
# ssl |
| 666 |
if(NOT PJLIB_WITH_SSL STREQUAL "") |
| 667 |
set(PJ_HAS_SSL_SOCK 1) |
| 668 |
string(TOUPPER "PJ_SSL_SOCK_IMP_${PJLIB_WITH_SSL}" PJ_SSL_SOCK_IMP) |
| 669 |
else() |
| 670 |
set(PJ_HAS_SSL_SOCK 0) |
| 671 |
set(PJ_SSL_SOCK_IMP "PJ_SSL_SOCK_IMP_NONE") |
| 672 |
endif() |
| 673 |
|
| 674 |
# write configured header |
| 675 |
configure_file( |
| 676 |
include/pj/compat/os_auto.h.cm |
| 677 |
include/pj/compat/os_auto.h |
| 678 |
@ONLY |
| 679 |
) |
| 680 |
endblock() |
| 681 |
|
| 682 |
# generate a dummy `pj/config_site.h` if it does not exist |
| 683 |
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/pj/config_site.h") |
| 684 |
file(TOUCH "${CMAKE_CURRENT_SOURCE_DIR}/include/pj/config_site.h") |
| 685 |
endif() |
| 686 |
|
| 687 |
# add generated files includes |
| 688 |
target_sources(pjlib |
| 689 |
PUBLIC |
| 690 |
FILE_SET config_headers TYPE HEADERS |
| 691 |
BASE_DIRS |
| 692 |
"${CMAKE_CURRENT_BINARY_DIR}/include" |
| 693 |
"${CMAKE_CURRENT_SOURCE_DIR}/include" |
| 694 |
FILES |
| 695 |
"${CMAKE_CURRENT_SOURCE_DIR}/include/pj/config_site.h" |
| 696 |
"${CMAKE_CURRENT_BINARY_DIR}/include/pj/compat/m_auto.h" |
| 697 |
"${CMAKE_CURRENT_BINARY_DIR}/include/pj/compat/os_auto.h" |
| 698 |
) |
| 699 |
|
| 700 |
# ############################################################################## |
| 701 |
# pjlib test application |
| 702 |
|
| 703 |
if(BUILD_TESTING) |
| 704 |
add_executable(pjlib-test |
| 705 |
src/pjlib-test/activesock.c |
| 706 |
src/pjlib-test/atomic.c |
| 707 |
src/pjlib-test/atomic_slist.c |
| 708 |
src/pjlib-test/echo_clt.c |
| 709 |
src/pjlib-test/errno.c |
| 710 |
src/pjlib-test/exception.c |
| 711 |
src/pjlib-test/fifobuf.c |
| 712 |
src/pjlib-test/file.c |
| 713 |
src/pjlib-test/hash_test.c |
| 714 |
src/pjlib-test/ioq_perf.c |
| 715 |
src/pjlib-test/ioq_udp.c |
| 716 |
src/pjlib-test/ioq_stress_test.c |
| 717 |
src/pjlib-test/ioq_unreg.c |
| 718 |
src/pjlib-test/ioq_tcp.c |
| 719 |
src/pjlib-test/ioq_iocp_unreg_test.c |
| 720 |
src/pjlib-test/list.c |
| 721 |
src/pjlib-test/mutex.c |
| 722 |
src/pjlib-test/os.c |
| 723 |
src/pjlib-test/pool.c |
| 724 |
src/pjlib-test/pool_perf.c |
| 725 |
src/pjlib-test/rand.c |
| 726 |
src/pjlib-test/rbtree.c |
| 727 |
src/pjlib-test/select.c |
| 728 |
src/pjlib-test/sleep.c |
| 729 |
src/pjlib-test/sock.c |
| 730 |
src/pjlib-test/sock_perf.c |
| 731 |
src/pjlib-test/ssl_sock.c |
| 732 |
src/pjlib-test/ssl_sock_stress.c |
| 733 |
src/pjlib-test/string.c |
| 734 |
src/pjlib-test/test.c |
| 735 |
src/pjlib-test/thread.c |
| 736 |
src/pjlib-test/timer.c |
| 737 |
src/pjlib-test/timestamp.c |
| 738 |
src/pjlib-test/udp_echo_srv_sync.c |
| 739 |
src/pjlib-test/udp_echo_srv_ioqueue.c |
| 740 |
src/pjlib-test/unittest_test.c |
| 741 |
src/pjlib-test/util.c |
| 742 |
src/pjlib-test/${PJ_TEST_MAIN} |
| 743 |
) |
| 744 |
|
| 745 |
target_link_libraries(pjlib-test PRIVATE pjlib pjlib-ssl) |
| 746 |
|
| 747 |
add_test(NAME pjlib-test COMMAND pjlib-test) |
| 748 |
endif() |
| 749 |
|
| 750 |
# ############################################################################## |
| 751 |
# pjlib++ |
| 752 |
|
| 753 |
add_library(pjlib++ INTERFACE) |
| 754 |
|
| 755 |
# headers |
| 756 |
target_sources(pjlib++ |
| 757 |
INTERFACE |
| 758 |
FILE_SET HEADERS |
| 759 |
BASE_DIRS |
| 760 |
include/ |
| 761 |
FILES |
| 762 |
include/pjlib++.hpp |
| 763 |
include/pj++/file.hpp |
| 764 |
include/pj++/hash.hpp |
| 765 |
include/pj++/list.hpp |
| 766 |
include/pj++/lock.hpp |
| 767 |
include/pj++/os.hpp |
| 768 |
include/pj++/pool.hpp |
| 769 |
include/pj++/proactor.hpp |
| 770 |
include/pj++/scanner.hpp |
| 771 |
include/pj++/sock.hpp |
| 772 |
include/pj++/string.hpp |
| 773 |
include/pj++/timer.hpp |
| 774 |
include/pj++/tree.hpp |
| 775 |
include/pj++/types.hpp |
| 776 |
) |
| 777 |
|
| 778 |
# dependencies |
| 779 |
target_link_libraries(pjlib++ INTERFACE pjlib) |
| 780 |
|
| 781 |
# ############################################################################## |
| 782 |
# pjlib++ test application |
| 783 |
|
| 784 |
if(BUILD_TESTING AND FALSE) # does not compile |
| 785 |
add_executable(pjlib++-test |
| 786 |
src/pjlib++-test/main.cpp |
| 787 |
) |
| 788 |
|
| 789 |
target_link_libraries(pjlib++-test PRIVATE pjlib++) |
| 790 |
|
| 791 |
add_test(NAME pjlib++-test COMMAND pjlib++-test) |
| 792 |
endif() |