-
Notifications
You must be signed in to change notification settings - Fork 543
/
Copy pathMakeDist.cmake
101 lines (77 loc) · 2.94 KB
/
MakeDist.cmake
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
# This module implements the process of making source distribution tarballs.
# The list of all non-generated files to include in the distribution is
# 'dist_manifest.txt'. Inclusion of generated files (e.g., documentation) is
# handled via the 'dist_generated' CMake cache variable.
#
# The procedure is:
#
# 1. Remove any existing dist directory and make a new one.
# 2. Copy all of the files in dist_manifest.text and ${dist_generated}
# into the dist directory.
# 3. Create the tarball and compress it.
# 4. Remove the dist directory.
include (MakeDistFiles)
function (MAKE_DIST PACKAGE_PREFIX MONGOCXX_SOURCE_DIR BUILD_SOURCE_DIR)
set (CMAKE_COMMAND_TMP "")
set (CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env)
# -- 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 ${MONGOCXX_SOURCE_DIR}/${file})
message (FATAL_ERROR
"Can't find dist file ${MONGOCXX_SOURCE_DIR}/${file}"
)
endif ()
get_filename_component (dir ${file} DIRECTORY)
file (MAKE_DIRECTORY ${PACKAGE_PREFIX}/${dir})
file (COPY
${MONGOCXX_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_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."
)
# -- 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\nDistribution ${PACKAGE_PREFIX}.tar.gz created.\n\n")
endfunction ()
make_dist (${PACKAGE_PREFIX} ${MONGOCXX_SOURCE_DIR} ${BUILD_SOURCE_DIR})