1include(CheckLibraryExists) 2include(CheckTypeSize) 3include(CheckCXXSourceCompiles) 4 5# Check if the size of numeric types are suitable. 6 7check_type_size("short" SIZEOF_SHORT) 8if(NOT ${SIZEOF_SHORT} EQUAL 2) 9 message(FATAL_ERROR "TagLib requires that short is 16-bit wide.") 10endif() 11 12check_type_size("int" SIZEOF_INT) 13if(NOT ${SIZEOF_INT} EQUAL 4) 14 message(FATAL_ERROR "TagLib requires that int is 32-bit wide.") 15endif() 16 17check_type_size("long long" SIZEOF_LONGLONG) 18if(NOT ${SIZEOF_LONGLONG} EQUAL 8) 19 message(FATAL_ERROR "TagLib requires that long long is 64-bit wide.") 20endif() 21 22check_type_size("wchar_t" SIZEOF_WCHAR_T) 23if(${SIZEOF_WCHAR_T} LESS 2) 24 message(FATAL_ERROR "TagLib requires that wchar_t is sufficient to store a UTF-16 char.") 25endif() 26 27check_type_size("float" SIZEOF_FLOAT) 28if(NOT ${SIZEOF_FLOAT} EQUAL 4) 29 message(FATAL_ERROR "TagLib requires that float is 32-bit wide.") 30endif() 31 32check_type_size("double" SIZEOF_DOUBLE) 33if(NOT ${SIZEOF_DOUBLE} EQUAL 8) 34 message(FATAL_ERROR "TagLib requires that double is 64-bit wide.") 35endif() 36 37# Determine which kind of atomic operations your compiler supports. 38 39check_cxx_source_compiles(" 40 int main() { 41 volatile int x; 42 __sync_add_and_fetch(&x, 1); 43 int y = __sync_sub_and_fetch(&x, 1); 44 return 0; 45 } 46 " HAVE_GCC_ATOMIC) 47 48if(NOT HAVE_GCC_ATOMIC) 49 check_cxx_source_compiles(" 50 #include <libkern/OSAtomic.h> 51 int main() { 52 volatile int32_t x; 53 OSAtomicIncrement32Barrier(&x); 54 int32_t y = OSAtomicDecrement32Barrier(&x); 55 return 0; 56 } 57 " HAVE_MAC_ATOMIC) 58 59 if(NOT HAVE_MAC_ATOMIC) 60 check_cxx_source_compiles(" 61 #include <windows.h> 62 int main() { 63 volatile LONG x; 64 InterlockedIncrement(&x); 65 LONG y = InterlockedDecrement(&x); 66 return 0; 67 } 68 " HAVE_WIN_ATOMIC) 69 70 if(NOT HAVE_WIN_ATOMIC) 71 check_cxx_source_compiles(" 72 #include <ia64intrin.h> 73 int main() { 74 volatile int x; 75 __sync_add_and_fetch(&x, 1); 76 int y = __sync_sub_and_fetch(&x, 1); 77 return 0; 78 } 79 " HAVE_IA64_ATOMIC) 80 endif() 81 endif() 82endif() 83 84# Determine which kind of byte swap functions your compiler supports. 85 86check_cxx_source_compiles(" 87 int main() { 88 __builtin_bswap16(0); 89 __builtin_bswap32(0); 90 __builtin_bswap64(0); 91 return 0; 92 } 93" HAVE_GCC_BYTESWAP) 94 95if(NOT HAVE_GCC_BYTESWAP) 96 check_cxx_source_compiles(" 97 #include <byteswap.h> 98 int main() { 99 __bswap_16(0); 100 __bswap_32(0); 101 __bswap_64(0); 102 return 0; 103 } 104 " HAVE_GLIBC_BYTESWAP) 105 106 if(NOT HAVE_GLIBC_BYTESWAP) 107 check_cxx_source_compiles(" 108 #include <stdlib.h> 109 int main() { 110 _byteswap_ushort(0); 111 _byteswap_ulong(0); 112 _byteswap_uint64(0); 113 return 0; 114 } 115 " HAVE_MSC_BYTESWAP) 116 117 if(NOT HAVE_MSC_BYTESWAP) 118 check_cxx_source_compiles(" 119 #include <libkern/OSByteOrder.h> 120 int main() { 121 OSSwapInt16(0); 122 OSSwapInt32(0); 123 OSSwapInt64(0); 124 return 0; 125 } 126 " HAVE_MAC_BYTESWAP) 127 128 if(NOT HAVE_MAC_BYTESWAP) 129 check_cxx_source_compiles(" 130 #include <sys/endian.h> 131 int main() { 132 swap16(0); 133 swap32(0); 134 swap64(0); 135 return 0; 136 } 137 " HAVE_OPENBSD_BYTESWAP) 138 endif() 139 endif() 140 endif() 141endif() 142 143# Determine whether your compiler supports some safer version of vsprintf. 144 145check_cxx_source_compiles(" 146 #include <cstdio> 147 #include <cstdarg> 148 int main() { 149 char buf[20]; 150 va_list args; 151 vsnprintf(buf, 20, \"%d\", args); 152 return 0; 153 } 154" HAVE_VSNPRINTF) 155 156if(NOT HAVE_VSNPRINTF) 157 check_cxx_source_compiles(" 158 #include <cstdio> 159 #include <cstdarg> 160 int main() { 161 char buf[20]; 162 va_list args; 163 vsprintf_s(buf, \"%d\", args); 164 return 0; 165 } 166 " HAVE_VSPRINTF_S) 167endif() 168 169# Determine whether your compiler supports ISO _strdup. 170 171check_cxx_source_compiles(" 172 #include <cstring> 173 int main() { 174 _strdup(0); 175 return 0; 176 } 177" HAVE_ISO_STRDUP) 178 179# Determine whether zlib is installed. 180 181if(NOT ZLIB_SOURCE) 182 find_package(ZLIB) 183 if(ZLIB_FOUND) 184 set(HAVE_ZLIB 1) 185 else() 186 set(HAVE_ZLIB 0) 187 endif() 188endif() 189 190# Determine whether CppUnit is installed. 191 192if(BUILD_TESTS AND NOT BUILD_SHARED_LIBS) 193 find_package(CppUnit) 194 if(NOT CppUnit_FOUND) 195 message(STATUS "CppUnit not found, disabling tests.") 196 set(BUILD_TESTS OFF) 197 endif() 198endif() 199 200# Detect WinRT mode 201if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") 202 set(PLATFORM WINRT 1) 203endif() 204