File: AwsThreadName.cmake

package info (click to toggle)
aws-crt-python 0.16.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 78,328 kB
  • sloc: ansic: 330,743; python: 18,949; makefile: 6,271; sh: 3,712; asm: 754; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (59 lines) | stat: -rw-r--r-- 1,763 bytes parent folder | download
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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

include(CheckSymbolExists)

# Check how the platform supports setting thread name
function(aws_set_thread_name_method target)

    if (WINDOWS)
        # On Windows we do a runtime check, instead of compile-time check
        return()
    elseif (APPLE)
        # All Apple platforms we support have the same function, so no need for compile-time check.
        return()
    endif()

    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
    list(APPEND CMAKE_REQUIRED_LIBRARIES pthread)

    # The start of the test program
    set(c_source_start "
        #define _GNU_SOURCE
        #include <pthread.h>

        #if defined(__FreeBSD__) || defined(__NETBSD__)
        #include <pthread_np.h>
        #endif

        int main() {
            pthread_t thread_id;
        ")

    # The end of the test program
    set(c_source_end "}")

    # pthread_setname_np() usually takes 2 args
    check_c_source_compiles("
        ${c_source_start}
        pthread_setname_np(thread_id, \"asdf\");
        ${c_source_end}"
        PTHREAD_SETNAME_TAKES_2ARGS)
    if (PTHREAD_SETNAME_TAKES_2ARGS)
        target_compile_definitions(${target} PRIVATE -DAWS_PTHREAD_SETNAME_TAKES_2ARGS)
        return()
    endif()

    # But on NetBSD it takes 3!
    check_c_source_compiles("
        ${c_source_start}
        pthread_setname_np(thread_id, \"asdf\", NULL);
        ${c_source_end}
        " PTHREAD_SETNAME_TAKES_3ARGS)
    if (PTHREAD_SETNAME_TAKES_3ARGS)
        target_compile_definitions(${target} PRIVATE -DAWS_PTHREAD_SETNAME_TAKES_3ARGS)
        return()
    endif()

    # And on many older/weirder platforms it's just not supported
endfunction()