Skip to content

Commit

Permalink
Added variables and new spec template to generate RPM source and
Browse files Browse the repository at this point in the history
binary files via UseRPMTools.cmake.
  • Loading branch information
prelz committed Dec 28, 2012
1 parent 8bf7cdb commit b5179a0
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(CMAKE_INSTALL_PREFIX "/usr")
set(CPACK_PACKAGE_VENDOR "EMI")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Batch Local ASCII Helper Protocol suite")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/blah_description.txt")
file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_PACKAGE_DESCRIPTION)
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "19")
set(CPACK_PACKAGE_VERSION_PATCH "0")
Expand All @@ -44,19 +45,38 @@ set(CPACK_PACKAGE_VERSION
set(CPACK_SET_DESTDIR ON)
set(CPACK_PACKAGE_RELOCATABLE "false")

# Pre-definition of variables for the UseRPMTools spec template
set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_RPM_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
set(CPACK_RPM_PACKAGE_VENDOR ${CPACK_PACKAGE_VENDOR})

set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_RPM_PACKAGE_LICENSE "Apache Software License")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Internet")
set(CPACK_RPM_USER_BINARY_SPECFILE "${CMAKE_CURRENT_SOURCE_DIR}/project/cmake_spec_template")

set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE
${CMAKE_CURRENT_SOURCE_DIR}/project/glite-ce-blahp.post)
file(READ ${CPACK_RPM_POST_INSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_POSTINSTALL)
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
${CMAKE_CURRENT_SOURCE_DIR}/project/glite-ce-blahp.preun)
file(READ ${CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE} CPACK_RPM_SPEC_PREUNINSTALL)

set(CPACK_SOURCE_IGNORE_FILES
"Makefile;CMakeCache.txt;/RPM/;/autom4te.cache/;/CMakeFiles/;/build/;/\\\\.git/;/\\\\.deps/;\\\\.tar\\\\.gz$;\\\\.o$;\\\\.rpm$;\\\\.deb$;${CPACK_SOURCE_IGNORE_FILES}")

add_subdirectory(src build)
add_subdirectory(config)
add_subdirectory(doc)

include(CPack)
include(UseRPMTools.cmake)

if(RPMTools_FOUND)
RPMTools_ADD_RPM_TARGETS(${CMAKE_PROJECT_NAME}
"${CMAKE_CURRENT_SOURCE_DIR}/project/BLAH.spec.in")
endif(RPMTools_FOUND)

install(FILES LICENSE
DESTINATION share/doc/${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION})
176 changes: 176 additions & 0 deletions UseRPMTools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#
# - Find tools needed for building RPM Packages
# on Linux systems and defines macro that helps to
# build source or binary RPM, the MACRO assumes
# CMake 2.4.x which includes CPack support.
# CPack is used to build tar.gz source tarball
# which may be used by a custom user-made spec file.
#
# - Define RPMTools_ADD_RPM_TARGETS which defines
# two (top-level) CUSTOM targets for building
# source and binary RPMs
#
# Those CMake macros are provided by the TSP Developer Team
# https://savannah.nongnu.org/projects/tsp
#

IF (WIN32)
MESSAGE(STATUS "RPM tools not available on Win32 systems")
ENDIF(WIN32)

IF (UNIX)
# Look for RPM builder executable
FIND_PROGRAM(RPMTools_RPMBUILD_EXECUTABLE
NAMES rpmbuild
PATHS "/usr/bin;/usr/lib/rpm"
PATH_SUFFIXES bin
DOC "The RPM builder tool")

IF (RPMTools_RPMBUILD_EXECUTABLE)
MESSAGE(STATUS "Looking for RPMTools... - found rpmuild is ${RPMTools_RPMBUILD_EXECUTABLE}")
SET(RPMTools_RPMBUILD_FOUND "YES")
GET_FILENAME_COMPONENT(RPMTools_BINARY_DIRS ${RPMTools_RPMBUILD_EXECUTABLE} PATH)
ELSE (RPMTools_RPMBUILD_EXECUTABLE)
SET(RPMTools_RPMBUILD_FOUND "NO")
MESSAGE(STATUS "Looking for RPMTools... - rpmbuild NOT FOUND")
ENDIF (RPMTools_RPMBUILD_EXECUTABLE)

# Detect if CPack was included or not
IF (NOT DEFINED "CPACK_PACKAGE_NAME")
MESSAGE(FATAL_ERROR "CPack was not included, you should include CPack before Using RPMTools")
ENDIF (NOT DEFINED "CPACK_PACKAGE_NAME")

IF (RPMTools_RPMBUILD_FOUND)
SET(RPMTools_FOUND TRUE)
#
# - first arg (ARGV0) is RPM name
# - second arg (ARGV1) is the RPM spec file path [optional]
# - third arg (ARGV2) is the RPM ROOT DIRECTORY used to build RPMs [optional]
#
MACRO(RPMTools_ADD_RPM_TARGETS RPMNAME)

#
# If no spec file is provided create a minimal one
#
IF ("${ARGV1}" STREQUAL "")
SET(SPECFILE_PATH "${CMAKE_BINARY_DIR}/${RPMNAME}.spec")
ELSE ("${ARGV1}" STREQUAL "")
SET(SPECFILE_PATH "${ARGV1}")
ENDIF("${ARGV1}" STREQUAL "")

# Verify whether if RPM_ROOTDIR was provided or not
IF("${ARGV2}" STREQUAL "")
SET(RPM_ROOTDIR ${CMAKE_BINARY_DIR}/RPM)
ELSE ("${ARGV2}" STREQUAL "")
SET(RPM_ROOTDIR "${ARGV2}")
ENDIF("${ARGV2}" STREQUAL "")
MESSAGE(STATUS "RPMTools:: Using RPM_ROOTDIR=${RPM_ROOTDIR}")

# Prepare RPM build tree
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR})
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/tmp)
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/BUILD)
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/RPMS)
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SOURCES)
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SPECS)
FILE(MAKE_DIRECTORY ${RPM_ROOTDIR}/SRPMS)

#
# We check whether if the provided spec file is
# to be configure or not.
#
IF ("${ARGV1}" STREQUAL "")
SET(SPECFILE_PATH "${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec")
SET(SPECFILE_NAME "${RPMNAME}.spec")
MESSAGE(STATUS "No Spec file given generate a minimal one --> ${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec")
FILE(WRITE ${RPM_ROOTDIR}/SPECS/${RPMNAME}.spec
"# -*- rpm-spec -*-
Summary: ${RPMNAME}
Name: ${RPMNAME}
Version: ${PACKAGE_VERSION}
Release: 1
License: Unknown
Group: Unknown
Source: ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: cmake
%define prefix /opt/${RPMNAME}-%{version}
%define rpmprefix $RPM_BUILD_ROOT%{prefix}
%define srcdirname %{name}-%{version}-Source
%description
${RPMNAME} : No description for now
%prep
%setup -q -n %{srcdirname}
%build
cd ..
rm -rf build_tree
mkdir build_tree
cd build_tree
cmake -DCMAKE_INSTALL_PREFIX=%{rpmprefix} ../%{srcdirname}
make
%install
cd ../build_tree
make install
%clean
rm -rf %{srcdirname}
rm -rf build_tree
%files
%defattr(-,root,root,-)
%dir %{prefix}
%{prefix}/*
%changelog
* Wed Feb 28 2007 Erk <[email protected]>
Generated by CMake UseRPMTools macros"
)

ELSE ("${ARGV1}" STREQUAL "")
SET(SPECFILE_PATH "${ARGV1}")

GET_FILENAME_COMPONENT(SPECFILE_EXT ${SPECFILE_PATH} EXT)
IF ("${SPECFILE_EXT}" STREQUAL ".spec")
# This is a 'ready-to-use' spec file which does not need to be CONFIGURED
GET_FILENAME_COMPONENT(SPECFILE_NAME ${SPECFILE_PATH} NAME)
MESSAGE(STATUS "Simple copy spec file <${SPECFILE_PATH}> --> <${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}>")
CONFIGURE_FILE(
${SPECFILE_PATH}
${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
COPYONLY)
ELSE ("${SPECFILE_EXT}" STREQUAL ".spec")
# This is a to-be-configured spec file
GET_FILENAME_COMPONENT(SPECFILE_NAME ${SPECFILE_PATH} NAME_WE)
SET(SPECFILE_NAME "${SPECFILE_NAME}.spec")
MESSAGE(STATUS "Configuring spec file <${SPECFILE_PATH}> --> <${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}>")
CONFIGURE_FILE(
${SPECFILE_PATH}
${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
@ONLY)
ENDIF ("${SPECFILE_EXT}" STREQUAL ".spec")
ENDIF("${ARGV1}" STREQUAL "")

ADD_CUSTOM_TARGET(${RPMNAME}_srpm
COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz ${RPM_ROOTDIR}/SOURCES
COMMAND ${RPMTools_RPMBUILD_EXECUTABLE} -bs --define=\"_topdir ${RPM_ROOTDIR}\" --buildroot=${RPM_ROOTDIR}/tmp ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
)

ADD_CUSTOM_TARGET(${RPMNAME}_rpm
COMMAND cpack -G TGZ --config CPackSourceConfig.cmake
COMMAND ${CMAKE_COMMAND} -E copy ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz ${RPM_ROOTDIR}/SOURCES
COMMAND ${RPMTools_RPMBUILD_EXECUTABLE} -bb --define=\"_topdir ${RPM_ROOTDIR}\" --buildroot=${RPM_ROOTDIR}/tmp ${RPM_ROOTDIR}/SPECS/${SPECFILE_NAME}
)
ENDMACRO(RPMTools_ADD_RPM_TARGETS)

ELSE (RPMTools_RPMBUILD_FOUND)
SET(RPMTools FALSE)
ENDIF (RPMTools_RPMBUILD_FOUND)

ENDIF (UNIX)

124 changes: 124 additions & 0 deletions project/BLAH.spec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# -*- rpm-spec -*-
Summary: @CPACK_RPM_PACKAGE_SUMMARY@
Name: @CPACK_RPM_PACKAGE_NAME@@CPACK_RPM_PACKAGE_COMPONENT_PART_NAME@
Version: @CPACK_RPM_PACKAGE_VERSION@
Release: @CPACK_RPM_PACKAGE_RELEASE@
License: @CPACK_RPM_PACKAGE_LICENSE@
Group: @CPACK_RPM_PACKAGE_GROUP@
Vendor: @CPACK_RPM_PACKAGE_VENDOR@
Source: @CMAKE_PROJECT_NAME@-@[email protected]
BuildRequires: cmake


%define srcdirname %{name}-%{version}-Source


%description
@CPACK_PACKAGE_DESCRIPTION@

# This is a shortcutted spec file generated by CMake RPM generator
# we skip _install step because CPack does that for us.
# We do only save CPack installed tree in _prepr
# and then restore it in build.
%prep
%setup -q -n %{srcdirname}

%build
cmake .
make

%install
make install DESTDIR=%{buildroot}

%clean
rm -rf %{srcdirname}
rm -rf %{buildroot}/*

%post
@CPACK_RPM_SPEC_POSTINSTALL@

%postun
@CPACK_RPM_SPEC_POSTUNINSTALL@

%pre
@CPACK_RPM_SPEC_PREINSTALL@

%preun
@CPACK_RPM_SPEC_PREUNINSTALL@

%files
%defattr(-,root,root,-)
%dir "/etc/rc.d/init.d"
%dir "/usr/share/doc/@CMAKE_PROJECT_NAME@-@CPACK_PACKAGE_VERSION@"
"/usr/share/doc/@CMAKE_PROJECT_NAME@-@CPACK_PACKAGE_VERSION@/LICENSE"
"/usr/man/man1/blahpd_daemon.1*"
"/usr/man/man1/blah_job_registry_add.1*"
"/usr/man/man1/blah_check_config.1*"
"/usr/man/man1/blah_job_registry_dump.1*"
"/usr/man/man1/blahpd.1*"
"/usr/man/man1/blah_job_registry_scan_by_subject.1*"
"/usr/man/man1/blah_job_registry_lkup.1*"
"/usr/sbin/blahpd_daemon"
"/usr/sbin/blah_check_config"
"/usr/sbin/blah_job_registry_dump"
"/usr/sbin/blah_job_registry_add"
"/usr/sbin/blah_job_registry_purge"
"/usr/sbin/blah_job_registry_scan_by_subject"
"/usr/sbin/blah_job_registry_lkup"
"/usr/sbin/glite-ce-check-blparser"
"/usr/libexec/pbs_submit.sh"
"/usr/libexec/BUpdaterLSF"
"/usr/libexec/pbs_cancel.sh"
"/usr/libexec/condor_submit.sh"
"/usr/libexec/sge_filestaging"
"/usr/libexec/condor_cancel.sh"
"/usr/libexec/slurm_status.sh"
"/usr/libexec/BPRserver"
"/usr/libexec/sge_local_submit_attributes.sh"
"/usr/libexec/lsf_hold.sh"
"/usr/libexec/condor_resume.sh"
"/usr/libexec/BUpdaterSGE"
"/usr/libexec/blah_load_config.sh"
"/usr/libexec/lsf_resume.sh"
"/usr/libexec/sge_status.sh"
"/usr/libexec/BPRclient"
"/usr/libexec/lsf_submit.sh"
"/usr/libexec/lsf_cancel.sh"
"/usr/libexec/BNotifier"
"/usr/libexec/blparser_master"
"/usr/libexec/sge_submit.sh"
"/usr/libexec/BUpdaterSLURM"
"/usr/libexec/lsf_status.sh"
"/usr/libexec/sge_hold.sh"
"/usr/libexec/sge_helper"
"/usr/libexec/BLParserPBS"
"/usr/libexec/pbs_hold.sh"
"/usr/libexec/pbs_status.sh"
"/usr/libexec/slurm_submit.sh"
"/usr/libexec/sge_cancel.sh"
"/usr/libexec/BLClient"
"/usr/libexec/sge_resume.sh"
"/usr/libexec/blah_common_submit_functions.sh"
"/usr/libexec/condor_status.sh"
"/usr/libexec/pbs_resume.sh"
"/usr/libexec/runcmd.pl.template"
"/usr/libexec/BUpdaterCondor"
"/usr/libexec/BLParserLSF"
"/usr/libexec/condor_hold.sh"
"/usr/libexec/slurm_cancel.sh"
"/usr/libexec/slurm_hold.sh"
"/usr/libexec/slurm_resume.sh"
"/usr/libexec/BUpdaterPBS"
"/usr/bin/blahpd"
"/etc/rc.d/init.d/glite-ce-blah-parser"

%config "/etc/blah.config.template"
%config "/etc/blparser.conf.template"



%changelog
* Fri Dec 28 2012 prelz <[email protected]>
Attempt to build a spec template that can work with both the CPack
RPM generator and UseRPMTools.cmake
@CPACK_RPM_SPEC_CHANGELOG@

0 comments on commit b5179a0

Please sign in to comment.