[CMake] CPack: Detecting if to build DEB/RPM packages

Eric Noulard eric.noulard at gmail.com
Thu Jul 22 03:25:58 EDT 2010


2010/7/22 Freddie Witherden <freddie at witherden.org>:
> Hi,
>
> I use CPack in my project to build binary packages as an alternative to `make
> install`.  However, I am interested in getting my project to automatically
> detect which packages to build.
>
> Currently I have TGZ set and then require the user to pass the appropriate
> parameter to `cmake` (such as -DCPACK_BINARY_DEB:BOOL=on) to have deb/rpm
> packages made.
>
> I wish to know how I can have CMake/CPack determine if it is possible to build
> an RPM or DEB package on the system (so if all the required utilities are
> installed) and if so to go ahead and package them.

I did wrote a small CMake scripts which may help you for this.
add
include(SystemSpecificInformations)
to your CMakeLists.txt

then
SPECIFIC_SYSTEM_PREFERED_CPACK_GENERATOR
should contain the appropriate name of the CPack generator to be used
on the host.

Note however that the current script does not check whether if appropriate tool
(dpkg, rpmbuild, NSIS,...) are installed but basically associate an
host type with
a "prefered" CPACK_GENERATOR.

Windows --> NSIS
Debian --> DEB
Ubuntu --> DEB
Fedora --> RPM
SuSE --> RPM
other linux --> TGZ

> This would simplify things for people who checkout the project as they just
> need to type `make package` and can be sure of the appropriate package being
> built.
>
> However I am unsure how to reliably go about the detection process.  (Asking
> CMake to produce an RPM package on my Debian Squeeze system only fails when
> one tries to make the package -- after `cmake` has run.)

Yes and normally it fails by saying that you need to have "rpmbuild"
installed right?

something like:
CMake Error at /usr/share/cmake-2.8/Modules/CPackRPM.cmake:195 (MESSAGE):
  RPM package requires rpmbuild executable

Now I'm not sure we may do anything better, because you may effectively
want to build RPM on a debian host, even if this is not the 'native
package format'.
In fact on your Debian-based system if you "aptitude install rpm" you'll be able
to build RPM just fine.

I personnally usually build both DEB and RPM on my debian host.
This way I may easily build RPM for my collegue that do not want to
"compile themself".

That said you are right, in your case it would be interesting to build
the "prefered" package
automatically. May be you can file a feature request on the bug
tracker and we may submit
a enhance version of my "SystemSpecificInformations.cmake" which may
be integrated in CMake upstream.

What do other listeners think about that?

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SystemSpecificInformations.cmake
Type: application/octet-stream
Size: 4821 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100722/04976a73/attachment-0001.obj>


More information about the CMake mailing list