#1006 Update CMake guidelines
Merged 2 years ago by james. Opened 2 years ago by ignatenkobrain.
ignatenkobrain/packaging-committee cmake-new  into  master

@@ -3,18 +3,17 @@ 

  * xref:Alternatives.adoc[Alternatives]

  * xref:AppData.adoc[AppData]

  * xref:AutoProvidesAndRequiresFiltering.adoc[Dependency Filtering]

- * xref:CMake.adoc[CMake]

  * xref:Conflicts.adoc[Conflicts]

  * xref:CryptoPolicies.adoc[Crypto Policies]

  * xref:Debuginfo.adoc[Debuginfo]

  * xref:DefaultServices.adoc[Default Services]

+ * xref:vpath.adoc[Defining source and build directories]

  * xref:deprecating-packages.adoc[Deprecating Packages]

  * xref:Directory_Replacement.adoc[Directory Replacement]

  * xref:DistTag.adoc[Dist Tag]

  * xref:Initial_Service_Setup.adoc[Initial Service Setup]

  * xref:Langpacks.adoc[Language Packs]

  * xref:LicensingGuidelines.adoc[Licensing]

- * xref:Meson.adoc[Meson]

  * xref:Naming.adoc[Naming]

  * xref:PatchUpstreamStatus.adoc[Patch Status]

  * xref:Per-Product_Configuration.adoc[Per-Product Configuration]
@@ -34,6 +33,10 @@ 

  * xref:WeakDependencies.adoc[Weak Dependencies]

  * xref:what-can-be-packaged.adoc[What Can Be Packaged]

  

+ * Build Systems

+ ** xref:CMake.adoc[CMake]

+ ** xref:Meson.adoc[Meson]

+ 

  * Programming Languages

  ** xref:Ada.adoc[Ada]

  ** xref:C_and_C++.adoc[C and {cpp}]

@@ -1,30 +1,61 @@ 

- = Guidelines for CMake

+ :last-reviewed: 2020-07-18

  

- This document provides CMake best-practices for generating Fedora RPMS using CMake

+ = CMake Packaging Guidelines

+ :toc:

  

- == RPM Macros

+ This document provides best practices for the usage of https://cmake.org/[the CMake build system] in Fedora packages.

  

- If CMake is installed, see `+/usr/lib/rpm/macros.d/macros.cmake+`.

+ == Build Dependencies

  

- If kde-filesystem is installed, see `+/usr/lib/rpm/macros.d/macros.kde4+`

+ You *MUST* add following BuildRequires:

  

- == Specfile Usage

+ ....

+ BuildRequires: cmake

+ ....

+ 

+ == Available Macros

+ 

+ You will generally make use of these in your specs:

+ 

+ `+%cmake+`::

+   Defines CFLAGS, LDFLAGS, etc. and calls `+%__cmake+` with appropriate parameters (`+-DCMAKE_INSTALL_PREFIX:PATH=/usr+` and such). You can pass `+-Doption=value+` to this macro in order to set options for the buildsystem.

+ `+%cmake_build+`::

+   Builds the project (using `+%__cmake --build+`).

+ `+%cmake_install+`::

+   Installs the built project (using `+%__cmake --install+`).

+ `+%ctest+`::

+   Runs the tests that are defined with `+add_test()+` in project (using `+%__ctest+`).

+ 

+ When packaging KDE software, you most likely would replace `+%cmake+` with `+%cmake_kf5+` that defines multiple KDE-related variables (shipped in `+kf5+` package).

+ 

+ It is rarely necessary (but permissible) to use or alter these:

+ 

+ `+%__cmake+`::

+   The path to the cmake executable.

+ `+%__ctest+`::

+   The path to the ctest executable.

+ `+%__cmake_in_source_build+`::

+   Controls whether builds are done in-source (when defined) or out-of-source (when undefined).

+   See the xref:vpath.adoc[Defining source and build directories] for more information.

+ 

+ == Example usage in the spec file

  

  ....

  %build

- %cmake .

- %make_build

- 

+ %cmake

+ %cmake_build

  

  %install

- %make_install

+ %cmake_install

  

  %check

- ctest -V %{?_smp_mflags}

+ %ctest

  ....

  

  == Notes

  

+ NOTE: Since Fedora 33, `+%__cmake_in_source_build+` is not defined so if you want to have consistent behavior across different releases, make sure to `+%define+` or `+%undefine+` it accordingly.

+ 

  *NOTE*: `+-DCMAKE_SKIP_RPATH:BOOL=ON+`.

  With recent cmake-2.4, it should not be used.

  This CMake version should handle RPATHs issues correctly (set them in build-dir, remove them during installation).
@@ -37,5 +68,5 @@ 

  

  *NOTE*: CMake has good documentation in two places:

  

- * https://www.cmake.org/documentation/

+ * https://cmake.org/documentation/

  * https://gitlab.kitware.com/cmake/community/wikis/Home

@@ -16,23 +16,22 @@ 

  You will generally make use of these in your specs:

  

  `+%meson+`::

-   Defines CFLAGS, LDFLAGS, etc. and calls %__meson with appropriate parameters (`+--libdir=%{_libdir}+` and such). You can pass `+-Doption=value+` to this macro in order to set options for the buildsystem.

+   Defines CFLAGS, LDFLAGS, etc. and calls `+%__meson+` with appropriate parameters (`+--libdir=%{_libdir}+` and such).

+   You can pass `+-Doption=value+` to this macro in order to set options for the buildsystem.

  `+%meson_build+`::

-   An alias for `+%ninja_build -C %{_vpath_builddir}+`

+   An alias for `+%ninja_build -C %{_vpath_builddir}+`.

  `+%meson_install+`::

-   An alias for `+%ninja_install -C %{_vpath_builddir}+`

+   An alias for `+%ninja_install -C %{_vpath_builddir}+`.

  `+%meson_test+`::

-   An alias for `+%ninja_test -C %{_vpath_builddir}+`

+   An alias for `+%ninja_test -C %{_vpath_builddir}+`.

  

  It is rarely necessary (but permissible) to use or alter these:

  

- `+%_vpath_srcdir+`::

-   Path (relative to the RPM build directory) where the sources to be built are located (default: `+.+`)

- `+%_vpath_builddir+`::

-   Path (relative to the RPM build directory) where the built objects are located (default: `+%{_target_platform}+`)

  `+%__meson+`::

    The path to the meson executable

  

+ Also see xref:vpath.adoc[Defining source and build directories].

+ 

  == Example RPM spec file

  

  ....

@@ -0,0 +1,13 @@ 

+ = Defining source and build directories

+ 

+ Build systems that support defining source/build directories via RPM macros:

+ 

+ * xref:CMake.adoc[CMake]

+ * xref:Meson.adoc[Meson]

+ 

+ Macros:

+ 

+ `+%_vpath_srcdir+`::

+   Path (relative to the RPM build directory) where the sources to be built are located (default: `+.+`).

+ `+%_vpath_builddir+`::

+   Path (relative to the RPM build directory) where the built objects are located (default: `+%{_target_platform}+`).

Metadata Update from @ignatenkobrain:
- Pull-request tagged with: meeting

2 years ago

We talked about this in this weeks meeting (https://meetbot-raw.fedoraproject.org/fedora-meeting-1/2020-07-23/fpc.2020-07-23-16.01.txt):

Commit 027d155 fixes this pull-request

Pull-Request has been merged by james

2 years ago

Pull-Request has been merged by james

2 years ago