File: init_target.cmake

package info (click to toggle)
libtgowt 0~git20210627.91d836d%2Bdfsg-3~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,624 kB
  • sloc: cpp: 1,001,903; ansic: 438,839; asm: 59,305; java: 38,075; python: 17,273; sh: 8,094; objc: 4,256; perl: 1,924; pascal: 1,103; makefile: 958; cs: 471; javascript: 286; xml: 276
file content (129 lines) | stat: -rw-r--r-- 4,306 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
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
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL

function(init_target_folder target_name folder_name)
    if (NOT "${folder_name}" STREQUAL "")
        set_target_properties(${target_name} PROPERTIES FOLDER ${folder_name})
    endif()
endfunction()

function(init_target target_name) # init_target(my_target folder_name)
    if (APPLE)
        target_compile_features(${target_name} PUBLIC cxx_std_14)
    else()
        # C++20 is not supported by bundled abseil-cpp yet:
        # https://github.com/abseil/abseil-cpp/issues/722
        target_compile_features(${target_name} PUBLIC cxx_std_17)
    endif()
    if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
        set_target_properties(${target_name} PROPERTIES
            MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    endif()
    set_target_properties(${target_name} PROPERTIES
        XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK YES
        XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN YES
        XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES
    )
    if (NOT TG_OWT_SPECIAL_TARGET STREQUAL "")
        set_target_properties(${target_name} PROPERTIES
            XCODE_ATTRIBUTE_GCC_OPTIMIZATION_LEVEL $<IF:$<CONFIG:Debug>,0,fast>
            XCODE_ATTRIBUTE_LLVM_LTO $<IF:$<CONFIG:Debug>,NO,YES>
        )
    endif()
    target_compile_definitions(${target_name}
    PRIVATE
        HAVE_SCTP
        ABSL_ALLOCATOR_NOTHROW=1
    )
    if (WIN32)
        target_compile_definitions(${target_name}
        PRIVATE
            WIN32_LEAN_AND_MEAN
            HAVE_WINSOCK2_H
            NOMINMAX
            HAVE_SSE2
        )

        target_compile_options(${target_name}
        PRIVATE
            /W1
            /wd4715 # not all control paths return a value.
            /wd4244 # 'initializing' conversion from .. to .., possible loss of data.
            /wd4838 # conversion from .. to .. requires a narrowing conversion.
            /wd4305 # 'return': truncation from 'int' to 'bool'.
            /MP     # Enable multi process build.
            /EHsc   # Catch C++ exceptions only, extern C functions never throw a C++ exception.
            /Zc:wchar_t- # don't tread wchar_t as builtin type
            /Zi
        )
    else()
        if (APPLE)
            target_compile_options(${target_name}
            PRIVATE
                -Wno-deprecated-declarations
                -fobjc-arc
                -fvisibility=hidden
                -fvisibility-inlines-hidden
            )
        else()
            target_compile_options(${target_name}
            PRIVATE
                -Wno-deprecated-declarations
                -Wno-attributes
                -Wno-narrowing
                -Wno-return-type
            )
            if (NOT TG_OWT_SPECIAL_TARGET STREQUAL "" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
                target_compile_options(${target_name}
                PRIVATE
                    -g0
                )
            endif()
        endif()

        target_compile_definitions(${target_name}
        PRIVATE
            HAVE_NETINET_IN_H
        )
    endif()
endfunction()

function(init_feature_target target_name feature)
    init_target(${target_name})

    set(option "")
    if (WIN32)
        if (${feature} STREQUAL "avx")
            set(option /arch:AVX)
        elseif (${feature} STREQUAL "avx2")
            set(option /arch:AVX2)
        endif()
    else()
        if (${feature} STREQUAL "mmx")
            set(option -mmmx)
        elseif (${feature} STREQUAL "sse2")
            set(option -msse2)
        elseif (${feature} STREQUAL "ssse3")
            set(option -mssse3)
        elseif (${feature} STREQUAL "sse4")
            set(option -msse4.1)
        elseif (${feature} STREQUAL "avx")
            set(option -mavx)
        elseif (${feature} STREQUAL "avx2")
            set(option -mavx2 -mfma)
        endif()
        target_compile_options(${target_name}
        PRIVATE
            ${posix_option}
        )
    endif()
    if (NOT "${option}" STREQUAL "")
        target_compile_options(${target_name}
        PRIVATE
            ${option}
        )
    endif()
endfunction()