+
+#########
+# Dist #
+#########
+
+add_custom_target(dist-dir
+ COMMENT "Generating the distribution directory"
+ COMMAND test -e ${DIST_NAME}/ && chmod -R a+w ${DIST_NAME}/ || true
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}
+)
+
+set(dirs_in_tarball "")
+foreach(file ${source_to_pack})
+
+ # This damn prefix is still set somewhere (seems to be in subdirs)
+ string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" file "${file}")
+
+ # Create the directory on need
+ get_filename_component(file_location ${file} PATH)
+ string(REGEX MATCH ";${file_location};" OPERATION "${dirs_in_tarball}")
+ if(NOT OPERATION)
+ set(dirs_in_tarball "${dirs_in_tarball};${file_location};")
+ add_custom_command(
+ TARGET dist-dir
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}/${file_location}/
+ )
+ endif(NOT OPERATION)
+
+ # Actually copy the file
+ add_custom_command(
+ TARGET dist-dir
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/${file} ${DIST_NAME}/${file_location}/
+ )
+endforeach(file ${source_to_pack})
+
+add_custom_target(dist
+ DEPENDS ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz
+ COMMENT "Generated ${DIST_NAME}"
+)
+add_custom_command(
+ OUTPUT ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz
+ COMMENT "Compressing the archive from the distribution directory"
+ COMMAND ${CMAKE_COMMAND} -E tar cf ${DIST_NAME}.tar ${DIST_NAME}/
+ COMMAND gzip -9v ${DIST_NAME}.tar
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
+)
+add_dependencies(dist dist-dir)
+