[CMake] Documentation in RPM Package

Paul Londino londinop at gmail.com
Thu Dec 22 21:14:02 EST 2016


Hi Domen,

Thanks for the quick reply.  I've spent a bit more time digging into this.

What I am specifically trying to do is use the built-in %doc mechanism
of RPM to automatically package the documentation. Using rpmbuild, if
you specify a relative path (no leading /) with the %doc attribute, it
will automatically package the documentation in a subfolder of
/usr/share/doc with the name and version of the package. This path is
relative to the BUILD directory (after extraction from the SOURCE
directory). So for example a file "readme.txt" for a package "foo"
version "2.5.1" residing in the BUILD/foo/directory and specified as
"%doc readme.txt" will get automatically copied to a
/usr/share/foo-2.5.1/readme.txt via the following instructions:

 cd /home/plondino/code/cpp/foo/cmake_build/_CPack_Packages/Linux/RPM/BUILD
+ DOCDIR=/home/plondino/code/cpp/foo/cmake_build/_CPack_Packages/Linux/RPM/foo-2.20.5.16916-1.el7.x86_64/libraries/usr/share/doc/foo-devel.rpm-2.20.5.16916
+ export DOCDIR
+ /usr/bin/mkdir -p
/home/plondino/code/cpp/foo/cmake_build/_CPack_Packages/Linux/RPM/foo-2.20.5.16916-1.el7.x86_64/libraries/usr/share/doc/foo-devel.rpm-2.20.5.16916
+ cp -pr readme.txt
/home/plondino/code/cpp/foo/cmake_build/_CPack_Packages/Linux/RPM/foo-2.20.5.16916-1.el7.x86_64/libraries/usr/share/doc/foo-devel.rpm-2.20.5.16916

I am not sure if this behavior is hard-coded or configurable somewhere
in the RPM build process.

So actually my current CMake build which installs these files to the
BUILDROOT directory will not work as is. If given an absolute path
such as /usr/share/doc/readme.txt, the RPM build process will look for
it under BUILDROOT and not BUILD, and it will not automatically create
the package subdirectory; instead it will just use the exact path and
mark it as documentation.

It believe it would be useful to perform this same kind of
documentation installation in CPack, since it seems like a standard
place for documentation in an RPM-based distribution. Is there an easy
way to do this using the existing CMake infrastructure? A custom
installation for documentation that mimics the above structure springs
to mind, but it would need to be specific to the RPM packaging only,
other package generators would probably not want a similar structure.

Any ideas about how to achieve this would be helpful. Please let me
know if there is any other data or testing I can provide that would
help.

Thanks,
Paul

On Tue, Dec 20, 2016 at 6:52 PM, Domen Vrankar <domen.vrankar at gmail.com> wrote:
> 2016-12-20 21:53 GMT+01:00 Paul Londino <londinop at gmail.com>:
>>
>> Hello,
>>
>> I am trying to create an RPM package using CPack. I am having trouble
>> packaging the documentation. There is a custom target that generates
>> HTML using DoxyGen (in a folder called html), and this gets installed
>> to /usr/doc/share during the packaging process. However, this
>> generates 12,000+ files which are all added individually to the .spec
>> file.
>>
>> What I would like to do is just add the whole doc directory to the RPM
>> package using the %doc attribute so the RPM correctly installs this in
>> the package-named subfolder of /usr/share/doc and marks it as
>> documentation. I experimented with the
>> CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST variable but this doesn't seem to
>> work on a wildcard basis and excluding all 12,000 generated files by
>> hand does not seem practical. Also, I was able to generate the %doc
>> attribute using CPACK_RPM_USER_FILELIST, but I believe in order to
>> have the auto-generated doc dir, it needs to be a relative path
>> instead of absolute, which I had problems setting using the CMAKE
>> variable (this could be more an RPM issue than a CMAKE one).
>>
>> Any ideas in the best way to achieve what I'm trying to do? I could
>> try using a custom .spec file but there is a lot of value in the
>> automatically generated one from the CMake, so I would prefer to use
>> that if possible.
>
>
> I don't believe that CPack/RPM can currently do what you want.
>
> CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST is not intended to be used for removing
> an entire list of files so it doesn't support wildcards - it is meant to be
> used to exclude directory paths from being tracked by rpm and deleted during
> rpm package uninstall.
>
> Why exactly do you want to remove all those files? Spec file size or
> something else?
> If you write something like this:
>
> install(FILES CMakeLists.txt DESTINATION x/maabc COMPONENT test RENAME
> manx.txt)
> install(FILES CMakeLists.txt DESTINATION x/maabc COMPONENT test RENAME
> many.txt)
>
> set(CPACK_RPM_USER_FILELIST
>   "%doc /usr/x"
>   )
>
> Where /usr is packaging install prefix (this part could be replaced with a
> variable so that it depends on for e.g. CPACK_PACKAGING_INSTALL_PREFIX or
> some other path).
>
> And then expect the generated package with (listing only files marked with
> %doc):
>
> rpm -qpld <your_rpm_package_name>
>
> You'll get both files in that subdirectory flagged with %doc and I believe
> that that's what you'd like to achieve.
>
> If for some reason you'd really like to remove those files from spec file
> you'll either have to patch your CPackRPM.cmake or write your own spec file.
> If that's the case then please explain the reasons a bit further and if it
> would be useful for others it could be added to a later CPackRPM release.
>
> Regards,
> Domen


More information about the CMake mailing list