• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
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.
8#
9# - Define RPMTools_ADD_RPM_TARGETS which defines
10#   two (top-level) CUSTOM targets for building
11#   source and binary RPMs
12#
13# Those CMake macros are provided by the TSP Developer Team
14# https://savannah.nongnu.org/projects/tsp
15#
16
17IF (WIN32)
18  MESSAGE(STATUS "RPM tools not available on Win32 systems")
19ENDIF(WIN32)
20
21IF (UNIX)
22  # Look for RPM builder executable
23  FIND_PROGRAM(RPMTools_RPMBUILD_EXECUTABLE
24    NAMES rpmbuild
25    PATHS "/usr/bin;/usr/lib/rpm"
26    PATH_SUFFIXES bin
27    DOC "The RPM builder tool")
28
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)
37
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")
42
43  IF (RPMTools_RPMBUILD_FOUND)
44    SET(RPMTools_FOUND TRUE)
45    #
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]
49    #
50    MACRO(RPMTools_ADD_RPM_TARGETS RPMNAME)
51
52      #
53      # If no spec file is provided create a minimal one
54      #
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 "")
60
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}")
68
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)
77
78      #
79      # We check whether if the provided spec file is
80      # to be configure or not.
81      #
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
87	  "# -*- rpm-spec -*-
88Summary:        ${RPMNAME}
89Name:           ${RPMNAME}
90Version:        ${CPACK_PACKAGE_VERSION}
91Release:        1
92License:        Unknown
93Group:          Unknown
94Source:         ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
95BuildRoot:      %{_tmppath}/%{name}-%{CPACK_PACKAGE_VERSION}-1-root
96BuildRequires:	cmake
97
98%define prefix /opt/${RPMNAME}-%{version}
99%define rpmprefix $RPM_BUILD_ROOT%{prefix}
100%define srcdirname %{name}-%{version}
101
102%description
103${RPMNAME} : No description for now
104
105%prep
106%setup -q -n %{srcdirname}
107
108%build
109cd ..
110rm -rf build_tree
111mkdir build_tree
112cd build_tree
113cmake -DCMAKE_INSTALL_PREFIX=%{rpmprefix} ../%{srcdirname}
114make %{?_smp_mflags}
115
116%install
117cd ../build_tree
118make install
119
120%clean
121rm -rf %{srcdirname}
122rm -rf build_tree
123
124%files
125%defattr(-,root,root,-)
126%dir %{prefix}
127%{prefix}/*
128
129%changelog
130* Wed Feb 28 2007 Erk <eric.noulard@gmail.com>
131  Generated by CMake UseRPMTools macros"
132	)
133
134      ELSE ("${ARGV1}" STREQUAL "")
135	SET(SPECFILE_PATH "${ARGV1}")
136
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}>")
142	  CONFIGURE_FILE(
143	    ${SPECFILE_PATH}
144	    ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
145	    COPYONLY)
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}>")
151	  CONFIGURE_FILE(
152	    ${SPECFILE_PATH}
153	    ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
154	    @ONLY)
155	ENDIF ("${SPECFILE_EXT}" STREQUAL ".spec")
156      ENDIF("${ARGV1}" STREQUAL "")
157
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}
162	)
163
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}
168	)
169    ENDMACRO(RPMTools_ADD_RPM_TARGETS)
170
171  ELSE (RPMTools_RPMBUILD_FOUND)
172    SET(RPMTools FALSE)
173  ENDIF (RPMTools_RPMBUILD_FOUND)
174
175ENDIF (UNIX)
176
177