diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-09-15 16:24:37 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-09-15 16:24:37 +0400 |
commit | bcfba49779a8deb142cc538a4e7a8027f98bbebe (patch) | |
tree | 42301a3bbb843357a4bd4d8743ddae9c1d8b55c9 | |
parent | 94ce619f8a598ea1532c8e63137f74157ac5c9ed (diff) | |
download | rspamd-bcfba49779a8deb142cc538a4e7a8027f98bbebe.tar.gz rspamd-bcfba49779a8deb142cc538a4e7a8027f98bbebe.zip |
* Prepare rspamd build infrastructure for creating rpm and deb packages
-rw-r--r-- | CMakeLists.txt | 131 | ||||
-rw-r--r-- | linux/cmake/DpkgDeb.cmake | 241 | ||||
-rw-r--r-- | linux/cmake/UseRPMTools.cmake | 176 |
3 files changed, 536 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c56520d4..5e5d697ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ SET(RSPAMD_VERSION_MINOR 3) SET(RSPAMD_VERSION_PATCH 2) SET(RSPAMD_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}") -SET(RSPAMD_MASTER_SITE_URL "http://cebka.pp.ru/hg/rspamd") +SET(RSPAMD_MASTER_SITE_URL "http://bitbucket.org/vstakhov/rspamd") SET(RSPAMD_USER "nobody") SET(RSPAMD_GROUP "nobody") @@ -42,6 +42,10 @@ INCLUDE(FindPerl) SET(CMAKE_REQUIRED_LIBRARIES m) SET(CMAKE_REQUIRED_INCLUDES sys/mman.h stdlib.h stdio.h unistd.h time.h sched.h) +IF(CMAKE_INSTALL_PREFIX) + SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +ENDIF(CMAKE_INSTALL_PREFIX) + # Platform specific routines IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -DFREEBSD") @@ -52,8 +56,13 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ENDIF(ENABLE_REDIRECTOR MATCHES "ON") IF(NOT ETC_PREFIX) SET(ETC_PREFIX /usr/local/etc) - SET(PREFIX /usr/local) ENDIF(NOT ETC_PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/local/man) + ENDIF(NOT MAN_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /usr/local) + ENDIF(NOT PREFIX) FIND_LIBRARY(LIBINTL_LIBRARY NAMES intl PATHS /lib /opt/lib /usr/lib @@ -69,8 +78,14 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") IF(NOT ETC_PREFIX) SET(ETC_PREFIX /usr/local/etc) - SET(PREFIX /usr/local) ENDIF(NOT ETC_PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/local/man) + ENDIF(NOT MAN_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /usr/local) + ENDIF(NOT PREFIX) + FIND_LIBRARY(LIBINTL_LIBRARY NAMES intl PATHS /lib /opt/lib /usr/lib @@ -85,8 +100,13 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DLINUX") IF(NOT ETC_PREFIX) SET(ETC_PREFIX /etc) - SET(PREFIX /usr) ENDIF(NOT ETC_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /usr) + ENDIF(NOT PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/share/man) + ENDIF(NOT MAN_PREFIX) LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) MESSAGE(STATUS "Configuring for Linux") @@ -96,8 +116,14 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DSOLARIS") IF(NOT ETC_PREFIX) SET(ETC_PREFIX /etc) - SET(PREFIX /opt/rspamd) ENDIF(NOT ETC_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /opt/rspamd) + ENDIF(NOT PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/share/man) + ENDIF(NOT MAN_PREFIX) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) LIST(APPEND CMAKE_REQUIRED_LIBRARIES resolv) @@ -154,7 +180,7 @@ ENDIF(ENABLE_STATIC MATCHES "ON") pkg_check_modules(GMIME2 gmime-2.0) # Try to link with gmime24 -IF(NOT GMIME2_FOUND) +IF(NOT GMIME2_FOUND OR USE_GMIME24) pkg_check_modules(GMIME24 REQUIRED gmime-2.4) SET(GMIME24 "yes") # Gmime2 @@ -173,7 +199,7 @@ IF(NOT GMIME2_FOUND) ENDIF(ENABLE_STATIC MATCHES "ON") INCLUDE_DIRECTORIES(${GMIME24_INCLUDE_DIRS}) LINK_DIRECTORIES(${GMIME24_LIBRARY_DIRS}) -ELSE(NOT GMIME2_FOUND) +ELSE(NOT GMIME2_FOUND OR USE_GMIME24) # Gmime2 FOREACH(arg ${GMIME2_CFLAGS}) SET(GMIME_CFLAGS "${GMIME_CFLAGS} ${arg}") @@ -190,7 +216,7 @@ ELSE(NOT GMIME2_FOUND) ENDIF(ENABLE_STATIC MATCHES "ON") INCLUDE_DIRECTORIES(${GMIME2_INCLUDE_DIRS}) LINK_DIRECTORIES(${GMIME2_LIBRARY_DIRS}) -ENDIF(NOT GMIME2_FOUND) +ENDIF(NOT GMIME2_FOUND OR USE_GMIME24) # Make from ; separated list normal space separated list # Glib2 @@ -442,7 +468,9 @@ IF(DEBUG_MODE MATCHES "ON") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") ENDIF(DEBUG_MODE MATCHES "ON") -SET(DESTDIR $ENV{DESTDIR}) +IF(NOT DESTDIR) + SET(DESTDIR $ENV{DESTDIR}) +ENDIF(NOT DESTDIR) ################################ SOURCES SECTION ########################### @@ -560,7 +588,7 @@ ADD_CUSTOM_COMMAND(OUTPUT src/modules.c IF(PERL_EXECUTABLE) ADD_CUSTOM_COMMAND(OUTPUT perl/Makefile DEPENDS perl/Makefile.PL - COMMAND ${PERL_EXECUTABLE} ./Makefile.PL DESTDIR=${DESTDIR} PREFIX=${CMAKE_INSTALL_PREFIX} INSTALLMAN3DIR=${CMAKE_INSTALL_PREFIX}/man/man3 + COMMAND ${PERL_EXECUTABLE} ./Makefile.PL DESTDIR=${DESTDIR} PREFIX=${PREFIX} INSTALLMAN3DIR=${MAN_PREFIX}/man3 WORKING_DIRECTORY perl) CONFIGURE_FILE(perl/Makefile.PL.in perl/Makefile.PL) ADD_CUSTOM_TARGET(perlmodule @@ -696,7 +724,7 @@ FOREACH(LUA_PLUGIN ${LUA_PLUGINS}) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/lua/${_rp})") ENDIF(NOT IS_DIRECTORY ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/lua/${_rp}) IF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/${_rp}/${LUA_PLUGIN}) - INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/lua/${_rp}) + INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION ${ETC_PREFIX}/rspamd/plugins/lua/${_rp}) ENDIF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/${_rp}/${LUA_PLUGIN}) ENDFOREACH(LUA_PLUGIN) @@ -711,7 +739,7 @@ FOREACH(LUA_CONF ${LUA_CONFIGS}) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp})") ENDIF(NOT IS_DIRECTORY ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}) IF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}/${LUA_CONF}) - INSTALL(FILES "conf/lua/${LUA_CONF}" DESTINATION ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}) + INSTALL(FILES "conf/lua/${LUA_CONF}" DESTINATION ${ETC_PREFIX}/rspamd/lua/${_rp}) ENDIF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}/${LUA_CONF}) ENDFOREACH(LUA_CONF) @@ -744,3 +772,82 @@ SET(CPACK_PACKAGE_VERSION_MAJOR ${RSPAMD_VERSION_MAJOR}) SET(CPACK_PACKAGE_VERSION_MINOR ${RSPAMD_VERSION_MINOR}) SET(CPACK_PACKAGE_VERSION_PATCH ${RSPAMD_VERSION_PATCH}) INCLUDE(CPack) + +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + INCLUDE("linux/cmake/DpkgDeb.cmake") + INCLUDE("linux/cmake/UseRPMTools.cmake") +ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + +SET(RPMNAME "rspamd") +SET(PACKAGE_NAME "rspamd") +SET(PACKAGE_RELEASE "1") +SET(PACKAGE_SECTION "mail") +SET(PACKAGE_PRIORITY "optional") +SET(PACKAGE_HOMEPAGE "http://bitbucket.org/vstakhov/rspamd") +SET(PACKAGE_MAINTAINER_NAME "vstakhov") +SET(PACKAGE_MAINTAINER_EMAIL "vsevolod@highsecure.ru") +SET(PACKAGE_DESCRIPTION_SUMMARY "rspamd - fast and modular antispam system written in C") +SET(PACKAGE_DESCRIPTION "Fast and modular antispam system written in C") +IF(GMIME24) + SET(PACKAGE_DEPENDS "libevent1, libgmime-2.4-2, liblua5.1-0, libxml-parser-perl, libterm-readkey-perl, libglib2.0-0") +ELSE(GMIME24) + SET(PACKAGE_DEPENDS "libevent1, libgmime-2.0-2, liblua5.1-0, libxml-parser-perl, libterm-readkey-perl, libglib2.0-0") +ENDIF(GMIME24) + +SET(PACKAGE_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}") + + +IF(RPMTools_FOUND) + FILE(WRITE linux/rspamd.spec +"# -*- rpm-spec -*- +Summary: ${RPMNAME} +Name: ${RPMNAME} +Version: ${PACKAGE_VERSION} +Release: ${PACKAGE_RELEASE} +License: BSD +Group: Mail +Source: ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root +BuildRequires: cmake, gmime, perl + +%define prefix /opt/${RPMNAME}-%{version} +%define rpmprefix $RPM_BUILD_ROOT%{prefix} +%define srcdirname %{name}-%{version}-Source + +%description +${RPMNAME} : Fast and modular antispam system written in C + +%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 Sep 15 2010 vstakhov <vsevolod@highsecure.ru> + Release 0.3.2 +") + RPMTools_ADD_RPM_TARGETS("rspamd" "linux/rspamd.spec") +ENDIF(RPMTools_FOUND) + +IF(DPKG_FOUND STREQUAL "YES") + ADD_DEBIAN_PACKAGE("rspamd") +ENDIF(DPKG_FOUND STREQUAL "YES")
\ No newline at end of file diff --git a/linux/cmake/DpkgDeb.cmake b/linux/cmake/DpkgDeb.cmake new file mode 100644 index 000000000..ed9115681 --- /dev/null +++ b/linux/cmake/DpkgDeb.cmake @@ -0,0 +1,241 @@ +# DpkgDeb : Create debian packages for your projects and sub projects. Written by Mehdi Rabah +# Was heavily inspired by UseDebian (Mathieu Malaterre) and UseRPMTools (TSP Team) modules + +# need /usr/bin/dpkg + +# USAGE : ADD_DEBIAN_PACKAGE ( DEB_TARGET_NAME [CONTROL_FILE] ) +# You need to set the control file either by setting these variables +# or by giving as second parameter the path to the control file you want to use +# If you choose to set the variables, you must set the mandatory variables: +# (see man 5 deb-control for more details) +# +# -- MANDATORY Variables +# Package: ${PACKAGE_NAME}. Must be a lowercase string +# Version: ${PACKAGE_VERSION}. Like 1.1.0 +# Release: ${PACKAGE_RELEASE}. A number beetween 0 and 9 +# Maintainer: ${PACKAGE_MAINTAINER_NAME} and ${PACKAGE_MAINTAINER_EMAIL}. +# Description summary: ${PACKAGE_DESCRIPTION_SUMMARY}. Project summary +# Description : ${PACKAGE_DESCRIPTION}. Warning : for now, use of special characters (>, (, ', ... ) is not allowed +# +# -- OPTIONAL Variables +# Architecture: ${DEBIAN_ARCHITECTURE}, by default i386 for intel on debian like +# Depends: ${PACKAGE_DEPENDS} +# Section: ${PACKAGE_SECTION} +# Priority: ${PACKAGE_PRIORITY} +# Essential: ${PACKAGE_ESSENTIAL} +# Source: ${PACKAGE_SOURCE} +# Pre-Depends: ${PACKAGE_PREDEPENDS} +# Recommends: ${PACKAGE_RECOMMENDS} +# Suggests: ${PACKAGE_SUGGESTS} +# Breaks: ${PACKAGE_BREAKS} +# Conflicts: ${PACKAGE_CONFLICTS} +# Replaces: ${PACKAGE_REPLACES} +# Provides: ${PACKAGE_PROVIDES} + +# TODO: Make clean does not clean the DEBIAN_DIR folder +# TODO: use objdump -p to automatically generate depedencies (cf dh_makeshlibs) + +FIND_PROGRAM(DPKG + NAMES dpkg-deb + PATHS "/usr/bin") + +IF ( DPKG ) + GET_FILENAME_COMPONENT(DPKG_PATH ${DPKG} ABSOLUTE) + MESSAGE(STATUS "Found dpkg-deb : ${DPKG_PATH}") + SET(DPKG_FOUND "YES") +ELSE ( DPKG ) + MESSAGE(STATUS "dpkg-deb NOT found. deb generation will not be available") + SET(DPKG_FOUND "NO") +ENDIF ( DPKG ) + +# Main and only command of this module. For more details, visit this webpage +# http://tldp.org/HOWTO/Debian-Binary-Package-Building-HOWTO/ +MACRO(ADD_DEBIAN_PACKAGE DEBNAME) + + SET ( CONTROL_FILE ${PROJECT_BINARY_DIR}/control_${PROJECT_NAME} ) + + # First choice for control file : user defined variables + IF ("${ARGV1}" STREQUAL "") + + # Check if the mandatory variables are here + IF(NOT PACKAGE_NAME OR NOT PACKAGE_VERSION OR NOT DEFINED PACKAGE_RELEASE OR + NOT PACKAGE_MAINTAINER_NAME OR NOT PACKAGE_MAINTAINER_EMAIL OR + NOT PACKAGE_DESCRIPTION_SUMMARY OR NOT PACKAGE_DESCRIPTION ) + message ( FATAL_ERROR "ADD_DEBIAN_PACKAGE command was not correctly configured for ${PROJECT_NAME}. See the documentation for more details" ) + ENDIF(NOT PACKAGE_NAME OR NOT PACKAGE_VERSION OR NOT DEFINED PACKAGE_RELEASE OR + NOT PACKAGE_MAINTAINER_NAME OR NOT PACKAGE_MAINTAINER_EMAIL OR + NOT PACKAGE_DESCRIPTION_SUMMARY OR NOT PACKAGE_DESCRIPTION ) + + IF(NOT DEBIAN_ARCHITECTURE) + EXECUTE_PROCESS(COMMAND "/usr/bin/dpkg" "--print-architecture" OUTPUT_VARIABLE DEBIAN_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) + ENDIF(NOT DEBIAN_ARCHITECTURE) + + # Writing the control file + # see man 5 deb-control for more details + ADD_CUSTOM_COMMAND( + OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Package: ${PACKAGE_NAME}" > ${CONTROL_FILE} + + COMMAND ${CMAKE_COMMAND} -E echo + "Version: ${PACKAGE_VERSION}" >> ${CONTROL_FILE} + + COMMAND ${CMAKE_COMMAND} -E echo + "Maintainer: ${PACKAGE_MAINTAINER_NAME}" + \"<"${PACKAGE_MAINTAINER_EMAIL}\">" >> ${CONTROL_FILE} + + COMMAND ${CMAKE_COMMAND} + ARGS -E echo "Architecture: ${DEBIAN_ARCHITECTURE}" >> ${CONTROL_FILE} + ) + + IF ( DEFINED PACKAGE_DEPENDS ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Depends: ${PACKAGE_DEPENDS}" >> ${CONTROL_FILE} + APPEND ) + ENDIF ( DEFINED PACKAGE_DEPENDS ) + + IF ( DEFINED PACKAGE_SECTION ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Section: ${PACKAGE_SECTION}" >> ${CONTROL_FILE} + APPEND ) + ENDIF ( DEFINED PACKAGE_SECTION) + IF ( DEFINED PACKAGE_HOMEPAGE ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Homepage: ${PACKAGE_HOMEPAGE}" >> ${CONTROL_FILE} + APPEND ) + ENDIF ( DEFINED PACKAGE_HOMEPAGE) + + IF ( DEFINED PACKAGE_PRIORITY ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Priority: ${PACKAGE_PRIORITY}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_PRIORITY) + + IF ( DEFINED PACKAGE_ESSENTIAL ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Essential: ${PACKAGE_ESSENTIAL}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_ESSENTIAL) + + IF ( DEFINED PACKAGE_SOURCE ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Source: ${PACKAGE_SOURCE}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_SOURCE) + + IF ( DEFINED PACKAGE_PREDEPENDS ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Pre-Depends: ${PACKAGE_PREDEPENDS}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_PREDEPENDS ) + + IF ( DEFINED PACKAGE_RECOMMENDS ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Recommends: ${PACKAGE_RECOMMENDS}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_RECOMMENDS) + + IF ( DEFINED PACKAGE_SUGGESTS ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Suggests: ${PACKAGE_SUGGESTS}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_SUGGESTS ) + + IF ( DEFINED PACKAGE_BREAKS ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Breaks: ${PACKAGE_BREAKS}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_BREAKS ) + + IF ( DEFINED PACKAGE_CONFLICTS ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Conflicts: ${PACKAGE_CONFLICTS}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_CONFLICTS ) + + IF ( DEFINED PACKAGE_REPLACES ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Replaces: ${PACKAGE_REPLACES}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_REPLACES ) + + IF ( DEFINED PACKAGE_PROVIDES ) + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Provides: ${PACKAGE_PROVIDES}" >> ${CONTROL_FILE} + APPEND) + ENDIF ( DEFINED PACKAGE_PROVIDES ) + + ADD_CUSTOM_COMMAND( OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "Description: ${PACKAGE_DESCRIPTION_SUMMARY}" >> ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + " ." >> ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + " ${PACKAGE_DESCRIPTION}" >> ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + " ." >> ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E echo + "" >> ${CONTROL_FILE} + COMMENT "Generating control file" + APPEND + ) + ELSE ("${ARGV1}" STREQUAL "") + ADD_CUSTOM_COMMAND( + OUTPUT ${CONTROL_FILE} + COMMAND ${CMAKE_COMMAND} -E copy "${ARGV1}" ${CONTROL_FILE} + COMMENT "Copying user specified control file : ${ARGV1}" + ) + ENDIF("${ARGV1}" STREQUAL "") + + # let's create a directory to call 'make install DESTDIR=...' into: + SET ( DEBIAN_DIR ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE}_${DEBIAN_ARCHITECTURE} ) + FILE ( REMOVE ${DEBIAN_DIR} ) + FILE ( MAKE_DIRECTORY ${DEBIAN_DIR} ) + FILE ( MAKE_DIRECTORY ${DEBIAN_DIR}/DEBIAN ) + + # Calling "make install DESTDIR=${DEBIAN_DIR}" + ADD_CUSTOM_TARGET(deb_destdir_install + COMMAND ${CMAKE_MAKE_PROGRAM} install CMAKE_INSTALL_PREFIX=/usr DESTDIR=${DEBIAN_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/cmake_install.cmake + COMMENT "Installing with DESTDIR = ${DEBIAN_DIR}" + ) + ADD_DEPENDENCIES(deb_destdir_install deb_destdir_preinstall) + ADD_CUSTOM_TARGET(deb_destdir_preinstall + COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=/usr -DDESTDIR=${DEBIAN_DIR} . + DEPENDS ${CMAKE_BINARY_DIR}/cmake_install.cmake + COMMENT "Configuring with DESTDIR = ${DEBIAN_DIR}" + ) + ADD_DEPENDENCIES(deb_destdir_preinstall all preinstall) + + # Calling dpkg --build + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE}_${DEBIAN_ARCHITECTURE}.deb + COMMAND ${CMAKE_COMMAND} -E copy ${CONTROL_FILE} ${DEBIAN_DIR}/DEBIAN/control + COMMAND ${DPKG_PATH} --build ${DEBIAN_DIR} + # removing control, so its (re)generated each time we need to build the package + COMMAND ${CMAKE_COMMAND} -E remove ${CONTROL_FILE} + DEPENDS ${CONTROL_FILE} + COMMENT "Generating deb package" + ) + + # the final target: + ADD_CUSTOM_TARGET(${DEBNAME}_deb + DEPENDS ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE}_${DEBIAN_ARCHITECTURE}.deb + ) + + ADD_DEPENDENCIES(${DEBNAME}_deb deb_destdir_install) + +ENDMACRO(ADD_DEBIAN_PACKAGE DEBNAME) diff --git a/linux/cmake/UseRPMTools.cmake b/linux/cmake/UseRPMTools.cmake new file mode 100644 index 000000000..74e0112ca --- /dev/null +++ b/linux/cmake/UseRPMTools.cmake @@ -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 <eric.noulard@gmail.com> + 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) + |