Debian Codegraph @

cmake/SndFileChecks.cmake

raw
1 include (CheckFunctionExists)
2 include (CheckIncludeFile)
3 include (CheckLibraryExists)
4 include (CheckSymbolExists)
5 include (CheckTypeSize)
6 include (TestBigEndian)
7
8 include (TestInline)
9 include (ClipMode)
10 include (TestLargeFiles)
11 include (CheckCPUArch)
12
13 test_large_files (_LARGEFILES)
14
15 if (LARGE_FILES_DEFINITIONS)
16 add_definitions(${LARGE_FILES_DEFINITIONS})
17 endif ()
18
19 if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
20 find_package (Sndio)
21 elseif (NOT WIN32)
22 find_package (ALSA)
23 endif ()
24
25 if (VCPKG_TOOLCHAIN AND (NOT CMAKE_VERSION VERSION_LESS 3.15))
26 set (CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
27 endif ()
28
29 if (CMAKE_FIND_PACKAGE_PREFER_CONFIG)
30 find_package (Ogg 1.3 CONFIG)
31 find_package (Vorbis CONFIG COMPONENTS Enc)
32 find_package (FLAC CONFIG)
33 find_package (Opus CONFIG)
34
35 include (FindPackageHandleStandardArgs)
36 find_package_handle_standard_args (Ogg CONFIG_MODE)
37 find_package_handle_standard_args (Vorbis CONFIG_MODE)
38 find_package_handle_standard_args (FLAC CONFIG_MODE)
39 find_package_handle_standard_args (Opus CONFIG_MODE)
40 else ()
41 find_package (Ogg 1.3)
42 find_package (Vorbis COMPONENTS Enc)
43 find_package (FLAC)
44 find_package (Opus)
45 endif ()
46 if (Vorbis_FOUND AND FLAC_FOUND AND Opus_FOUND)
47 set (HAVE_EXTERNAL_XIPH_LIBS 1)
48 else ()
49 set (HAVE_EXTERNAL_XIPH_LIBS 0)
50 endif ()
51
52 find_package (mp3lame)
53 find_package (mpg123 1.25.10)
54 if (TARGET mp3lame::mp3lame AND (TARGET MPG123::libmpg123))
55 set (HAVE_MPEG_LIBS 1)
56 else ()
57 set (HAVE_MPEG_LIBS 0)
58 endif()
59
60 find_package (Speex)
61 find_package (SQLite3)
62
63 check_include_file (byteswap.h HAVE_BYTESWAP_H)
64 check_include_file (dlfcn.h HAVE_DLFCN_H)
65 check_include_file (direct.h HAVE_DIRECT_H)
66 check_include_file (endian.h HAVE_ENDIAN_H)
67 check_include_file (inttypes.h HAVE_INTTYPES_H)
68 check_include_file (io.h HAVE_IO_H)
69 check_include_file (stdint.h HAVE_STDINT_H)
70 check_include_file (sys/time.h HAVE_SYS_TIME_H)
71 check_include_file (sys/types.h HAVE_SYS_TYPES_H)
72 check_include_file (unistd.h HAVE_UNISTD_H)
73 check_include_file (immintrin.h HAVE_IMMINTRIN_H)
74 check_include_file (stdbool.h HAVE_STDBOOL_H)
75
76 check_cpu_arch_x86 (CPU_IS_X86)
77 check_cpu_arch_x64 (CPU_IS_X64)
78 if ((CPU_IS_X86 OR CPU_IS_X64) AND HAVE_IMMINTRIN_H)
79 set (HAVE_SSE2 1)
80 endif ()
81
82 # Never checked
83 # check_include_file (stdlib.h HAVE_STDLIB_H)
84 # check_include_file (string.h HAVE_STRING_H)
85 # check_include_file (strings.h HAVE_STRINGS_H)
86 # check_include_file (sys/stat.h HAVE_SYS_STAT_H)
87 # check_include_file (memory.h HAVE_MEMORY_H)
88
89 if (BUILD_TESTING)
90 check_include_file (locale.h HAVE_LOCALE_H)
91 check_include_file (sys/wait.h HAVE_SYS_WAIT_H)
92 endif ()
93
94 check_type_size (int64_t SIZEOF_INT64_T)
95 check_type_size (long SIZEOF_LONG)
96 check_type_size (long\ long SIZEOF_LONG_LONG)
97 check_type_size (ssize_t SIZEOF_SSIZE_T)
98 check_type_size (wchar_t SIZEOF_WCHAR_T)
99
100 # Never used
101 # check_type_size (loff_t SIZEOF_LOFF_T)
102 # check_type_size (offt64_t SIZEOF_OFF64_T)
103
104 # Never checked
105 # check_type_size (size_t SIZEOF_SIZE_T)
106
107 # Used in configre.ac
108 # check_type_size (double SIZEOF_DOUBLE)
109 # check_type_size (float SIZEOF_FLOAT)
110 # check_type_size (int SIZEOF_INT)
111 # check_type_size (short SIZEOF_SHORT)
112
113 if (ENABLE_TESTING)
114 check_type_size (void* SIZEOF_VOIDP)
115 endif()
116
117 if (NOT WIN32)
118 check_library_exists (m floor "" LIBM_REQUIRED)
119 if (LIBM_REQUIRED)
120 list (APPEND CMAKE_REQUIRED_LIBRARIES m)
121 endif ()
122 endif ()
123
124 check_library_exists (sqlite3 sqlite3_close "" HAVE_SQLITE3)
125
126 check_function_exists (fstat HAVE_FSTAT)
127 check_function_exists (fstat64 HAVE_FSTAT64)
128 check_function_exists (gettimeofday HAVE_GETTIMEOFDAY)
129 check_function_exists (gmtime HAVE_GMTIME)
130 check_function_exists (gmtime_r HAVE_GMTIME_R)
131 check_function_exists (localtime HAVE_LOCALTIME)
132 check_function_exists (localtime_r HAVE_LOCALTIME_R)
133 check_function_exists (lseek HAVE_LSEEK)
134 check_function_exists (open HAVE_OPEN)
135 check_function_exists (read HAVE_READ)
136 check_function_exists (write HAVE_WRITE)
137 check_function_exists (lrint HAVE_LRINT)
138 check_function_exists (lrintf HAVE_LRINTF)
139
140 if (NOT WIN32)
141 check_function_exists (ftruncate HAVE_FTRUNCATE)
142 check_function_exists (fsync HAVE_FSYNC)
143 endif ()
144
145 if (BUILD_TESTING)
146 check_function_exists (pipe HAVE_PIPE)
147 check_function_exists (setlocale HAVE_SETLOCALE)
148 check_function_exists (waitpid HAVE_WAITPID)
149 endif ()
150
151 # Never checked
152 # check_function_exists (calloc HAVE_CALLOC)
153 # check_function_exists (free HAVE_FREE)
154 # check_function_exists (getpagesize HAVE_GETPAGESIZE)
155 # check_function_exists (malloc HAVE_MALLOC)
156 # check_function_exists (realloc HAVE_REALLOC)
157 # check_function_exists (snprintf HAVE_SNPRINTF)
158 # check_function_exists (vsnprintf HAVE_VSNPRINTF)
159 # check_function_exists (floor HAVE_FLOOR)
160 # check_function_exists (fmod HAVE_FMOD)
161
162 # Never used
163 # check_function_exists (mmap HAVE_MMAP)
164 # check_function_exists (ceil HAVE_CEIL)
165 # check_function_exists (lround HAVE_LROUND)
166 # check_function_exists (lseek64 HAVE_LSEEK64)
167
168
169 check_symbol_exists (S_IRGRP sys/stat.h HAVE_DECL_S_IRGRP)
170
171 test_big_endian (WORDS_BIGENDIAN)
172 if (WORDS_BIGENDIAN)
173 set (CPU_IS_BIG_ENDIAN 1)
174 else ()
175 set (CPU_IS_LITTLE_ENDIAN 1)
176 endif ()
177
178 if (WIN32)
179 set (OS_IS_WIN32 1)
180 set (USE_WINDOWS_API 1)
181 if (BUILD_SHARED_LIBS)
182 set (WIN32_TARGET_DLL 1)
183 endif ()
184 if (MINGW)
185 add_definitions (-D__USE_MINGW_ANSI_STDIO=1)
186 endif ()
187 endif ()
188
189 if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
190 set (OS_IS_OPENBSD 1)
191 endif ()
192
193
194 if (CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
195 set (COMPILER_IS_GCC 1)
196 endif ()
197
198 test_inline ()
199 clip_mode ()
200
201 if (MSVC)
202 add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
203 endif (MSVC)
204
205 if (DEFINED ENABLE_STATIC_RUNTIME)
206 if (MSVC)
207 if (ENABLE_STATIC_RUNTIME)
208 foreach (flag_var
209 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
210 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
211 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
212 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
213 )
214 if (${flag_var} MATCHES "/MD")
215 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
216 endif ()
217 endforeach (flag_var)
218 else ()
219 foreach (flag_var
220 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
221 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
222 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
223 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
224 )
225 if (${flag_var} MATCHES "/MT")
226 string (REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
227 endif (${flag_var} MATCHES "/MT")
228 endforeach (flag_var)
229 endif ( )
230 elseif (MINGW)
231 if (ENABLE_STATIC_RUNTIME)
232 if (CMAKE_C_COMPILER_ID STREQUAL GNU)
233 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
234 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -s")
235 endif ()
236 if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
237 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
238 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++ -s")
239 endif ()
240 if (CMAKE_C_COMPILER_ID STREQUAL Clang)
241 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
242 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static")
243 endif ()
244 if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
245 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
246 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static")
247 endif ()
248 endif ()
249 else ()
250 message (AUTHOR_WARNING "ENABLE_STATIC_RUNTIME option is for MSVC or MinGW only.")
251 endif ()
252 endif ()
253
254 if (BUILD_SHARED_LIBS)
255 find_package (PythonInterp REQUIRED)
256 endif()