2 # - Find tools needed for building RPM Packages
3 # on Linux systems and defines macro that helps to
4 # build source or binary RPM, the MACRO assumes
5 # CMake 2.4.x which includes CPack support.
6 # CPack is used to build tar.gz source tarball
7 # which may be used by a custom user-made spec file.
9 # - Define RPMTools_ADD_RPM_TARGETS which defines
10 # two (top-level) CUSTOM targets for building
11 # source and binary RPMs
13 # Those CMake macros are provided by the TSP Developer Team
14 # https://savannah.nongnu.org/projects/tsp
18 MESSAGE(STATUS "RPM tools not available on Win32 systems")
22 # Look for RPM builder executable
23 FIND_PROGRAM(RPMTools_RPMBUILD_EXECUTABLE
25 PATHS "/usr/bin;/usr/lib/rpm"
27 DOC "The RPM builder tool")
29 IF (RPMTools_RPMBUILD_EXECUTABLE)
30 MESSAGE(STATUS "Looking for RPMTools... - found rpmuild is ${RPMTools_RPMBUILD_EXECUTABLE}")
31 SET(RPMTools_RPMBUILD_FOUND "YES")
32 GET_FILENAME_COMPONENT(RPMTools_BINARY_DIRS ${RPMTools_RPMBUILD_EXECUTABLE} PATH)
33 ELSE (RPMTools_RPMBUILD_EXECUTABLE)
34 SET(RPMTools_RPMBUILD_FOUND "NO")
35 MESSAGE(STATUS "Looking for RPMTools... - rpmbuild NOT FOUND")
36 ENDIF (RPMTools_RPMBUILD_EXECUTABLE)
38 # Detect if CPack was included or not
39 IF (NOT DEFINED "CPACK_PACKAGE_NAME")
40 MESSAGE(FATAL_ERROR "CPack was not included, you should include CPack before Using RPMTools")
41 ENDIF (NOT DEFINED "CPACK_PACKAGE_NAME")
43 IF (RPMTools_RPMBUILD_FOUND)
44 SET(RPMTools_FOUND TRUE)
46 # - first arg (ARGV0) is RPM name
47 # - second arg (ARGV1) is the RPM spec file path [optional]
48 # - third arg (ARGV2) is the RPM ROOT DIRECTORY used to build RPMs [optional]
50 MACRO(RPMTools_ADD_RPM_TARGETS RPMNAME)
53 # If no spec file is provided create a minimal one
55 IF ("${ARGV1}" STREQUAL "")
56 SET(SPECFILE_PATH "${CMAKE_BINARY_DIR}/${RPMNAME}.spec")
57 ELSE ("${ARGV1}" STREQUAL "")
58 SET(SPECFILE_PATH "${ARGV1}")
59 ENDIF("${ARGV1}" STREQUAL "")
61 # Verify whether if RPM_ROOTDIR was provided or not
62 IF("${ARGV2}" STREQUAL "")
63 SET(RPM_ROOTDIR ${CMAKE_BINARY_DIR}/RPM)
64 ELSE ("${ARGV2}" STREQUAL "")
65 SET(RPM_ROOTDIR "${ARGV2}")
66 ENDIF("${ARGV2}" STREQUAL "")
67 MESSAGE(STATUS "RPMTools:: Using RPM_ROOTDIR=${RPM_ROOTDIR}")
69 # Prepare RPM build tree
70 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR})
71 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/tmp)
72 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/BUILD)
73 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/RPMS)
74 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SOURCES)
75 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SPECS)
76 FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SRPMS)
79 # We check whether if the provided spec file is
80 # to be configure or not.
82 IF ("${ARGV1}" STREQUAL "")
83 SET(SPECFILE_PATH "${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec")
84 SET(SPECFILE_NAME "${RPMNAME}.spec")
85 MESSAGE(STATUS "No Spec file given generate a minimal one --> ${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec")
86 FILE(WRITE ${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec
90 Version: ${CPACK_PACKAGE_VERSION}
94 Source: ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
95 BuildRoot: %{_tmppath}/%{name}-%{CPACK_PACKAGE_VERSION}-1-root
98 %define prefix /opt/${RPMNAME}-%{version}
99 %define rpmprefix $RPM_BUILD_ROOT%{prefix}
100 %define srcdirname %{name}-%{version}
103 ${RPMNAME} : No description for now
106 %setup -q -n %{srcdirname}
113 cmake -DCMAKE_INSTALL_PREFIX=%{rpmprefix} ../%{srcdirname}
125 %defattr(-,root,root,-)
130 * Wed Feb 28 2007 Erk <eric.noulard@gmail.com>
131 Generated by CMake UseRPMTools macros"
134 ELSE ("${ARGV1}" STREQUAL "")
135 SET(SPECFILE_PATH "${ARGV1}")
137 GET_FILENAME_COMPONENT(SPECFILE_EXT ${SPECFILE_PATH} EXT)
138 IF ("${SPECFILE_EXT}" STREQUAL ".spec")
139 # This is a 'ready-to-use' spec file which does not need to be CONFIGURED
140 GET_FILENAME_COMPONENT(SPECFILE_NAME ${SPECFILE_PATH} NAME)
141 MESSAGE(STATUS "Simple copy spec file <${SPECFILE_PATH}> --> <${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}>")
144 ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
146 ELSE ("${SPECFILE_EXT}" STREQUAL ".spec")
147 # This is a to-be-configured spec file
148 GET_FILENAME_COMPONENT(SPECFILE_NAME ${SPECFILE_PATH} NAME_WE)
149 SET(SPECFILE_NAME "${SPECFILE_NAME}.spec")
150 MESSAGE(STATUS "Configuring spec file <${SPECFILE_PATH}> --> <${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}>")
153 ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
155 ENDIF ("${SPECFILE_EXT}" STREQUAL ".spec")
156 ENDIF("${ARGV1}" STREQUAL "")
158 ADD_CUSTOM_TARGET(${RPMNAME}_srpm
159 COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
160 COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz ${RPM_ROOTDIR}/SOURCES
161 COMMAND ${RPMTools_RPMBUILD_EXECUTABLE} -bs --define=\"_topdir ${RPM_ROOTDIR}\" --buildroot=${RPM_ROOTDIR}/tmp ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
164 ADD_CUSTOM_TARGET(${RPMNAME}_rpm
165 COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
166 COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz ${RPM_ROOTDIR}/SOURCES
167 COMMAND ${RPMTools_RPMBUILD_EXECUTABLE} -bb --define=\"_topdir ${RPM_ROOTDIR}\" --buildroot=${RPM_ROOTDIR}/tmp ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
169 ENDMACRO(RPMTools_ADD_RPM_TARGETS)
171 ELSE (RPMTools_RPMBUILD_FOUND)
173 ENDIF (RPMTools_RPMBUILD_FOUND)