File: MakeDist.cmake

package info (click to toggle)
gnucash 1%3A3.4-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,864 kB
  • sloc: ansic: 327,376; cpp: 71,145; lisp: 47,888; javascript: 23,306; python: 8,063; xml: 4,622; perl: 524; sh: 223; makefile: 55
file content (103 lines) | stat: -rw-r--r-- 3,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# This file implements the process of making source distribution tarballs. It expects to find list in
# 'dist_manifest.txt' of all of the files to be included in the distribution, EXCEPT those
# files that are generated. The list of generated files handled via the 'dist_generated' cmake cache variable
#
# Given all of these files, the procedure is to:
# 1. Remove any existing dist directory and make a new one.
# 2. Copy of all the files in dist_manifest.text and ${dist_generated}
#    into the dist directory.
# 3. Create the tarball and compress it with gzip and bzip2.
# 4. Then remove the dist directory.

include(${CMAKE_MODULE_PATH}/MakeDistFiles.cmake)



function(make_dist PACKAGE_PREFIX GNUCASH_SOURCE_DIR BUILD_SOURCE_DIR BUILDING_FROM_VCS)

    set(CMAKE_COMMAND_TMP "")
    if (${CMAKE_VERSION} VERSION_GREATER 3.1)
        set(CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env)
    endif()

    # -- Remove any existing packaging directory.
    file(REMOVE_RECURSE ${PACKAGE_PREFIX})

    if (EXISTS ${PACKAGE_PREFIX})
        message(FATAL_ERROR "Unable to remove existing dist directory \"${PACKAGE_PREFIX}\". Cannot continue.")
    endif()


    # -- Copy in distributed files
    if(NOT EXISTS dist_manifest.txt)
        message(FATAL_ERROR "Cannot find dist manifest: dist_manifest.txt")
    endif()

    file(STRINGS dist_manifest.txt ALL_DIST)

    foreach(file ${ALL_DIST})
        if(NOT EXISTS ${GNUCASH_SOURCE_DIR}/${file})
            message(FATAL_ERROR "Can't find dist file ${GNUCASH_SOURCE_DIR}/${file}")
        endif()
        get_filename_component(dir ${file} DIRECTORY)
        file(MAKE_DIRECTORY ${PACKAGE_PREFIX}/${dir})
        file(COPY ${GNUCASH_SOURCE_DIR}/${file} DESTINATION ${PACKAGE_PREFIX}/${dir})
    endforeach()

    # -- Copy in build products that are distributed.

    foreach(file ${dist_generated})
        execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_SOURCE_DIR}/${file} ${PACKAGE_PREFIX}/${file})
        if (NOT EXISTS ${PACKAGE_PREFIX}/${file})
            message(FATAL_ERROR "Copy of ${BUILD_SOURCE_DIR}/${file} to dist dir '${PACKAGE_PREFIX}' failed.")
        endif()
    endforeach()

    cmake_policy(SET CMP0012 NEW)

    # -- Create the tarball.

    execute_process_and_check_result(
            COMMAND ${CMAKE_COMMAND} -E tar cf ${PACKAGE_PREFIX}.tar ${PACKAGE_PREFIX}
            WORKING_DIRECTORY .
            ERROR_MSG "tar command to create ${PACKAGE_PREFIX}.tar failed."
    )

    # -- Compress the tarball with gzip
    execute_process(
        COMMAND ${CMAKE_COMMAND} -E copy ${PACKAGE_PREFIX}.tar ${PACKAGE_PREFIX}.tar.save
    )
    execute_process_and_check_result(
            COMMAND ${CMAKE_COMMAND_TMP} gzip -f ${PACKAGE_PREFIX}.tar
            WORKING_DIRECTORY .
            ERROR_MSG "gzip command to create ${PACKAGE_PREFIX}.tar.gz failed."
    )

    # -- Compress the tarball with bzip2
    execute_process(
        COMMAND ${CMAKE_COMMAND} -E rename ${PACKAGE_PREFIX}.tar.save ${PACKAGE_PREFIX}.tar
    )
    execute_process_and_check_result(
            COMMAND ${CMAKE_COMMAND_TMP} bzip2 -f ${PACKAGE_PREFIX}.tar
            WORKING_DIRECTORY .
            ERROR_MSG "bzip2 command to create ${PACKAGE_PREFIX}.tar.bz2 failed."
    )

    # -- Clean up packaging directory.

    file(REMOVE_RECURSE ${PACKAGE_PREFIX})

    if(EXISTS ${PACKAGE_PREFIX})
        message(WARNING "Could not remove packaging directory '${PACKAGE_PREFIX}'")
    endif()

    # -- All done.

    message("\n\nDistributions ${PACKAGE_PREFIX}.tar.gz and ${PACKAGE_PREFIX}.tar.bz2 created.\n\n")
endfunction()

if (NOT WITH_GNUCASH)
    message(SEND_ERROR "Creation of dist tarballs is not supported when WITH_GNUCASH=OFF.")
endif()

 make_dist(${PACKAGE_PREFIX} ${GNUCASH_SOURCE_DIR} ${BUILD_SOURCE_DIR} ${BUILDING_FROM_VCS})