summaryrefslogtreecommitdiffstats
path: root/lib/libshout-idjc/CMakeLists.txt
blob: fb3365489635e09a2ff827aaba862bc153938b2d (plain)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
cmake_minimum_required(VERSION 3.1)
project(shout_mixxx LANGUAGES C VERSION 2.4.1)

add_library(${PROJECT_NAME} STATIC
    src/codec_opus.c
    src/codec_vorbis.c
    src/common/avl/avl.c
    src/common/net/sock.c
    src/common/net/resolver.c
    src/common/timing/timing.c
    src/common/httpp/httpp.c
    src/common/httpp/encoding.c
    src/common/thread/thread.c
    src/format_mpeg.c
    src/format_ogg.c
    src/format_webm.c
    src/proto_http.c
    src/proto_icy.c
    src/proto_roaraudio.c
    src/proto_xaudiocast.c
    src/queue.c
    src/shout.c
    src/tls.c
    src/util.c
)
target_include_directories(${PROJECT_NAME} PRIVATE include src src/common)

target_compile_definitions(${PROJECT_NAME}
    PRIVATE
        VERSION="${PROJECT_VERSION}"
        LIBSHOUT_MAJOR=${PROJECT_VERSION_MAJOR}
        LIBSHOUT_MINOR=${PROJECT_VERSION_MINOR}
        LIBSHOUT_MICRO=${PROJECT_VERSION_PATCH}
)

target_compile_options(${PROJECT_NAME} PRIVATE -pthread -Wall)
target_link_libraries(${PROJECT_NAME} PRIVATE pthread)

# Configure shout.h
set(SHOUT_THREADSAFE 1)
set(SHOUT_TLS 1)
configure_file(include/shoutidjc/shout.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/shoutidjc/shout.h" @ONLY)

# Required system dependencies
# Ogg Vorbis
find_package(OggVorbis REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC ${OggVorbis_LIBRARIES})

# Optional system dependencies
find_package(OpenSSL)
if(TARGET OpenSSL::SSL)
    target_compile_definitions(shout_mixxx PRIVATE HAVE_OPENSSL)
    target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
endif()

option(SPEEX "Speex support" OFF)
if(SPEEX)
    target_sources(${PROJECT_NAME} src/codec_speex.c)
    # TODO: Add support for finding speex headers and linking
endif()

option(THEORA "Theora support" OFF)
if(THEORA)
    target_sources(${PROJECT_NAME} src/codec_theora.c)
    # TODO: Add support for finding theora headers and linking
    #find_package(unofficial-theora)
    #if(TARGET unofficial::theora::theora)
    #    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_THEORA)
    #    target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::theora::theora unofficial::theora::theoradec unofficial::theora::theoraenc)
    #endif()
endif()

set(STORED_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")

check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
if (NOT _GNU_SOURCE)
    unset(_GNU_SOURCE CACHE)
    check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE)
endif ()
if (_GNU_SOURCE)
    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
    target_compile_definitions(${PROJECT_NAME} PRIVATE "_GNU_SOURCE")
endif ()

if(UNIX AND NOT APPLE)
    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=600)
    target_compile_definitions(${PROJECT_NAME} PRIVATE "_XOPEN_SOURCE=600")
endif()

check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
if(HAVE_ARPA_INET_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_ARPA_INET_H)
endif()

check_include_file(inttypes.h HAVE_INTTYPES_H)
if(HAVE_INTTYPES_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_INTTYPES_H)
endif()

check_include_file(stdint.h HAVE_STDINT_H)
if(HAVE_STDINT_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_STDINT_H)
endif()

check_include_file(sys/select.h HAVE_SYS_SELECT_H)
if(HAVE_SYS_SELECT_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_SYS_SELECT_H)
endif()

check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
if(HAVE_SYS_SOCKET_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_SYS_SOCKET_H)
endif()

check_include_file(winsock2.h HAVE_WINSOCK2_H)
if(HAVE_WINSOCK2_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_WINSOCK2_H)
endif()

check_include_file(sys/uio.h HAVE_SYS_UIO_H)
if(HAVE_SYS_UIO_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_SYS_UIO_H)
     
    check_symbol_exists(writev "sys/uio.h" HAVE_WRITEV)
    if(HAVE_WRITEV)
        target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_WRITEV)
    endif()
endif()

check_include_file(sys/time.h HAVE_SYS_TIME_H)
if(HAVE_SYS_TIME_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_SYS_TIME_H)

    check_symbol_exists(gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY)
    if(HAVE_GETTIMEOFDAY)
        target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_GETTIMEOFDAY)
    endif()
endif()

check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
if(HAVE_SYS_TIMEB_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_SYS_TIMEB_H)

    check_symbol_exists(ftime "sys/timeb.h" HAVE_FTIME)
    if(HAVE_FTIME)
        target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_FTIME)
    endif()
endif()

check_include_file(time.h HAVE_TIME_H)
if(HAVE_TIME_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_TIME_H)

    include(CheckStructHasMember)
    check_struct_has_member( "struct timespec" "tv_sec" "time.h" HAVE_STRUCT_TIMESPEC )
    # HAVE_STRUCT_TIMESPEC must be defined for windows pthreads on newer MSVC
    if(HAVE_STRUCT_TIMESPEC)
        target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_STRUCT_TIMESPEC)
    endif(HAVE_STRUCT_TIMESPEC)
endif()

if(HAVE_SYS_TIME_H AND HAVE_TIME_H)
    target_compile_definitions(${PROJECT_NAME} PRIVATE TIME_WITH_SYS_TIME)
endif()

check_symbol_exists(pthread_spin_init "sys/time.h" HAVE_PTHREAD_SPIN_LOCK)
if(HAVE_PTHREAD_SPIN_LOCK)
    add_compile_definitions(HAVE_PTHREAD_SPIN_LOCK)
endif()

check_include_file(unistd.h HAVE_UNISTD_H)
if(HAVE_UNISTD_H)
    # PUBLIC because it is also used in the header file
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_UNISTD_H)
endif()

check_include_file(poll "poll.h" HAVE_POLL)
if(HAVE_POLL)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_POLL)
endif()

check_include_file(winsock2.h HAVE_WINSOCK2_H)
if(HAVE_WINSOCK2_H)
    # PUBLIC because it is also used in the header file
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_WINSOCK2_H)

    check_symbol_exists(endhostent "winsock2.h;ws2tcpip.h" HAVE_ENDHOSTENT)
    check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" HAVE_GETADDRINFO)
    check_symbol_exists(getnameinfo "winsock2.h;ws2tcpip.h" HAVE_GETNAMEINFO)
    check_symbol_exists(inet_aton "winsock2.h;ws2tcpip.h" HAVE_INET_ATON)
    check_symbol_exists(inet_pton "winsock2.h;ws2tcpip.h" HAVE_INET_PTON)
    check_symbol_exists(sethostent "winsock2.h;ws2tcpip.h" HAVE_SETHOSTENT)
else()
    check_symbol_exists(endhostent "netdb.h" HAVE_ENDHOSTENT)
    check_symbol_exists(getaddrinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETADDRINFO)
    check_symbol_exists(getnameinfo "sys/socket.h;netdb.h" HAVE_GETNAMEINFO)
    check_symbol_exists(inet_aton "sys/socket.h;netinet/in.h;arpa/inet.h" HAVE_INET_ATON)
    check_symbol_exists(inet_pton "arpa/inet.h" HAVE_INET_PTON)
    check_symbol_exists(sethostent "netdb.h" HAVE_SETHOSTENT)
endif()

if(HAVE_GETADDRINFO)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_GETADDRINFO)
endif()
if(HAVE_GETNAMEINFO)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_GETNAMEINFO)
endif()
if(HAVE_INET_ATON)
    # PUBLIC because it is also used in the header file
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_INET_ATON)
endif()
if(HAVE_INET_PTON)
    # PUBLIC because it is also used in the header file
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_INET_PTON)
endif()
if(HAVE_SETHOSTENT)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_SETHOSTENT)
endif()

check_symbol_exists(strcasestr "string.h" HAVE_STRCASESTR)
if(HAVE_STRCASESTR)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_STRCASESTR)
endif()

check_symbol_exists(X509_check_host "openssl/x509v3.h" HAVE_X509_CHECK_HOST)
if(HAVE_X509_CHECK_HOST)
    target_compile_definitions(${PROJECT_NAME} PRIVATE XXX_HAVE_X509_check_host)
endif()

set(CMAKE_REQUIRED_DEFINITIONS "${STORED_REQUIRED_DEFINITIONS}")