File: DistTargets.cmake

package info (click to toggle)
evolution 3.56.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 135,044 kB
  • sloc: ansic: 519,950; javascript: 8,494; xml: 5,207; python: 702; makefile: 563; sh: 294; perl: 169
file content (88 lines) | stat: -rw-r--r-- 3,448 bytes parent folder | download | duplicates (15)
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
# DistTarget.cmake
#
# Defines custom targets related to distributing source code.
# It requires to have populated 'PROJECT_NAME' and 'PROJECT_VERSION' variables,
# possibly through the project() command. It also uses 'PROJECT_DISTCONFIGURE_PARAMS'
# variable when configuring the unpacked distribution.
#
# Added targets:
# dist - only creates a tarball
# disttest - creates a tarball and 'make && make install' it to a temporary prefix
#    to verify that the code can be built and installed; it also verifies
#    that the first line of the NEWS file contains the same version as
#    the tarball and that it claims today's date.
# distcheck - similar to 'disttest', only runs also 'make check' before installing

# Filenames for tarball
set(ARCHIVE_BASE_NAME ${PROJECT_NAME}-${PROJECT_VERSION})
set(ARCHIVE_FULL_NAME ${ARCHIVE_BASE_NAME}.tar.xz)

add_custom_target(dist
	COMMAND ${CMAKE_COMMAND} -E chdir . "${CMAKE_SOURCE_DIR}/cmake/verify-pre-dist.sh"
	COMMAND ${CMAKE_COMMAND} -E echo "Creating '${ARCHIVE_FULL_NAME}'..."
	COMMAND git archive --prefix=${ARCHIVE_BASE_NAME}/ HEAD | xz -z > ${CMAKE_BINARY_DIR}/${ARCHIVE_FULL_NAME}
	COMMAND ${CMAKE_COMMAND} -E echo "Distribution tarball '${ARCHIVE_FULL_NAME}' created at ${CMAKE_BINARY_DIR}"
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

set(disttest_extract_dir "${CMAKE_BINARY_DIR}/${ARCHIVE_BASE_NAME}")
set(disttest_build_dir "${disttest_extract_dir}/_build")
set(disttest_install_dir "${disttest_extract_dir}/_install")

add_custom_command(OUTPUT ${disttest_build_dir}/Makefile
	# remove any left-over directory
	COMMAND ${CMAKE_COMMAND} -E remove_directory ${disttest_extract_dir}

	# extract the tarball
	COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} tar -xf ${ARCHIVE_FULL_NAME}

	# verify the NEWS file contains what it should contain
	COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}
		bash ${CMAKE_SOURCE_DIR}/cmake/verify-news-file.sh "${disttest_extract_dir}/NEWS" "${PROJECT_VERSION}"

	# create a _build sub-directory
	COMMAND ${CMAKE_COMMAND} -E make_directory "${disttest_build_dir}"

	# configure the project with PROJECT_DISTCHECK_PARAMS
	COMMAND ${CMAKE_COMMAND} -E chdir "${disttest_build_dir}"
		${CMAKE_COMMAND} -G "Unix Makefiles"
			${PROJECT_DISTCONFIGURE_PARAMS}
			-DCMAKE_BUILD_TYPE=Release
			-DCMAKE_INSTALL_PREFIX="${disttest_install_dir}"
			..

	# 'make' the project
	COMMAND ${CMAKE_COMMAND} -E chdir ${disttest_build_dir} make -j

	DEPENDS dist
	COMMENT "Building from distribution tarball ${ARCHIVE_FULL_NAME}..."
)

add_custom_target(distcheck
	# 'make check' the project
	COMMAND ${CMAKE_COMMAND} -E chdir ${disttest_build_dir} make -j check

	# 'make install' the project
	COMMAND ${CMAKE_COMMAND} -E chdir ${disttest_build_dir} make -j install

	# if we get this far, then everything worked, thus clean up
	COMMAND ${CMAKE_COMMAND} -E remove_directory ${disttest_extract_dir}

	# and show the good news
	COMMAND ${CMAKE_COMMAND} -E echo "distcheck of '${ARCHIVE_FULL_NAME}' succeeded"

	DEPENDS ${disttest_build_dir}/Makefile
)

add_custom_target(disttest
	# 'make install' the project
	COMMAND ${CMAKE_COMMAND} -E chdir ${disttest_build_dir} make -j install

	# if we get this far, then everything worked, thus clean up
	COMMAND ${CMAKE_COMMAND} -E remove_directory ${disttest_extract_dir}

	# and show the good news
	COMMAND ${CMAKE_COMMAND} -E echo "disttest of '${ARCHIVE_FULL_NAME}' succeeded"

	DEPENDS ${disttest_build_dir}/Makefile
)