From Fedora Project Wiki

fp-wiki>ImportUser
(Imported from MoinMoin)
 
(Deprecate page.)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{OldGuidelinePage|CMake}}
= Guidelines for cmake =
= Guidelines for cmake =


More and more projects are moving to cmake, especially with KDE4 making the jump.  It seems like it is time to start collecting cmake best practices for generating Fedora RPMS using cmake
This document provides cmake best-practices for generating Fedora RPMS using cmake
 
 




Line 9: Line 9:
== RPM Macros ==
== RPM Macros ==


<pre>
If cmake is installed, see /usr/lib/rpm/macros.d/cmake or /etc/rpm/macros.cmake on EL6.
<!-- /etc/rpm/macros.cmake:
-->


%_cmake_lib_suffix64 -DLIB_SUFFIX=64
If kde-filesystem is installed, see /usr/lib/rpm/macros.d/macros.kde4
%__cmake %{_bindir}/cmake
 
%cmake \
CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
%__cmake \\\
%if "%{?_lib}" == "lib64" \
%{?_cmake_lib_suffix64} \\\
%endif \
-DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \\\
-DBUILD_SHARED_LIBS:BOOL=ON
</pre>




Line 35: Line 20:
%build
%build
%cmake .
%cmake .
make VERBOSE=1 %{?_smp_mflags}
%make_build




%install
%install
rm -rf $RPM_BUILD_ROOT
%make_install
make install DESTDIR=$RPM_BUILD_ROOT
 


%check
%check
ctest
ctest -V %{?_smp_mflags}
</pre>
</pre>


{{Anchor|cmakeNotes}}
{{Anchor|cmakeNotes}}
== Notes ==
== Notes ==
'''NOTE''': <code>-DCMAKE_SKIP_RPATH:BOOL=ON</code>.  With recent cmake-2.4, it should not be used. This cmake version handles RPATHs issues correctly (set them in build-dir, remove them during installation). Setting <code>CMAKE_SKIP_RPATH</code> for this version would avoid RPATHs in build-dir too. This might link binaries against system-libraries (e.g. when a previous version of the package was installed) instead of the libraries which were created by the build.
'''NOTE''': <code>-DCMAKE_SKIP_RPATH:BOOL=ON</code>.  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). Setting <code>CMAKE_SKIP_RPATH</code> for this version would avoid RPATHs in build-dir too. This might link binaries against system-libraries (e.g. when a previous version of the package was installed) instead of the libraries which were created by the build.


Nevertheless, RPATH issues might arise when cmake was used improperly. E.g. installing a target with <code>INSTALL(FILES ... RENAME ...)</code> will '''not''' strip rpaths; in this case <code>INSTALL(TARGETS ...)</code> must be used in combination with changing the <code>OUTPUT_NAME</code> property.
Nevertheless, RPATH issues might arise when cmake was used improperly. E.g. installing a target with <code>INSTALL(FILES ... RENAME ...)</code> will '''not''' strip rpaths; in this case <code>INSTALL(TARGETS ...)</code> must be used in combination with changing the <code>OUTPUT_NAME</code> property.


'''NOTE''': The proposed <code>%cmake</code> macro defines <code>-DLIB_SUFFIX=64</code> on 64bit platforms.  Not all packages handle this gracefully. The kdesvn package, for example, included cmake files taken from the KDE upstream that needed to be patched for this to work properly for all files (esp. .la files for loadable KDE modules).  You might want to see the patch included in the kdesvn .src.rpm for example changes.
'''NOTE''': cmake has good documentation in two places:
* http://www.cmake.org/documentation/
* http://www.cmake.org/Wiki/CMake
 
[[Category:Packaging guidelines]]

Latest revision as of 03:38, 20 December 2018

Warning.png
This is an old copy of a packaging guideline, preserved here in the wiki while we complete the transition to the Fedora documentation system. The current version is located at https://docs.fedoraproject.org/en-US/packaging-guidelines/CMake/. Please update your bookmarks.

Guidelines for cmake

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


RPM Macros

If cmake is installed, see /usr/lib/rpm/macros.d/cmake or /etc/rpm/macros.cmake on EL6.

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


Specfile Usage

%build
%cmake .
%make_build


%install
%make_install

%check
ctest -V %{?_smp_mflags}

Notes

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). Setting CMAKE_SKIP_RPATH for this version would avoid RPATHs in build-dir too. This might link binaries against system-libraries (e.g. when a previous version of the package was installed) instead of the libraries which were created by the build.

Nevertheless, RPATH issues might arise when cmake was used improperly. E.g. installing a target with INSTALL(FILES ... RENAME ...) will not strip rpaths; in this case INSTALL(TARGETS ...) must be used in combination with changing the OUTPUT_NAME property.

NOTE: cmake has good documentation in two places: