if("x${CMAKE_SYSTEM_NAME}" STREQUAL "xCYGWIN")
    set(CMAKE_SYSTEM_NAME cygwin)
else()
    string(TOLOWER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME_LOWER)
    if(${CMAKE_SYSTEM_NAME_LOWER} MATCHES linux)
        find_program(LSB_RELEASE_EXEC lsb_release)
        execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
            OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
            OUTPUT_STRIP_TRAILING_WHITESPACE
        )
        execute_process(COMMAND ${LSB_RELEASE_EXEC} -rs
            OUTPUT_VARIABLE LSB_RELEASE_REL_SHORT
            OUTPUT_STRIP_TRAILING_WHITESPACE
        )
        string(TOLOWER ${LSB_RELEASE_ID_SHORT} LSB_RELEASE_ID_SHORT_LOWER)
        if (${LSB_RELEASE_ID_SHORT_LOWER} MATCHES ubuntu)
            if (LSB_RELEASE_REL_SHORT VERSION_GREATER_EQUAL 20.04)
                set(LSB_RELEASE_REL_SHORT "20.04")
            endif()
            set(CMAKE_SYSTEM_NAME_LOWER "${LSB_RELEASE_ID_SHORT_LOWER}-${LSB_RELEASE_REL_SHORT}")
        endif()
    endif()
    set(CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME_LOWER}-${CMAKE_SYSTEM_PROCESSOR})
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES windows)
    if(CMAKE_CL_64)
        set(CMAKE_SYSTEM_NAME windows-x86_64)
    else()
        set(CMAKE_SYSTEM_NAME windows-x86_32)
    endif()
endif()

set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "midnightBITS")
set(CPACK_PACKAGE_CONTACT "Marcin Zdun <mzdun@midnightbits.com>")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}${PROJECT_VERSION_STABILITY}-${CMAKE_SYSTEM_NAME}")
set(CPACK_NSIS_MODIFY_PATH ON)
include(CPack)
