1# This file implements the process of making source distribution tarballs. It expects to find list in 2# 'dist_manifest.txt' of all of the files to be included in the distribution, EXCEPT those 3# files that are generated. The list of generated files handled via the 'dist_generated' cmake cache variable 4# 5# Given all of these files, the procedure is to: 6# 1. Remove any existing dist directory and make a new one. 7# 2. Copy of all the files in dist_manifest.text and ${dist_generated} 8# into the dist directory. 9# 3. Create the tarball and compress it with gzip and bzip2. 10# 4. Then remove the dist directory. 11 12include(${CMAKE_MODULE_PATH}/MakeDistFiles.cmake) 13 14 15 16function(make_dist PACKAGE_PREFIX GNUCASH_SOURCE_DIR BUILD_SOURCE_DIR BUILDING_FROM_VCS) 17 18 # -- Remove any existing packaging directory. 19 file(REMOVE_RECURSE ${PACKAGE_PREFIX}) 20 21 if (EXISTS ${PACKAGE_PREFIX}) 22 message(FATAL_ERROR "Unable to remove existing dist directory \"${PACKAGE_PREFIX}\". Cannot continue.") 23 endif() 24 25 26 # -- Copy in distributed files 27 if(NOT EXISTS dist_manifest.txt) 28 message(FATAL_ERROR "Cannot find dist manifest: dist_manifest.txt") 29 endif() 30 31 file(STRINGS dist_manifest.txt ALL_DIST) 32 33 foreach(file ${ALL_DIST}) 34 if(NOT EXISTS ${GNUCASH_SOURCE_DIR}/${file}) 35 message(FATAL_ERROR "Can't find dist file ${GNUCASH_SOURCE_DIR}/${file}") 36 endif() 37 get_filename_component(dir ${file} DIRECTORY) 38 file(MAKE_DIRECTORY ${PACKAGE_PREFIX}/${dir}) 39 file(COPY ${GNUCASH_SOURCE_DIR}/${file} DESTINATION ${PACKAGE_PREFIX}/${dir}) 40 endforeach() 41 42 # -- Copy in build products that are distributed. 43 44 foreach(file ${dist_generated}) 45 execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_SOURCE_DIR}/${file} ${PACKAGE_PREFIX}/${file}) 46 if (NOT EXISTS ${PACKAGE_PREFIX}/${file}) 47 message(FATAL_ERROR "Copy of ${BUILD_SOURCE_DIR}/${file} to dist dir '${PACKAGE_PREFIX}' failed.") 48 endif() 49 endforeach() 50 51 cmake_policy(SET CMP0012 NEW) 52 53 # -- Create the tarball. 54 55 execute_process_and_check_result( 56 COMMAND ${CMAKE_COMMAND} -E tar cf ${PACKAGE_PREFIX}.tar ${PACKAGE_PREFIX} 57 WORKING_DIRECTORY . 58 ERROR_MSG "tar command to create ${PACKAGE_PREFIX}.tar failed." 59 ) 60 61 # -- Compress the tarball with gzip 62 execute_process( 63 COMMAND ${CMAKE_COMMAND} -E copy ${PACKAGE_PREFIX}.tar ${PACKAGE_PREFIX}.tar.save 64 ) 65 execute_process_and_check_result( 66 COMMAND ${CMAKE_COMMAND} -E env gzip -f ${PACKAGE_PREFIX}.tar 67 WORKING_DIRECTORY . 68 ERROR_MSG "gzip command to create ${PACKAGE_PREFIX}.tar.gz failed." 69 ) 70 71 # -- Compress the tarball with bzip2 72 execute_process( 73 COMMAND ${CMAKE_COMMAND} -E rename ${PACKAGE_PREFIX}.tar.save ${PACKAGE_PREFIX}.tar 74 ) 75 execute_process_and_check_result( 76 COMMAND ${CMAKE_COMMAND} -E env bzip2 -f ${PACKAGE_PREFIX}.tar 77 WORKING_DIRECTORY . 78 ERROR_MSG "bzip2 command to create ${PACKAGE_PREFIX}.tar.bz2 failed." 79 ) 80 81 # -- Clean up packaging directory. 82 83 file(REMOVE_RECURSE ${PACKAGE_PREFIX}) 84 85 if(EXISTS ${PACKAGE_PREFIX}) 86 message(WARNING "Could not remove packaging directory '${PACKAGE_PREFIX}'") 87 endif() 88 89 # -- All done. 90 91 message("\n\nDistributions ${PACKAGE_PREFIX}.tar.gz and ${PACKAGE_PREFIX}.tar.bz2 created.\n\n") 92endfunction() 93 94if (NOT WITH_GNUCASH) 95 message(SEND_ERROR "Creation of dist tarballs is not supported when WITH_GNUCASH=OFF.") 96endif() 97 98 make_dist(${PACKAGE_PREFIX} ${GNUCASH_SOURCE_DIR} ${BUILD_SOURCE_DIR} ${BUILDING_FROM_VCS}) 99