include(CheckIncludeFile) include(CheckIncludeFiles) include(CheckSymbolExists) include(CheckFunctionExists) include(CheckLibraryExists) include(CheckTypeSize) include(CheckCXXCompilerFlag) include(CheckCXXSourceCompiles) include(TestBigEndian) include(TestFloatFormat) include(TestLargeFiles) # Determine whether your compiler supports C++0x/C++11 and enable it if possible. # This check covers GCC, Clang and ICC. if(NOT MSVC AND NOT CMAKE_CXX_FLAGS MATCHES "-std=^\\s+") CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_FLAG_CXX11) if(COMPILER_FLAG_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") else() CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_FLAG_CXX0X) if(COMPILER_FLAG_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif() endif() endif() # Check if the size of numeric types are suitable. check_type_size("short" SIZEOF_SHORT) if(NOT ${SIZEOF_SHORT} EQUAL 2) MESSAGE(FATAL_ERROR "TagLib requires that short is 16-bit wide.") endif() check_type_size("int" SIZEOF_INT) if(NOT ${SIZEOF_INT} EQUAL 4) MESSAGE(FATAL_ERROR "TagLib requires that int is 32-bit wide.") endif() check_type_size("long long" SIZEOF_LONGLONG) if(NOT ${SIZEOF_LONGLONG} EQUAL 8) MESSAGE(FATAL_ERROR "TagLib requires that long long is 64-bit wide.") endif() check_type_size("wchar_t" SIZEOF_WCHAR_T) if(${SIZEOF_WCHAR_T} LESS 2) MESSAGE(FATAL_ERROR "TagLib requires that wchar_t is sufficient to store a UTF-16 char.") endif() check_type_size("float" SIZEOF_FLOAT) if(NOT ${SIZEOF_FLOAT} EQUAL 4) MESSAGE(FATAL_ERROR "TagLib requires that float is 32-bit wide.") endif() check_type_size("double" SIZEOF_DOUBLE) if(NOT ${SIZEOF_DOUBLE} EQUAL 8) MESSAGE(FATAL_ERROR "TagLib requires that double is 64-bit wide.") endif() # Determine the CPU byte order. test_big_endian(IS_BIG_ENDIAN) if(NOT IS_BIG_ENDIAN) set(SYSTEM_BYTEORDER 1) else() set(SYSTEM_BYTEORDER 2) endif() # Check if the format of floating point types are suitable. test_float_format(FP_IEEE754) if(${FP_IEEE754} EQUAL 1) set(FLOAT_BYTEORDER 1) elseif(${FP_IEEE754} EQUAL 2) set(FLOAT_BYTEORDER 2) else() MESSAGE(FATAL_ERROR "TagLib requires that floating point types are IEEE754 compliant.") endif() # Determine whether your compiler supports large files. if(NOT WIN32) test_large_files(SUPPORT_LARGE_FILES) if(NOT SUPPORT_LARGE_FILES) MESSAGE(FATAL_ERROR "TagLib requires large files support.") endif() endif() # Determine which kind of atomic operations your compiler supports. check_cxx_source_compiles(" #include int main() { std::atomic x; x.fetch_add(1); x.fetch_sub(1); return 0; } " HAVE_STD_ATOMIC) if(NOT HAVE_STD_ATOMIC) check_cxx_source_compiles(" #include int main() { boost::atomic x(1); x.fetch_add(1); x.fetch_sub(1); return 0; } " HAVE_BOOST_ATOMIC) if(NOT HAVE_BOOST_ATOMIC) check_cxx_source_compiles(" int main() { volatile int x; __sync_add_and_fetch(&x, 1); int y = __sync_sub_and_fetch(&x, 1); return 0; } " HAVE_GCC_ATOMIC) if(NOT HAVE_GCC_ATOMIC) check_cxx_source_compiles(" #include int main() { volatile int32_t x; OSAtomicIncrement32Barrier(&x); int32_t y = OSAtomicDecrement32Barrier(&x); return 0; } " HAVE_MAC_ATOMIC) if(NOT HAVE_MAC_ATOMIC) check_cxx_source_compiles(" #include int main() { volatile LONG x; InterlockedIncrement(&x); LONG y = InterlockedDecrement(&x); return 0; } " HAVE_WIN_ATOMIC) if(NOT HAVE_WIN_ATOMIC) check_cxx_source_compiles(" #include int main() { volatile int x; __sync_add_and_fetch(&x, 1); int y = __sync_sub_and_fetch(&x, 1); return 0; } " HAVE_IA64_ATOMIC) endif() endif() endif() endif() endif() # Determine which kind of smart pointers your compiler supports. check_cxx_source_compiles(" #include int main() { std::shared_ptr x; std::unique_ptr y; return 0; } " HAVE_STD_SMART_PTR) if(NOT HAVE_STD_SMART_PTR) check_cxx_source_compiles(" #include #include int main() { boost::shared_ptr x; boost::scoped_ptr y; return 0; } " HAVE_BOOST_SMART_PTR) endif() # Determine which kind of byte swap functions your compiler supports. # GCC's __builtin_bswap* should be checked individually # because some of them can be missing depends on the GCC version. check_cxx_source_compiles(" int main() { __builtin_bswap16(0); return 0; } " HAVE_GCC_BYTESWAP_16) check_cxx_source_compiles(" int main() { __builtin_bswap32(0); return 0; } " HAVE_GCC_BYTESWAP_32) check_cxx_source_compiles(" int main() { __builtin_bswap64(0); return 0; } " HAVE_GCC_BYTESWAP_64) if(NOT HAVE_GCC_BYTESWAP_16 OR NOT HAVE_GCC_BYTESWAP_32 OR NOT HAVE_GCC_BYTESWAP_64) check_cxx_source_compiles(" #include int main() { __bswap_16(0); __bswap_32(0); __bswap_64(0); return 0; } " HAVE_GLIBC_BYTESWAP) if(NOT HAVE_GLIBC_BYTESWAP) check_cxx_source_compiles(" #include int main() { _byteswap_ushort(0); _byteswap_ulong(0); _byteswap_uint64(0); return 0; } " HAVE_MSC_BYTESWAP) if(NOT HAVE_MSC_BYTESWAP) check_cxx_source_compiles(" #include int main() { OSSwapInt16(0); OSSwapInt32(0); OSSwapInt64(0); return 0; } " HAVE_MAC_BYTESWAP) if(NOT HAVE_MAC_BYTESWAP) check_cxx_source_compiles(" #include int main() { swap16(0); swap32(0); swap64(0); return 0; } " HAVE_OPENBSD_BYTESWAP) endif() endif() endif() endif() # Determine whether your compiler supports snprintf or sprintf_s. check_cxx_source_compiles(" #include int main() { char buf[20]; snprintf(buf, 20, \"%d\", 1); return 0; } " HAVE_SNPRINTF) if(NOT HAVE_SNPRINTF) check_cxx_source_compiles(" #include int main() { char buf[20]; sprintf_s(buf, \"%d\", 1); return 0; } " HAVE_SPRINTF_S) endif() # Check which your compiler supports ISO _strdup. check_cxx_source_compiles(" #include int main() { _strdup(0); return 0; } " HAVE_ISO_STRDUP) # Determine whether zlib is installed. if(NOT ZLIB_SOURCE) find_package(ZLIB) if(ZLIB_FOUND) set(HAVE_ZLIB 1) else() set(HAVE_ZLIB 0) endif() endif() # Determine whether CppUnit is installed. find_package(CppUnit) if(NOT CppUnit_FOUND AND BUILD_TESTS) message(STATUS "CppUnit not found, disabling tests.") set(BUILD_TESTS OFF) endif()