[CMake] Generating archives and binaries with different PREFIX settings using CPack

Eric Noulard eric.noulard at gmail.com
Mon Apr 25 16:31:38 EDT 2011


2011/4/25 Clifford Yapp <cliffyapp at gmail.com>:
> I'm trying to generate both source tarballs and binary packages using
> CPack, and I'm at something of a loss as to how to achieve the
> following:
>
> I want the binaries (RPM, DEB, etc.) to respect the
> CMAKE_INSTALL_PREFIX.  I want the source tarballs to expand into their
> directory like a standard tarball, without any prefix directories.  As
> far as I can tell, both source and binary packaging structure is
> governed by CPACK_PACKAGING_INSTALL_PREFIX - am I missing something
> that will let me specify one setting for binary archives and another
> for source archives?
Nope your are not missing anything beside the fact that
there is nothing like a "source generator" known to cpack!!! :-(.

All generators do include a "CPack Config" file in order to configure
their behavior
so

package ==>
   cpack --config ./CPackConfig.cmake

package_source ==>
   cpack --config ./CPackSourceConfig.cmake

include(CPack) is "generating" this two config files using various
CPACK_xxx var values
but there is no such thing as a "source generator".

e.g. CPack generator used for source or binary is "the same generator"
using a different config file.

> (Ideal would be per-generator settings, so I
> could generate a binary tar.gz bundle that would expand locally as
> well, but the really important one is source tarballs.)

per-generator settings is doable using CPack project config file:
http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#Overall_usage_.28common_to_all_generators.29

inside the CPack project file you should be able to guess whether if
CPack is running for a "SOURCE" package because the
"CPACK_SOURCE_PACKAGE_FILE_NAME"
is defined which shouldn't be  the case when packaging for "binaries".

you may try with a CPack project file which could look like:

if(CPACK_GENERATOR MATCHES "ZIP")
   if (CPACK_SOURCE_PACKAGE_FILE_NAME)
     set(CPACK_PACKAGING_INSTALL_PREFIX "/SRC-ZIPprefix")
   else ()
     set(CPACK_PACKAGING_INSTALL_PREFIX "/ZIPprefix")
   endif()
endif(CPACK_GENERATOR MATCHES "ZIP")

if(CPACK_GENERATOR MATCHES "RPM")
   set(CPACK_PACKAGING_INSTALL_PREFIX "/RPMprefix")
endif(CPACK_GENERATOR MATCHES "RPM")

if(CPACK_GENERATOR MATCHES "DEB")
   set(CPACK_PACKAGING_INSTALL_PREFIX "/DEBprefix")
endif(CPACK_GENERATOR MATCHES "DEB")



if the toplevel dir you find in archive generators (TGZ, TBZ2, ZIP, ...)
is bothering you you can suppress it using:
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)

you can set this conditionnally in the CPack project file as well.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list