execute_process(COMMAND ${Python3_EXECUTABLE}
    "${PROJECT_SOURCE_DIR}/.flow/flow.py" system --format=platform
    OUTPUT_VARIABLE ___PACKAGE_NAME
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "{{COPY.HOLDER}}")
set(CPACK_PACKAGE_CONTACT "{{COPY.HOLDER}} <{{PROJECT.EMAIL}}>")
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_DESCRIPTION "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "{{PROJECT.NAME}}")
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "{{COPY.HOLDER}}/{{PROJECT.NAME}}")
set(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/data/assets/appicon-256.png")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}${PROJECT_VERSION_STABILITY}-${___PACKAGE_NAME}")

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE)
    string(REPLACE "." ";" _COMPILER_CHUNKS ${CMAKE_CXX_COMPILER_VERSION})
    list(GET _COMPILER_CHUNKS 0 CMAKE_CXX_COMPILER_VERSION_MAJOR)
    set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-clang${CMAKE_CXX_COMPILER_VERSION_MAJOR}")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-dbg")
endif()

set(CPACK_PACKAGE_DIRECTORY "${PROJECT_BINARY_DIR}/packages")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_BINARY_DIR}/packages/_CPack_Packages/LICENSE.txt")
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/packages/_CPack_Packages")
file(COPY_FILE "${PROJECT_SOURCE_DIR}/LICENSE" "${PROJECT_BINARY_DIR}/packages/_CPack_Packages/LICENSE.txt")
