summaryrefslogtreecommitdiff
path: root/legacy/eobj/cmake/Modules/MakeDistcheck.cmake
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2012-04-05 15:31:15 +0000
committerTom Hacohen <tom@stosb.com>2012-04-05 15:31:15 +0000
commit4f3f37059c7ec45c7154a4d7f89f9d133c49cc94 (patch)
treebe48af36650e4ce576b81e6e9df4d4d04cd6e30d /legacy/eobj/cmake/Modules/MakeDistcheck.cmake
parent8b6d230f5bfed840e2d12195d1f96c602c76da0d (diff)
Eobj: Initial commit.
SVN revision: 69932
Diffstat (limited to '')
-rw-r--r--legacy/eobj/cmake/Modules/MakeDistcheck.cmake122
1 files changed, 122 insertions, 0 deletions
diff --git a/legacy/eobj/cmake/Modules/MakeDistcheck.cmake b/legacy/eobj/cmake/Modules/MakeDistcheck.cmake
new file mode 100644
index 0000000000..1f383a5994
--- /dev/null
+++ b/legacy/eobj/cmake/Modules/MakeDistcheck.cmake
@@ -0,0 +1,122 @@
1# - adds support for the 'make distcheck' command -*- cmake -*-
2# Dependencies:
3# 1. CPack generating ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz.
4# 2. Having a "dist" target, e.g:
5# add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
6# Usage:
7# add_distcheck() ... called exactly once per project in the top-level
8# CMakeLists.txt; it adds the 'dist' and 'distcheck'
9# targets
10#
11# This module implements the 'make dist' and 'make distcheck'
12# commands.
13# It supports the following variables:
14#
15# DISTCHECK_TMPDIR ... directory for temporary files
16# DISTCHECK_FILENAME ... basename of existing tar.gz.; defaults to
17# ${CPACK_SOURCE_PACKAGE_FILE_NAME}
18# DISTCHECK_CMAKEFLAGS
19# ... flags which are given to 'cmake' by 'make distcheck'
20# DISTCHECK_BUILDTARGETS
21# ... the build-targets tried by 'make distcheck';
22# defaults to nothing (--> all)
23# DISTCHECK_INSTALLTARGETS
24# ... the install-targets tried by 'make distcheck';
25# defaults to 'install'
26#
27# Example:
28# --- top-level CMakeLists.txt ---
29# add_subdirectory(foo)
30# ...
31# ...
32# set(CPACK_PACKAGE_VERSION_MAJOR ${ECRIRE_VERSION_MAJOR})
33# set(CPACK_PACKAGE_VERSION_MINOR ${ECRIRE_VERSION_MINOR})
34# set(CPACK_PACKAGE_VERSION_PATCH ${ECRIRE_VERSION_MICRO})
35# set(CPACK_SOURCE_GENERATOR "TGZ")
36# set(CPACK_SOURCE_IGNORE_FILES
37# "${CMAKE_BINARY_DIR};/.git/;~$;${CPACK_SOURCE_IGNORE_FILES}")
38# include(CPack)
39# add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
40#
41# find_package(Distcheck)
42# add_distcheck()
43#
44#
45# Copyright (C) 2012 Tom Hacohen <tom@stosb.com>
46# Based on the work done by:
47# Copyright (C) 2006 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
48#
49# Redistribution and use, with or without modification, are permitted
50# provided that the following conditions are met:
51#
52# 1. Redistributions must retain the above copyright notice, this
53# list of conditions and the following disclaimer.
54# 2. The name of the author may not be used to endorse or promote
55# products derived from this software without specific prior
56# written permission.
57#
58# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
62# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
64# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
66# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
67# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
68# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69
70macro(add_distcheck)
71 set(MakeDist_FOUND 1)
72
73 set(DISTCHECK_TMPDIR "${CMAKE_BINARY_DIR}/.make-dist" CACHE PATH "directory for temporary files created by'make dist*'")
74 set(DISTCHECK_FILENAME ${CPACK_SOURCE_PACKAGE_FILE_NAME} CACHE PATH "basename of the tarball created by 'make dist'")
75 set(DISTCHECK_CMAKEFLAGS CACHE STRING "flags which are given to 'cmake' by 'make distcheck'")
76 set(DISTCHECK_BUILDTARGETS "" CACHE STRING "build-target(s) tried by 'make distcheck'")
77 set(DISTCHECK_INSTALLTARGETS install CACHE STRING "install-target(s) tried by 'make distcheck'")
78
79 mark_as_advanced(DISTCHECK_TMPDIR DISTCHECK_FILENAME DISTCHECK_CMAKEFLAGS DISTCHECK_BUILDTARGETS DISTCHECK_INSTALLTARGETS)
80
81 set(DISTCHECK_BASESOURCEDIR "${DISTCHECK_TMPDIR}/source")
82 set(DISTCHECK_SOURCEDIR "${DISTCHECK_BASESOURCEDIR}/${DISTCHECK_FILENAME}")
83 set(DISTCHECK_BUILDDIR "${DISTCHECK_TMPDIR}/build")
84 set(DISTCHECK_INSTALLTARGETS "install")
85 add_custom_target(distcheck
86 # Create the tarball
87 COMMAND ${CMAKE_MAKE_PROGRAM} dist
88
89 # Create the temp dir.
90 COMMAND chmod -Rf a+w "${DISTCHECK_TMPDIR}" 2>/dev/null || :
91 COMMAND rm -rf "${DISTCHECK_TMPDIR}"
92 COMMAND mkdir -p "${DISTCHECK_SOURCEDIR}" "${DISTCHECK_BUILDDIR}"
93
94 # extract tarball
95 COMMAND tar xzf ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz -C "${DISTCHECK_BASESOURCEDIR}"
96 # write-protect sources to detect modifies-sourcetree bugs
97 COMMAND chmod -R a-w "${DISTCHECK_SOURCEDIR}"
98
99 COMMAND cd "${DISTCHECK_BUILDDIR}" && ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX:PATH="${DISTCHECK_TMPDIR}/install" ${DISTCHECK_CMAKEFLAGS} "${DISTCHECK_SOURCEDIR}"
100
101 COMMAND cd "${DISTCHECK_BUILDDIR}" && ${CMAKE_MAKE_PROGRAM} ${DISTCHECK_BUILDTARGETS}
102
103 # execute 'make install' without DESTDIR
104 COMMAND cd "${DISTCHECK_BUILDDIR}" && ${CMAKE_MAKE_PROGRAM} ${DISTCHECK_INSTALLTARGETS} DESTDIR=
105 # write protect installation path to detect writing outside of DESTDIR
106 COMMAND chmod -R a-w "${DISTCHECK_TMPDIR}/install"
107 # execute 'make install' with DESTDIR and move the files to a better location
108 COMMAND cd "${DISTCHECK_BUILDDIR}" && ${CMAKE_MAKE_PROGRAM} ${DISTCHECK_INSTALLTARGETS} DESTDIR="${DISTCHECK_TMPDIR}/install-tmp"
109 COMMAND mv "${DISTCHECK_TMPDIR}/install-tmp/${DISTCHECK_TMPDIR}/install" "${DISTCHECK_TMPDIR}/install-destdir"
110
111 # generate list of files which were installed by the both 'make
112 # install' commands above and compare them
113 COMMAND cd "${DISTCHECK_TMPDIR}/install" && find -type f | sort > ../files.install
114 COMMAND cd "${DISTCHECK_TMPDIR}/install-destdir" && find -type f | sort > ../files.destdir
115 COMMAND cd "${DISTCHECK_TMPDIR}" && diff files.install files.destdir
116
117 # cleanup tmpdir
118 COMMAND chmod -R u+Xw "${DISTCHECK_TMPDIR}" 2>/dev/null || :
119 COMMAND rm -rf "${DISTCHECK_TMPDIR}"
120 )
121endmacro(add_distcheck)
122