if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
    set(MML_OS_WINDOWS 1)
    # detect the architecture (note: this test won't work for cross-compilation)
    include(CheckTypeSize)
    check_type_size(void* SIZEOF_VOID_PTR)
    if(${SIZEOF_VOID_PTR} STREQUAL "4")
        set(ARCH_32BITS 1)
    elseif(${SIZEOF_VOID_PTR} STREQUAL "8")
        set(ARCH_64BITS 1)
    else()
        message(FATAL_ERROR "Unsupported architecture")
        return()
    endif()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
    set(MML_OS_UNIX 1)
    if(ANDROID)
        set(MML_OS_ANDROID 1)
    else()
        set(MML_OS_LINUX 1)
    endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "^k?FreeBSD$")
    set(MML_OS_FREEBSD 1)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
    if(IOS)
        set(MML_OS_IOS 1)

        # set the target framework and platforms
        set(CMAKE_OSX_SYSROOT "iphoneos")
        set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
        set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")

        # help the compiler detection script below
        set(CMAKE_COMPILER_IS_GNUCXX 1)
    else()
        set(MML_OS_MACOSX 1)

        # detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.)
        EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
        STRING(REGEX REPLACE "10\\.([0-9]+).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}")
        if(${MACOSX_VERSION} LESS 7)
            message(FATAL_ERROR "Unsupported version of OS X: ${MACOSX_VERSION_RAW}")
            return()
        endif()
    endif()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
    set(MML_OS_ANDROID 1)
else()
    message(FATAL_ERROR "Unsupported operating system or environment")
    return()
endif()