1include (CheckFunctionExists) 2include (CheckIncludeFile) 3include (CheckLibraryExists) 4include (CheckSymbolExists) 5include (CheckTypeSize) 6include (TestBigEndian) 7 8include (TestInline) 9include (ClipMode) 10include (TestLargeFiles) 11include (CheckCPUArch) 12 13test_large_files (_LARGEFILES) 14 15if (LARGE_FILES_DEFINITIONS) 16 add_definitions(${LARGE_FILES_DEFINITIONS}) 17endif () 18 19if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") 20 find_package (Sndio) 21elseif (NOT WIN32) 22 find_package (ALSA) 23endif () 24 25if (VCPKG_TOOLCHAIN AND (NOT CMAKE_VERSION VERSION_LESS 3.15)) 26 set (CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) 27endif () 28 29if (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) 40else () 41 find_package (Ogg 1.3) 42 find_package (Vorbis COMPONENTS Enc) 43 find_package (FLAC) 44 find_package (Opus) 45endif () 46if (Vorbis_FOUND AND FLAC_FOUND AND Opus_FOUND) 47 set (HAVE_EXTERNAL_XIPH_LIBS 1) 48else () 49 set (HAVE_EXTERNAL_XIPH_LIBS 0) 50endif () 51 52find_package (mp3lame) 53find_package (Mpg123 1.25.10) 54if (TARGET mp3lame::mp3lame AND (TARGET MPG123::libmpg123)) 55 set (HAVE_MPEG_LIBS 1) 56else () 57 set (HAVE_MPEG_LIBS 0) 58endif() 59 60find_package (Speex) 61find_package (SQLite3) 62 63check_include_file (byteswap.h HAVE_BYTESWAP_H) 64check_include_file (dlfcn.h HAVE_DLFCN_H) 65check_include_file (direct.h HAVE_DIRECT_H) 66check_include_file (endian.h HAVE_ENDIAN_H) 67check_include_file (inttypes.h HAVE_INTTYPES_H) 68check_include_file (io.h HAVE_IO_H) 69check_include_file (stdint.h HAVE_STDINT_H) 70check_include_file (sys/time.h HAVE_SYS_TIME_H) 71check_include_file (sys/types.h HAVE_SYS_TYPES_H) 72check_include_file (unistd.h HAVE_UNISTD_H) 73check_include_file (immintrin.h HAVE_IMMINTRIN_H) 74check_include_file (stdbool.h HAVE_STDBOOL_H) 75 76check_cpu_arch_x86 (CPU_IS_X86) 77check_cpu_arch_x64 (CPU_IS_X64) 78if ((CPU_IS_X86 OR CPU_IS_X64) AND HAVE_IMMINTRIN_H) 79 set (HAVE_SSE2 1) 80endif () 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 89if (BUILD_TESTING) 90 check_include_file (locale.h HAVE_LOCALE_H) 91 check_include_file (sys/wait.h HAVE_SYS_WAIT_H) 92endif () 93 94check_type_size (int64_t SIZEOF_INT64_T) 95check_type_size (long SIZEOF_LONG) 96check_type_size (long\ long SIZEOF_LONG_LONG) 97check_type_size (ssize_t SIZEOF_SSIZE_T) 98check_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 113if (ENABLE_TESTING) 114 check_type_size (void* SIZEOF_VOIDP) 115endif() 116 117if (NOT WIN32) 118 check_library_exists (m floor "" LIBM_REQUIRED) 119 if (LIBM_REQUIRED) 120 list (APPEND CMAKE_REQUIRED_LIBRARIES m) 121 endif () 122endif () 123 124check_library_exists (sqlite3 sqlite3_close "" HAVE_SQLITE3) 125 126check_function_exists (fstat HAVE_FSTAT) 127check_function_exists (fstat64 HAVE_FSTAT64) 128check_function_exists (gettimeofday HAVE_GETTIMEOFDAY) 129check_function_exists (gmtime HAVE_GMTIME) 130check_function_exists (gmtime_r HAVE_GMTIME_R) 131check_function_exists (localtime HAVE_LOCALTIME) 132check_function_exists (localtime_r HAVE_LOCALTIME_R) 133check_function_exists (lseek HAVE_LSEEK) 134check_function_exists (open HAVE_OPEN) 135check_function_exists (read HAVE_READ) 136check_function_exists (write HAVE_WRITE) 137check_function_exists (lrint HAVE_LRINT) 138check_function_exists (lrintf HAVE_LRINTF) 139 140if (NOT WIN32) 141 check_function_exists (ftruncate HAVE_FTRUNCATE) 142 check_function_exists (fsync HAVE_FSYNC) 143endif () 144 145if (BUILD_TESTING) 146 check_function_exists (pipe HAVE_PIPE) 147 check_function_exists (setlocale HAVE_SETLOCALE) 148 check_function_exists (waitpid HAVE_WAITPID) 149endif () 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 169check_symbol_exists (S_IRGRP sys/stat.h HAVE_DECL_S_IRGRP) 170 171test_big_endian (WORDS_BIGENDIAN) 172if (WORDS_BIGENDIAN) 173 set (CPU_IS_BIG_ENDIAN 1) 174else () 175 set (CPU_IS_LITTLE_ENDIAN 1) 176endif () 177 178if (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 () 187endif () 188 189if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") 190 set (OS_IS_OPENBSD 1) 191endif () 192 193 194if (CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang")) 195 set (COMPILER_IS_GCC 1) 196endif () 197 198test_inline () 199clip_mode () 200 201if (MSVC) 202 add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) 203endif (MSVC) 204 205if (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 () 252endif () 253 254if (BUILD_SHARED_LIBS) 255 find_package (PythonInterp REQUIRED) 256endif() 257