if (UNIX)
  #
  # Prepare Snap files
  #

  configure_file(snap/snapcraft.yaml.in snap/snapcraft.yaml)

  #
  # Create archive
  #
  add_custom_target(packaging-archive
    COMMAND git archive HEAD --prefix ${PROJECT_NAME}-${PROJECT_VERSION}/ -o ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}.tar.gz
    COMMENT "Creating tarball"
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    )
  
  
    
  #
  # Prepare RPM files
  #
  
  configure_file(RPM/scantools.spec RPM/scantools.spec)
  add_custom_target(packaging-rpm
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}.tar.gz .
    DEPENDS packaging-archive
    WORKING_DIRECTORY RPM
    COMMENT "Downloading tarball and for RPM package"
    )
  
  
  #
  # Prepare Debian package
  #
  
  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debian)
  configure_file(debian/changelog debian-working/changelog)
  configure_file(debian/compat debian-working/compat)
  configure_file(debian/control debian-working/control COPYONLY)
  configure_file(debian/copyright debian-working/copyright COPYONLY)
  configure_file(debian/rules debian-working/rules)
  configure_file(debian/source/format debian-working/source/format)
  
  add_custom_target(packaging-debian
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}.tar.gz ./${PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.gz
    COMMAND tar xf ${PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.gz
    COMMAND mkdir ${PROJECT_NAME}-${PROJECT_VERSION}/debian
    COMMAND cp -prd ../debian-working/* ${PROJECT_NAME}-${PROJECT_VERSION}/debian
    COMMAND dpkg-source -b ${PROJECT_NAME}-${PROJECT_VERSION}
    COMMAND rm -rf ${PROJECT_NAME}-${PROJECT_VERSION}
    COMMENT "Downloading tarball and building Debian source package"
    DEPENDS packaging-archive
    WORKING_DIRECTORY debian
    )
  
  add_custom_target(packaging-windows
    COMMAND /usr/i686-w64-mingw32/bin/qt5/windeployqt ../src/scantools.exe
    #  WORKING_DIRECTORY debian
    )

  
  #
  # Add target that include  both RPM and Debian packages
  #
  
  add_custom_target(packaging
    DEPENDS packaging-debian
    DEPENDS packaging-rpm
    )
  
endif (UNIX)
