# 32 or 64 bit
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(BUILD_TARGET_ARCH "x64")
    set(BUILD_TARGET_X64 1)
else()
    set(BUILD_TARGET_ARCH "x86")
    set(BUILD_TARGET_X86 1)
endif()

set(BUILD_TARGET_WINDOWS 0)
set(BUILD_TARGET_LINUX 0)
set(BUILD_TARGET_OSX 0)
set(BUILD_TARGET_FREEBSD 0)
set(BUILD_TARGET_SOLARIS 0)

# OS detection
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    set(BUILD_TARGET_OS "Windows")
    set(BUILD_TARGET_WINDOWS 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    set(BUILD_TARGET_OS "Linux")
    set(BUILD_TARGET_LINUX 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set(BUILD_TARGET_OS "OSX")
    set(BUILD_TARGET_OSX 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
    set(BUILD_TARGET_OS "FreeBSD")
    set(BUILD_TARGET_FREEBSD 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
    set(BUILD_TARGET_OS "Solaris")
    set(BUILD_TARGET_SOLARIS 1)
else()
    message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
endif()

# Platform libraries
if(BUILD_TARGET_WINDOWS)
    set(BUILD_PLATFORM_SRC "windows")
    set(BUILD_PLATFORM_BIN "win")
    if(BUILD_TARGET_X64)
        set(BUILD_PLATFORM_BIN ${BUILD_PLATFORM_BIN}64)
    else()
        set(BUILD_PLATFORM_BIN ${BUILD_PLATFORM_BIN}32)
    endif()
elseif(BUILD_TARGET_OSX)
    set(BUILD_PLATFORM_SRC "osx")
    set(BUILD_PLATFORM_BIN "darwin")
else()
    if(BUILD_TARGET_LINUX)
        set(BUILD_PLATFORM_SRC "linux")
        set(BUILD_PLATFORM_BIN "linux")
    elseif(BUILD_TARGET_FREEBSD)
        set(BUILD_PLATFORM_SRC "freebsd")
        set(BUILD_PLATFORM_BIN "freebsd")
    elseif(BUILD_TARGET_SOLARIS)
        set(BUILD_PLATFORM_SRC "solaris")
        set(BUILD_PLATFORM_BIN "solaris")
    endif()
endif()
