From Fedora Project Wiki

Revision as of 14:13, 24 May 2008 by fp-wiki>ImportUser (Imported from MoinMoin)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

RPM Macros

<!-- /etc/rpm/macros.cmake:

%_cmake_lib_suffix64 -DLIB_SUFFIX=64
%__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 \

Specfile Usage

%cmake .
make VERBOSE=1 %{?_smp_mflags}




NOTE: -DCMAKE_SKIP_RPATH:BOOL=ON. 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 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: The proposed %cmake macro defines -DLIB_SUFFIX=64 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.