[CMake] RPM CPack generator, was: How to request features?

Eric Noulard eric.noulard at gmail.com
Mon Aug 6 12:31:32 EDT 2007


2007/8/6, Alexander Neundorf <a.neundorf-work at gmx.net>:
>
> Yes, it seems so. The one for the source RPM would be a full regular spec file
> as far as I understand.

Yes.
I attached a example of such a generated file: cmake.spec

> The one for the binary would have to be quite special.
> How does rpmbuild do the packaging ?
> Does it compress the installed tree or does it catch the install commands and
> record this way what is installed ?

To be fully honest I wasn't aware of what rpmbuild does before you ask :))
Now I'm pretty sure it only
 compress the install tree
+ content checking
  for verifying if the files described in the spec file match the one
  he found in the install tree.
+ binary dependencies add-on

>
> If it compresses the installed tree, then it should be possible to create such
> a spec file, which doesn't actually build the project again and which also
> doesn't execute make install again, but which "only" compresses the install
> tree. If you have a look in ${CMAKE_BUILD_DIR}/_CPack_Packages/, you will
> notice there are install tree for every package generator. Such an install
> tree will also be generated if we add a RPM generator. Can you tweak the spec
> file so that it just compresses this tree ?

Yes  and you were right.
Find attached cmake_fast.spec which should correspond to your needs.
As you'll see all
%prep does nothing at all

%build and %install may do nothing
I just did "simulate" the CPack behavior you described with the commented
lines. (.spec files sections are just shell scripts which may use
predefined variables)

%build
#mkdir -p /LOCAL/ERIC/tools/CMake/build_CMake/_CPack_Packages/RPM

%install
#cd /LOCAL/ERIC/tools/CMake/build_CMake
#make DESTDIR=/LOCAL/ERIC/tools/CMake/build_CMake/_CPack_Packages/RPM install

If cpack -G RPM did already populate the _CPack_Packages/RPM
there is nothing to do in %build and  %install steps.

> Can you try to get this working manually ?

once you have the cmake_fast.spec generated you should run:

rpmbuild -bb --define="_topdir
/LOCAL/ERIC/tools/CMake/build_CMake/RPM"
--buildroot=/LOCAL/ERIC/tools/CMake/build_CMake/_CPack_Packages/RPM
/LOCAL/ERIC/tools/CMake/build_CMake/RPM/SPECS/cmake_fast.spec

I leave the PATH untouched.
You may replace:
/LOCAL/ERIC/tools/CMake/build_CMake with CMAKE_BINARY_DIR

> If this or the step above works, I'd like to add this as a generator in CPack
> (for more see below).

Ok nice to have for some of us :))

> > And please don't take this question as a pure critic of
> > the work you and/or other have done.
> > I'm just trying to understand the pro/cons of the approach
> > and your point of view regarding what should be
> > implemented in CMake C++ source code and
> > what should implemented as a CMake macro.
>
> Since two weeks or so CPack can also execute cmake scripts, this is now partly
> used in the ZIP and Debian generators. They use it "only" to set up variables
> and find stuff. It could also be used to call execute_process() or
> file(MAKE_DIRECTORY ...) etc. You can't use ADD_CUSTOM_COMMAND() or
> ADD_CUSTOM_TARGET() there.
>
> We could do the following: I add a CPackRPMGenerator.cxx which executes a
> cmake script (something like Modules/CPackRPM.cmake), and you can put most of
> the logic in that script file.

I find it OK, but note that you may well create a CPackGenericGenerator.cxx
and implements CPackRPM.cmake as a "simple" cmake script.
I'll propose some idea just for that afterwards.
Nevertheless you may well do it with a specific "CPackRPMGenerator.cxx"
if you want to get it fast or if you find my idea to too much for the
current needs :))
I won't be ashamed :==)

I attach my current UseRPMTools.cmake which now defines 3 targets:

<package>_srpm        --> source RPM
<package>_rpm         --> binary RPM "as before"
<package>_rpm_fast  --> binary RPM directly from current build tree as you asked

The <package>_rpm_fast part may be taken from the file to create
a CPackRPM.cmake.

> In CMake it is currently possible e.g. to add languages without modifying the
> C++ sources. CPack needs some work to get to such a stage where you can add
> package generators by just modifying some scripts.

I think we may begin with RPM packager if you want.
Let's begin with stating what should be the minimal content of a

CPack<GeneratorName>Generator.cmake

in order to able to easily add a new packager.
here comes a draft specification:

1) the file should be named CPack<GeneratorName>Generator.cmake
   e.g. CPackRPMGenerator.cmake
   this way cpack may scan such file name in order to display them
   when running cpakc --help

2) Those files MUST define the following variables

    CPACK_GENERATOR_NAME --> the name of the GENERATOR
    e.g. SET(CPACK_GENERATOR_NAME "RPM")

    CPACK_RPM_OK will be set after INCLUDing(CPackRPMGenerator.cmake)
    such that cpack will know if the generator may be used on the current
    platform or not.

    then afterwards
   CPACK_RPM_TYPE --> the type which may be source, binary, both
    e.g. SET(CPACK_RPM_TYPE "binary")
    whereas
          SET(CPACK_SRPM_TYPE "source")
    and
          SET(CPACK_ZIP_TYPE "both")
          or may be
          SET(CPACK_ZIP_TYPE "binary;source")

   then the file file should define a macro
   CPACK_RPM_EXECUTE
   which may be called to build the package.
   with some arguments
      * input: DIR_TOBE_PACKAGED your _CPack_Packages/
      * output: PACKAGES the varname used to store the
        produced package(s) files.
      * error:  ERROR the varname used to store eventual packaging error.

For some cpack generator kind one may define the value of
CPACK_<GeneratorName>_TEMPLATE_FILE
which should be used by the generator if defined by the user.
For example I may
SET(CPACK_RPM_TEMPLATE_FILE "my_customized_spec_file.spec")

And finally it would be useful if we had access to CMAKE_BINARY_DIR
and CMAKE_SOURCE_DIR value from within the
CPack<GeneratorName>Generator.cmake file.

-- 
Erk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake.spec
Type: application/octet-stream
Size: 824 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20070806/39b9e1ec/cmake.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake_fast.spec
Type: application/octet-stream
Size: 663 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20070806/39b9e1ec/cmake_fast.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: UseRPMTools.cmake
Type: application/octet-stream
Size: 6886 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20070806/39b9e1ec/UseRPMTools.obj


More information about the CMake mailing list