Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Modules / CPackRPM.cmake
1 ##section Variables specific to CPack RPM generator
2 ##end
3 ##module
4 # - The builtin (binary) CPack RPM generator (Unix only)
5 # CPackRPM may be used to create RPM package using CPack.
6 # CPackRPM is a CPack generator thus it uses the CPACK_XXX variables
7 # used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
8 #
9 # However CPackRPM has specific features which are controlled by
10 # the specifics CPACK_RPM_XXX variables. CPackRPM is a component aware
11 # generator so when CPACK_RPM_COMPONENT_INSTALL is ON some more
12 # CPACK_RPM_<ComponentName>_XXXX variables may be used in order
13 # to have component specific values. Note however that <componentName>
14 # refers to the **grouping name**. This may be either a component name
15 # or a component GROUP name.
16 # Usually those vars correspond to RPM spec file entities, one may find
17 # information about spec files here http://www.rpm.org/wiki/Docs.
18 # You'll find a detailed usage of CPackRPM on the wiki:
19 #  http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29
20 # However as a handy reminder here comes the list of specific variables:
21 ##end
22 #
23 ##variable
24 #  CPACK_RPM_PACKAGE_SUMMARY - The RPM package summary.
25 #     Mandatory : YES
26 #     Default   : CPACK_PACKAGE_DESCRIPTION_SUMMARY
27 ##end
28 ##variable
29 #  CPACK_RPM_PACKAGE_NAME - The RPM package name.
30 #     Mandatory : YES
31 #     Default   : CPACK_PACKAGE_NAME
32 ##end
33 ##variable
34 #  CPACK_RPM_PACKAGE_VERSION - The RPM package version.
35 #     Mandatory : YES
36 #     Default   : CPACK_PACKAGE_VERSION
37 ##end
38 ##variable
39 #  CPACK_RPM_PACKAGE_ARCHITECTURE - The RPM package architecture.
40 #     Mandatory : NO
41 #     Default   : -
42 #     This may be set to "noarch" if you
43 #     know you are building a noarch package.
44 ##end
45 ##variable
46 #  CPACK_RPM_PACKAGE_RELEASE - The RPM package release.
47 #     Mandatory : YES
48 #     Default   : 1
49 #     This is the numbering of the RPM package
50 #     itself, i.e. the version of the packaging and not the version of the
51 #     content (see CPACK_RPM_PACKAGE_VERSION). One may change the default
52 #     value if the previous packaging was buggy and/or you want to put here
53 #     a fancy Linux distro specific numbering.
54 ##end
55 ##variable
56 #  CPACK_RPM_PACKAGE_LICENSE - The RPM package license policy.
57 #     Mandatory : YES
58 #     Default   : "unknown"
59 ##end
60 ##variable
61 #  CPACK_RPM_PACKAGE_GROUP - The RPM package group.
62 #     Mandatory : YES
63 #     Default   : "unknown"
64 ##end
65 ##variable
66 #  CPACK_RPM_PACKAGE_VENDOR - The RPM package vendor.
67 #     Mandatory : YES
68 #     Default   : CPACK_PACKAGE_VENDOR if set or "unknown"
69 ##end
70 ##variable
71 #  CPACK_RPM_PACKAGE_URL - The projects URL.
72 #     Mandatory : NO
73 #     Default   : -
74 ##end
75 ##variable
76 #  CPACK_RPM_PACKAGE_DESCRIPTION - RPM package description.
77 #     Mandatory : YES
78 #     Default   : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package description available"
79 ##end
80 ##variable
81 #  CPACK_RPM_COMPRESSION_TYPE - RPM compression type.
82 #     Mandatory : NO
83 #     Default   : -
84 #     May be used to override RPM compression type to be used
85 #     to build the RPM. For example some Linux distribution now default
86 #     to lzma or xz compression whereas older cannot use such RPM.
87 #     Using this one can enforce compression type to be used.
88 #     Possible value are: lzma, xz, bzip2 and gzip.
89 ##end
90 ##variable
91 #  CPACK_RPM_PACKAGE_REQUIRES - RPM spec requires field.
92 #     Mandatory : NO
93 #     Default   : -
94 #     May be used to set RPM dependencies (requires).
95 #     Note that you must enclose the complete requires string between quotes,
96 #     for example:
97 #     set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8")
98 #     The required package list of an RPM file could be printed with
99 #     rpm -qp --requires file.rpm
100 ##end
101 ##variable
102 #  CPACK_RPM_PACKAGE_SUGGESTS - RPM spec suggest field.
103 #     Mandatory : NO
104 #     Default   : -
105 #     May be used to set weak RPM dependencies (suggests).
106 #     Note that you must enclose the complete requires string between quotes.
107 ##end
108 ##variable
109 #  CPACK_RPM_PACKAGE_PROVIDES - RPM spec provides field.
110 #     Mandatory : NO
111 #     Default   : -
112 #     May be used to set RPM dependencies (provides).
113 #     The provided package list of an RPM file could be printed with
114 #     rpm -qp --provides file.rpm
115 ##end
116 ##variable
117 #  CPACK_RPM_PACKAGE_OBSOLETES - RPM spec obsoletes field.
118 #     Mandatory : NO
119 #     Default   : -
120 #     May be used to set RPM packages that are obsoleted by this one.
121 ##end
122 ##variable
123 #  CPACK_RPM_PACKAGE_RELOCATABLE - build a relocatable RPM.
124 #     Mandatory : NO
125 #     Default   : CPACK_PACKAGE_RELOCATABLE
126 #     If this variable is set to TRUE or ON CPackRPM will try
127 #     to build a relocatable RPM package. A relocatable RPM may
128 #     be installed using rpm --prefix or --relocate in order to
129 #     install it at an alternate place see rpm(8).
130 #     Note that currently this may fail if CPACK_SET_DESTDIR is set to ON.
131 #     If CPACK_SET_DESTDIR is set then you will get a warning message
132 #     but if there is file installed with absolute path you'll get
133 #     unexpected behavior.
134 ##end
135 ##variable
136 #  CPACK_RPM_SPEC_INSTALL_POST - [deprecated].
137 #     Mandatory : NO
138 #     Default   : -
139 #     This way of specifying post-install script is deprecated use
140 #     CPACK_RPM_POST_INSTALL_SCRIPT_FILE
141 #     May be used to set an RPM post-install command inside the spec file.
142 #     For example setting it to "/bin/true" may be used to prevent
143 #     rpmbuild to strip binaries.
144 ##end
145 ##variable
146 #  CPACK_RPM_SPEC_MORE_DEFINE - RPM extended spec definitions lines.
147 #     Mandatory : NO
148 #     Default   : -
149 #     May be used to add any %define lines to the generated spec file.
150 ##end
151 ##variable
152 #  CPACK_RPM_PACKAGE_DEBUG - Toggle CPackRPM debug output.
153 #     Mandatory : NO
154 #     Default   : -
155 #     May be set when invoking cpack in order to trace debug information
156 #     during CPack RPM run. For example you may launch CPack like this
157 #     cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM
158 ##end
159 ##variable
160 #  CPACK_RPM_USER_BINARY_SPECFILE - A user provided spec file.
161 #     Mandatory : NO
162 #     Default   : -
163 #     May be set by the user in order to specify a USER binary spec file
164 #     to be used by CPackRPM instead of generating the file.
165 #     The specified file will be processed by configure_file( @ONLY).
166 ##end
167 ##variable
168 #  CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE - Spec file template.
169 #     Mandatory : NO
170 #     Default   : -
171 #     If set CPack will generate a template for USER specified binary
172 #     spec file and stop with an error. For example launch CPack like this
173 #     cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM
174 #     The user may then use this file in order to hand-craft is own
175 #     binary spec file which may be used with CPACK_RPM_USER_BINARY_SPECFILE.
176 ##end
177 ##variable
178 #  CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
179 #  CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
180 #     Mandatory : NO
181 #     Default   : -
182 #     May be used to embed a pre (un)installation script in the spec file.
183 #     The refered script file(s) will be read and directly
184 #     put after the %pre or %preun section
185 #     If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for
186 #     each component can be overridden with
187 #     CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE and
188 #     CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE
189 #     One may verify which scriptlet has been included with
190 #      rpm -qp --scripts  package.rpm
191 ##end
192 ##variable
193 #  CPACK_RPM_POST_INSTALL_SCRIPT_FILE
194 #  CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
195 #     Mandatory : NO
196 #     Default   : -
197 #     May be used to embed a post (un)installation script in the spec file.
198 #     The refered script file(s) will be read and directly
199 #     put after the %post or %postun section
200 #     If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for
201 #     each component can be overridden with
202 #     CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE and
203 #     CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE
204 #     One may verify which scriptlet has been included with
205 #      rpm -qp --scripts  package.rpm
206 ##end
207 ##variable
208 #  CPACK_RPM_USER_FILELIST
209 #  CPACK_RPM_<COMPONENT>_USER_FILELIST
210 #     Mandatory : NO
211 #     Default   : -
212 #     May be used to explicitly specify %(<directive>) file line
213 #     in the spec file. Like %config(noreplace) or any other directive
214 #     that be found in the %files section. Since CPackRPM is generating
215 #     the list of files (and directories) the user specified files of
216 #     the CPACK_RPM_<COMPONENT>_USER_FILELIST list will be removed from the generated list.
217 ##end
218 ##variable
219 #  CPACK_RPM_CHANGELOG_FILE - RPM changelog file.
220 #     Mandatory : NO
221 #     Default   : -
222 #     May be used to embed a changelog in the spec file.
223 #     The refered file will be read and directly put after the %changelog
224 #     section.
225 ##end
226
227 #=============================================================================
228 # Copyright 2007-2009 Kitware, Inc.
229 #
230 # Distributed under the OSI-approved BSD License (the "License");
231 # see accompanying file Copyright.txt for details.
232 #
233 # This software is distributed WITHOUT ANY WARRANTY; without even the
234 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
235 # See the License for more information.
236 #=============================================================================
237 # (To distribute this file outside of CMake, substitute the full
238 #  License text for the above reference.)
239
240 # Author: Eric Noulard with the help of Alexander Neundorf.
241
242 if(CMAKE_BINARY_DIR)
243   message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.")
244 endif()
245
246 if(NOT UNIX)
247   message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.")
248 endif()
249
250 # rpmbuild is the basic command for building RPM package
251 # it may be a simple (symbolic) link to rpm command.
252 find_program(RPMBUILD_EXECUTABLE rpmbuild)
253
254 # Check version of the rpmbuild tool this would be easier to
255 # track bugs with users and CPackRPM debug mode.
256 # We may use RPM version in order to check for available version dependent features
257 if(RPMBUILD_EXECUTABLE)
258   execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version
259                   OUTPUT_VARIABLE _TMP_VERSION
260                   ERROR_QUIET
261                   OUTPUT_STRIP_TRAILING_WHITESPACE)
262   string(REGEX REPLACE "^.* " ""
263          RPMBUILD_EXECUTABLE_VERSION
264          ${_TMP_VERSION})
265   if(CPACK_RPM_PACKAGE_DEBUG)
266     message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>")
267   endif()
268 endif()
269
270 if(NOT RPMBUILD_EXECUTABLE)
271   message(FATAL_ERROR "RPM package requires rpmbuild executable")
272 endif()
273
274 # Display lsb_release output if DEBUG mode enable
275 # This will help to diagnose problem with CPackRPM
276 # because we will know on which kind of Linux we are
277 if(CPACK_RPM_PACKAGE_DEBUG)
278   find_program(LSB_RELEASE_EXECUTABLE lsb_release)
279   if(LSB_RELEASE_EXECUTABLE)
280     execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a
281                     OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT
282                     ERROR_QUIET
283                     OUTPUT_STRIP_TRAILING_WHITESPACE)
284     string(REGEX REPLACE "\n" ", "
285            LSB_RELEASE_OUTPUT
286            ${_TMP_LSB_RELEASE_OUTPUT})
287   else ()
288     set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!")
289   endif()
290   message("CPackRPM:Debug: LSB_RELEASE  = ${LSB_RELEASE_OUTPUT}")
291 endif()
292
293 # We may use RPM version in the future in order
294 # to shut down warning about space in buildtree
295 # some recent RPM version should support space in different places.
296 # not checked [yet].
297 if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*")
298   message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.")
299 endif()
300
301 # If rpmbuild is found
302 # we try to discover alien since we may be on non RPM distro like Debian.
303 # In this case we may try to to use more advanced features
304 # like generating RPM directly from DEB using alien.
305 # FIXME feature not finished (yet)
306 find_program(ALIEN_EXECUTABLE alien)
307 if(ALIEN_EXECUTABLE)
308   message(STATUS "alien found, we may be on a Debian based distro.")
309 endif()
310
311 # Are we packaging components ?
312 if(CPACK_RPM_PACKAGE_COMPONENT)
313   set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}")
314 else()
315   set(CPACK_RPM_PACKAGE_COMPONENT_PART_NAME "")
316 endif()
317
318 set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}")
319
320 #
321 # Use user-defined RPM specific variables value
322 # or generate reasonable default value from
323 # CPACK_xxx generic values.
324 # The variables comes from the needed (mandatory or not)
325 # values found in the RPM specification file aka ".spec" file.
326 # The variables which may/should be defined are:
327 #
328
329 # CPACK_RPM_PACKAGE_SUMMARY (mandatory)
330 if(NOT CPACK_RPM_PACKAGE_SUMMARY)
331   # if neither var is defined lets use the name as summary
332   if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
333     string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY)
334   else()
335     set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
336   endif()
337 endif()
338
339 # CPACK_RPM_PACKAGE_NAME (mandatory)
340 if(NOT CPACK_RPM_PACKAGE_NAME)
341   string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME)
342 endif()
343
344 # CPACK_RPM_PACKAGE_VERSION (mandatory)
345 if(NOT CPACK_RPM_PACKAGE_VERSION)
346   if(NOT CPACK_PACKAGE_VERSION)
347     message(FATAL_ERROR "RPM package requires a package version")
348   endif()
349   set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
350 endif()
351 # Replace '-' in version with '_'
352 # '-' character is  an Illegal RPM version character
353 # it is illegal because it is used to separate
354 # RPM "Version" from RPM "Release"
355 string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
356
357 # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
358 if(CPACK_RPM_PACKAGE_ARCHITECTURE)
359   set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
360   if(CPACK_RPM_PACKAGE_DEBUG)
361     message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
362   endif()
363 else()
364   set(TMP_RPM_BUILDARCH "")
365 endif()
366
367 # CPACK_RPM_PACKAGE_RELEASE
368 # The RPM release is the numbering of the RPM package ITSELF
369 # this is the version of the PACKAGING and NOT the version
370 # of the CONTENT of the package.
371 # You may well need to generate a new RPM package release
372 # without changing the version of the packaged software.
373 # This is the case when the packaging is buggy (not) the software :=)
374 # If not set, 1 is a good candidate
375 if(NOT CPACK_RPM_PACKAGE_RELEASE)
376   set(CPACK_RPM_PACKAGE_RELEASE 1)
377 endif()
378
379 # CPACK_RPM_PACKAGE_LICENSE
380 if(NOT CPACK_RPM_PACKAGE_LICENSE)
381   set(CPACK_RPM_PACKAGE_LICENSE "unknown")
382 endif()
383
384 # CPACK_RPM_PACKAGE_GROUP
385 if(NOT CPACK_RPM_PACKAGE_GROUP)
386   set(CPACK_RPM_PACKAGE_GROUP "unknown")
387 endif()
388
389 # CPACK_RPM_PACKAGE_VENDOR
390 if(NOT CPACK_RPM_PACKAGE_VENDOR)
391   if(CPACK_PACKAGE_VENDOR)
392     set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}")
393   else()
394     set(CPACK_RPM_PACKAGE_VENDOR "unknown")
395   endif()
396 endif()
397
398 # CPACK_RPM_PACKAGE_SOURCE
399 # The name of the source tarball in case we generate a source RPM
400
401 # CPACK_RPM_PACKAGE_DESCRIPTION
402 # The variable content may be either
403 #   - explicitly given by the user or
404 #   - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE
405 #     if it is defined
406 #   - set to a default value
407 #
408 if (NOT CPACK_RPM_PACKAGE_DESCRIPTION)
409         if (CPACK_PACKAGE_DESCRIPTION_FILE)
410                 file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
411         else ()
412                 set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available")
413         endif ()
414 endif ()
415
416 # CPACK_RPM_COMPRESSION_TYPE
417 #
418 if (CPACK_RPM_COMPRESSION_TYPE)
419    if(CPACK_RPM_PACKAGE_DEBUG)
420      message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}")
421    endif()
422    if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma")
423      set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio")
424    endif()
425    if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz")
426      set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio")
427    endif()
428    if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2")
429      set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio")
430    endif()
431    if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip")
432      set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio")
433    endif()
434 else()
435    set(CPACK_RPM_COMPRESSION_TYPE_TMP "")
436 endif()
437
438 if(CPACK_PACKAGE_RELOCATABLE)
439   set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
440 endif()
441 if(CPACK_RPM_PACKAGE_RELOCATABLE)
442   if(CPACK_RPM_PACKAGE_DEBUG)
443     message("CPackRPM:Debug: Trying to build a relocatable package")
444   endif()
445   if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON"))
446     message("CPackRPM:Warning: CPACK_SET_DESTDIR is set (=${CPACK_SET_DESTDIR}) while requesting a relocatable package (CPACK_RPM_PACKAGE_RELOCATABLE is set): this is not supported, the package won't be relocatable.")
447   else()
448     set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX})
449   endif()
450 endif()
451
452 # Check if additional fields for RPM spec header are given
453 # There may be some COMPONENT specific variables as well
454 # If component specific var is not provided we use the global one
455 # for each component
456 foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV)
457     if(CPACK_RPM_PACKAGE_DEBUG)
458       message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
459     endif()
460     if(CPACK_RPM_PACKAGE_COMPONENT)
461         if(DEFINED CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER})
462             if(CPACK_RPM_PACKAGE_DEBUG)
463               message("CPackRPM:Debug: using CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}")
464             endif()
465             set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}})
466         else()
467             if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
468               if(CPACK_RPM_PACKAGE_DEBUG)
469                 message("CPackRPM:Debug: CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER} not defined")
470                 message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
471               endif()
472               set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
473             endif()
474         endif()
475     else()
476         if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER})
477           if(CPACK_RPM_PACKAGE_DEBUG)
478             message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}")
479           endif()
480           set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}})
481         endif()
482     endif()
483
484   # Treat the RPM Spec keyword iff it has been properly defined
485   if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP)
486     # Transform NAME --> Name e.g. PROVIDES --> Provides
487     # The Upper-case first letter and lowercase tail is the
488     # appropriate value required in the final RPM spec file.
489     string(LENGTH ${_RPM_SPEC_HEADER} _PACKAGE_HEADER_STRLENGTH)
490     math(EXPR _PACKAGE_HEADER_STRLENGTH "${_PACKAGE_HEADER_STRLENGTH} - 1")
491     string(SUBSTRING ${_RPM_SPEC_HEADER} 1 ${_PACKAGE_HEADER_STRLENGTH} _PACKAGE_HEADER_TAIL)
492     string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL)
493     string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME)
494     set(_PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}${_PACKAGE_HEADER_TAIL}")
495     if(CPACK_RPM_PACKAGE_DEBUG)
496       message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
497     endif()
498     set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}")
499   else()
500     # Do not forget to unset previously set header (from previous component)
501     unset(TMP_RPM_${_RPM_SPEC_HEADER})
502   endif()
503 endforeach()
504
505 # CPACK_RPM_SPEC_INSTALL_POST
506 # May be used to define a RPM post intallation script
507 # for example setting it to "/bin/true" may prevent
508 # rpmbuild from stripping binaries.
509 if(CPACK_RPM_SPEC_INSTALL_POST)
510   if(CPACK_RPM_PACKAGE_DEBUG)
511     message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
512   endif()
513   set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
514 endif()
515
516 # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
517 # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
518 # May be used to embed a post (un)installation script in the spec file.
519 # The refered script file(s) will be read and directly
520 # put after the %post or %postun section
521 if(CPACK_RPM_PACKAGE_COMPONENT)
522   if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE)
523     set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_INSTALL_SCRIPT_FILE})
524   else()
525     set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
526   endif()
527   if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_UNINSTALL_SCRIPT_FILE)
528     set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_POST_UNINSTALL_SCRIPT_FILE})
529   else()
530     set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
531   endif()
532 else()
533   set(CPACK_RPM_POST_INSTALL_READ_FILE ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE})
534   set(CPACK_RPM_POST_UNINSTALL_READ_FILE ${CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE})
535 endif()
536
537 # Handle post-install file if it has been specified
538 if(CPACK_RPM_POST_INSTALL_READ_FILE)
539   if(EXISTS ${CPACK_RPM_POST_INSTALL_READ_FILE})
540     file(READ ${CPACK_RPM_POST_INSTALL_READ_FILE} CPACK_RPM_SPEC_POSTINSTALL)
541   else()
542     message("CPackRPM:Warning: CPACK_RPM_POST_INSTALL_SCRIPT_FILE <${CPACK_RPM_POST_INSTALL_READ_FILE}> does not exists - ignoring")
543   endif()
544 else()
545   # reset SPEC var value if no post install file has been specified
546   # (either globally or component-wise)
547   set(CPACK_RPM_SPEC_POSTINSTALL "")
548 endif()
549
550 # Handle post-uninstall file if it has been specified
551 if(CPACK_RPM_POST_UNINSTALL_READ_FILE)
552   if(EXISTS ${CPACK_RPM_POST_UNINSTALL_READ_FILE})
553     file(READ ${CPACK_RPM_POST_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_POSTUNINSTALL)
554   else()
555     message("CPackRPM:Warning: CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_POST_UNINSTALL_READ_FILE}> does not exists - ignoring")
556   endif()
557 else()
558   # reset SPEC var value if no post uninstall file has been specified
559   # (either globally or component-wise)
560   set(CPACK_RPM_SPEC_POSTUNINSTALL "")
561 endif()
562
563 # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE)
564 # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE)
565 # May be used to embed a pre (un)installation script in the spec file.
566 # The refered script file(s) will be read and directly
567 # put after the %pre or %preun section
568 if(CPACK_RPM_PACKAGE_COMPONENT)
569   if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE)
570     set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_INSTALL_SCRIPT_FILE})
571   else()
572     set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
573   endif()
574   if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_UNINSTALL_SCRIPT_FILE)
575     set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PRE_UNINSTALL_SCRIPT_FILE})
576   else()
577     set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
578   endif()
579 else()
580   set(CPACK_RPM_PRE_INSTALL_READ_FILE ${CPACK_RPM_PRE_INSTALL_SCRIPT_FILE})
581   set(CPACK_RPM_PRE_UNINSTALL_READ_FILE ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE})
582 endif()
583
584 # Handle pre-install file if it has been specified
585 if(CPACK_RPM_PRE_INSTALL_READ_FILE)
586   if(EXISTS ${CPACK_RPM_PRE_INSTALL_READ_FILE})
587     file(READ ${CPACK_RPM_PRE_INSTALL_READ_FILE} CPACK_RPM_SPEC_PREINSTALL)
588   else()
589     message("CPackRPM:Warning: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_INSTALL_READ_FILE}> does not exists - ignoring")
590   endif()
591 else()
592   # reset SPEC var value if no pre-install file has been specified
593   # (either globally or component-wise)
594   set(CPACK_RPM_SPEC_PREINSTALL "")
595 endif()
596
597 # Handle pre-uninstall file if it has been specified
598 if(CPACK_RPM_PRE_UNINSTALL_READ_FILE)
599   if(EXISTS ${CPACK_RPM_PRE_UNINSTALL_READ_FILE})
600     file(READ ${CPACK_RPM_PRE_UNINSTALL_READ_FILE} CPACK_RPM_SPEC_PREUNINSTALL)
601   else()
602     message("CPackRPM:Warning: CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE <${CPACK_RPM_PRE_UNINSTALL_READ_FILE}> does not exists - ignoring")
603   endif()
604 else()
605   # reset SPEC var value if no pre-uninstall file has been specified
606   # (either globally or component-wise)
607   set(CPACK_RPM_SPEC_PREUNINSTALL "")
608 endif()
609
610 # CPACK_RPM_CHANGELOG_FILE
611 # May be used to embed a changelog in the spec file.
612 # The refered file will be read and directly put after the %changelog section
613 if(CPACK_RPM_CHANGELOG_FILE)
614   if(EXISTS ${CPACK_RPM_CHANGELOG_FILE})
615     file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG)
616   else()
617     message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring")
618   endif()
619 else()
620   set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Erk <eric.noulard@gmail.com>\n  Generated by CPack RPM (no Changelog file were provided)")
621 endif()
622
623 # CPACK_RPM_SPEC_MORE_DEFINE
624 # This is a generated spec rpm file spaceholder
625 if(CPACK_RPM_SPEC_MORE_DEFINE)
626   if(CPACK_RPM_PACKAGE_DEBUG)
627     message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}")
628   endif()
629 endif()
630
631 # Now we may create the RPM build tree structure
632 set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}")
633 message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}")
634 # Prepare RPM build tree
635 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR})
636 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp)
637 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD)
638 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS)
639 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
640 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
641 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
642
643 #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
644 set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
645 # it seems rpmbuild can't handle spaces in the path
646 # neither escaping (as below) nor putting quotes around the path seem to help
647 #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
648 set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}")
649
650 # if we are creating a relocatable package, omit parent directories of
651 # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list"
652 # which is passed to the find command that generates the content-list
653 if(CPACK_RPM_PACKAGE_RELOCATABLE)
654   # get a list of the elements in CPACK_RPM_PACKAGE_PREFIX and remove
655   # the final element (so the install-prefix dir itself is not omitted
656   # from the RPM's content-list)
657   string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS ".${CPACK_RPM_PACKAGE_PREFIX}")
658   list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1)
659   # Now generate all of the parent dirs of CPACK_RPM_PACKAGE_PREFIX
660   foreach(_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS})
661     list(APPEND _TMP_LIST "${_ELEM}")
662     string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}")
663     set(_OMIT_DIR "-o -path ${_OMIT_DIR}")
664     separate_arguments(_OMIT_DIR)
665     list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR})
666   endforeach()
667 endif()
668
669 # Use files tree to construct files command (spec file)
670 # We should not forget to include symlinks (thus -o -type l)
671 # We should include directory as well (thus -type d)
672 #   but not the main local dir "." (thus -a -not -name ".")
673 # We must remove the './' due to the local search and escape the
674 # file name by enclosing it between double quotes (thus the sed)
675 # Then we must authorize any man pages extension (adding * at the end)
676 # because rpmbuild may automatically compress those files
677 execute_process(COMMAND find . -type f -o -type l -o (-type d -a -not ( -name "." ${_RPM_DIRS_TO_OMIT} ) )
678                 COMMAND sed s:.*/man.*/.*:&*:
679                 COMMAND sed s/\\.\\\(.*\\\)/\"\\1\"/
680                 WORKING_DIRECTORY "${WDIR}"
681                 OUTPUT_VARIABLE CPACK_RPM_INSTALL_FILES)
682
683 # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_<COMPONENT>
684 #                   into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
685 #         otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES
686 # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling
687 if(CPACK_RPM_PACKAGE_COMPONENT)
688   if(CPACK_ABSOLUTE_DESTINATION_FILES)
689    set(COMPONENT_FILES_TAG "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}")
690    set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}")
691    if(CPACK_RPM_PACKAGE_DEBUG)
692      message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>")
693      message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
694    endif()
695   endif()
696 else()
697   if(CPACK_ABSOLUTE_DESTINATION_FILES)
698     set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}")
699   endif()
700 endif()
701
702 # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM_<COMPONENT>_USER_FILELIST.
703 if(CPACK_RPM_PACKAGE_COMPONENT)
704   if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST)
705     set(CPACK_RPM_USER_FILELIST_INTERNAL ${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST})
706     if(CPACK_RPM_PACKAGE_DEBUG)
707       message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
708       message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}")
709     endif()
710   else()
711     set(CPACK_RPM_USER_FILELIST_INTERNAL "")
712   endif()
713 else()
714   if(CPACK_RPM_USER_FILELIST)
715     set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}")
716   else()
717     set(CPACK_RPM_USER_FILELIST_INTERNAL "")
718   endif()
719 endif()
720
721 # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL
722 # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
723 #                      or CPACK_RPM_INSTALL_FILES,
724 # hence it must be done before these auto-generated lists are processed.
725 if(CPACK_RPM_USER_FILELIST_INTERNAL)
726   if(CPACK_RPM_PACKAGE_DEBUG)
727     message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>")
728   endif()
729
730   # Create CMake list from CPACK_RPM_INSTALL_FILES
731   string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
732   string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
733                           "${CPACK_RPM_INSTALL_FILES_LIST}")
734   string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
735                           "${CPACK_RPM_INSTALL_FILES_LIST}")
736
737   set(CPACK_RPM_USER_INSTALL_FILES "")
738   foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL)
739     string(REGEX REPLACE "%[A-Za-z0-9\(\),-]* " "" F_PATH ${F})
740     string(REGEX MATCH "%[A-Za-z0-9\(\),-]*" F_PREFIX ${F})
741
742     if(CPACK_RPM_PACKAGE_DEBUG)
743       message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>")
744     endif()
745     if(F_PREFIX)
746       set(F_PREFIX "${F_PREFIX} ")
747     endif()
748     # Rebuild the user list file
749     set(CPACK_RPM_USER_INSTALL_FILES "${CPACK_RPM_USER_INSTALL_FILES}${F_PREFIX}\"${F_PATH}\"\n")
750
751     # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL
752     list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH})
753     # ABSOLUTE destination files list may not exists at all
754     if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
755       list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH})
756     endif()
757
758   endforeach()
759
760   # Rebuild CPACK_RPM_INSTALL_FILES
761   set(CPACK_RPM_INSTALL_FILES "")
762   foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
763     set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
764   endforeach()
765 else()
766   set(CPACK_RPM_USER_INSTALL_FILES "")
767 endif()
768
769 if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
770   if(CPACK_RPM_PACKAGE_DEBUG)
771     message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}")
772   endif()
773   # Remove trailing space
774   string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
775   # Transform endline separated - string into CMake List
776   string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
777   # Remove unecessary quotes
778   string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}")
779   # Remove ABSOLUTE install file from INSTALL FILE LIST
780   list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL})
781   # Rebuild INSTALL_FILES
782   set(CPACK_RPM_INSTALL_FILES "")
783   foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
784     set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
785   endforeach()
786   # Build ABSOLUTE_INSTALL_FILES
787   set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
788   foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL)
789     set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "${CPACK_RPM_ABSOLUTE_INSTALL_FILES}%config \"${F}\"\n")
790   endforeach()
791   if(CPACK_RPM_PACKAGE_DEBUG)
792     message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}")
793     message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}")
794   endif()
795 else()
796   # reset vars in order to avoid leakage of value(s) from one component to another
797   set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "")
798 endif()
799
800 # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir
801 # This is necessary to avoid duplicate files since rpmbuild do
802 # recursion on its own when encountering a pathname which is a directory
803 # which is not flagged as %dir
804 string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST)
805 string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST
806                         "${CPACK_RPM_INSTALL_FILES_LIST}")
807 string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST
808                         "${CPACK_RPM_INSTALL_FILES_LIST}")
809 set(CPACK_RPM_INSTALL_FILES "")
810 foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST)
811   if(IS_DIRECTORY "${WDIR}/${F}")
812     set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}%dir \"${F}\"\n")
813   else()
814     set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n")
815   endif()
816 endforeach()
817 set(CPACK_RPM_INSTALL_FILES_LIST "")
818
819 # The name of the final spec file to be used by rpmbuild
820 set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec")
821
822 # Print out some debug information if we were asked for that
823 if(CPACK_RPM_PACKAGE_DEBUG)
824    message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY          = ${CPACK_TOPLEVEL_DIRECTORY}")
825    message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG                = ${CPACK_TOPLEVEL_TAG}")
826    message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY         = ${CPACK_TEMPORARY_DIRECTORY}")
827    message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME            = ${CPACK_OUTPUT_FILE_NAME}")
828    message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH            = ${CPACK_OUTPUT_FILE_PATH}")
829    message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME           = ${CPACK_PACKAGE_FILE_NAME}")
830    message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE         = ${CPACK_RPM_BINARY_SPECFILE}")
831    message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY   = ${CPACK_PACKAGE_INSTALL_DIRECTORY}")
832    message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}")
833 endif()
834
835 # USER generated spec file handling.
836 # We should generate a spec file template:
837 #  - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE
838 #  - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE
839 #
840 if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE)
841    file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in
842       "# -*- rpm-spec -*-
843 BuildRoot:      \@CPACK_RPM_DIRECTORY\@/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@
844 Summary:        \@CPACK_RPM_PACKAGE_SUMMARY\@
845 Name:           \@CPACK_RPM_PACKAGE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_NAME\@
846 Version:        \@CPACK_RPM_PACKAGE_VERSION\@
847 Release:        \@CPACK_RPM_PACKAGE_RELEASE\@
848 License:        \@CPACK_RPM_PACKAGE_LICENSE\@
849 Group:          \@CPACK_RPM_PACKAGE_GROUP\@
850 Vendor:         \@CPACK_RPM_PACKAGE_VENDOR\@
851 \@TMP_RPM_URL\@
852 \@TMP_RPM_REQUIRES\@
853 \@TMP_RPM_PROVIDES\@
854 \@TMP_RPM_OBSOLETES\@
855 \@TMP_RPM_CONFLICTS\@
856 \@TMP_RPM_AUTOPROV\@
857 \@TMP_RPM_AUTOREQ\@
858 \@TMP_RPM_AUTOREQPROV\@
859 \@TMP_RPM_BUILDARCH\@
860 \@TMP_RPM_PREFIX\@
861
862 %define _rpmdir \@CPACK_RPM_DIRECTORY\@
863 %define _rpmfilename \@CPACK_RPM_FILE_NAME\@
864 %define _unpackaged_files_terminate_build 0
865 %define _topdir \@CPACK_RPM_DIRECTORY\@
866 \@TMP_RPM_SPEC_INSTALL_POST\@
867 \@CPACK_RPM_SPEC_MORE_DEFINE\@
868 \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
869
870 %description
871 \@CPACK_RPM_PACKAGE_DESCRIPTION\@
872
873 # This is a shortcutted spec file generated by CMake RPM generator
874 # we skip _install step because CPack does that for us.
875 # We do only save CPack installed tree in _prepr
876 # and then restore it in build.
877 %prep
878 mv $RPM_BUILD_ROOT \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\"
879
880 #p build
881
882 %install
883 if [ -e $RPM_BUILD_ROOT ];
884 then
885   rm -rf $RPM_BUILD_ROOT
886 fi
887 mv \"\@CPACK_TOPLEVEL_DIRECTORY\@/tmpBBroot\" $RPM_BUILD_ROOT
888
889 %clean
890
891 %post
892 \@CPACK_RPM_SPEC_POSTINSTALL\@
893
894 %postun
895 \@CPACK_RPM_SPEC_POSTUNINSTALL\@
896
897 %pre
898 \@CPACK_RPM_SPEC_PREINSTALL\@
899
900 %preun
901 \@CPACK_RPM_SPEC_PREUNINSTALL\@
902
903 %files
904 %defattr(-,root,root,-)
905 ${CPACK_RPM_INSTALL_FILES}
906 ${CPACK_RPM_ABSOLUTE_INSTALL_FILES}
907 ${CPACK_RPM_USER_INSTALL_FILES}
908
909 %changelog
910 \@CPACK_RPM_SPEC_CHANGELOG\@
911 ")
912   # Stop here if we were asked to only generate a template USER spec file
913   # The generated file may then be used as a template by user who wants
914   # to customize their own spec file.
915   if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE)
916      message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file templare is: ${CPACK_RPM_BINARY_SPECFILE}.in")
917   endif()
918 endif()
919
920 # After that we may either use a user provided spec file
921 # or generate one using appropriate variables value.
922 if(CPACK_RPM_USER_BINARY_SPECFILE)
923   # User may have specified SPECFILE just use it
924   message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}")
925   # The user provided file is processed for @var replacement
926   configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
927 else()
928   # No User specified spec file, will use the generated spec file
929   message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}")
930   # Note the just created file is processed for @var replacement
931   configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY)
932 endif()
933
934 if(RPMBUILD_EXECUTABLE)
935   # Now call rpmbuild using the SPECFILE
936   execute_process(
937     COMMAND "${RPMBUILD_EXECUTABLE}" -bb
938             --define "_topdir ${CPACK_RPM_DIRECTORY}"
939             --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
940             "${CPACK_RPM_BINARY_SPECFILE}"
941     WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
942     RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
943     ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err"
944     OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
945   if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT)
946     file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err RPMBUILDERR)
947     file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out RPMBUILDOUT)
948     message("CPackRPM:Debug: You may consult rpmbuild logs in: ")
949     message("CPackRPM:Debug:    - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.err")
950     message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
951     message("CPackRPM:Debug:    - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.out")
952     message("CPackRPM:Debug: *** ${RPMBUILDERR} ***")
953   endif()
954 else()
955   if(ALIEN_EXECUTABLE)
956     message(FATAL_ERROR "RPM packaging through alien not done (yet)")
957   endif()
958 endif()