Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use CMake rpm macros and unset in-source builds #742

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

christianrauch
Copy link
Contributor

The RPM CMake macros under /usr/lib/rpm/macros.d/macros.cmake are defined differently for RHEL / AlmaLinux 8 and 9. Specifically, under AlmaLinux 8 in-source builds are enabled via %__cmake_in_source_build 1 and AlmaLinux 9 turns of stripping via -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF.

The effect is that the evaluation of the macros generates different spec files. This can be verified via:

# AlmaLinux 8
docker run --rm almalinux:8 bash -c "dnf -y install cmake && rpm --eval '%cmake' && rpm --eval '%cmake_build'"
# AlmaLinux 9
docker run --rm almalinux:9 bash -c "dnf -y install cmake && rpm --eval '%cmake' && rpm --eval '%cmake_build'"

On AlmaLinux 8 this evaluates to:

%if 0 
  %set_build_flags 
%else 
  CFLAGS="${CFLAGS:--O2 -g}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:--O2 -g}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:--O2 -g}" ; export FFLAGS ; 
  FCFLAGS="${FCFLAGS:--O2 -g}" ; export FCFLAGS ; 
   
%endif 
  /usr/bin/cmake \
         \
         \
        -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
        -DCMAKE_INSTALL_PREFIX:PATH=/usr \
        -DINCLUDE_INSTALL_DIR:PATH=/usr/include \
        -DLIB_INSTALL_DIR:PATH=/usr/lib64 \
        -DSYSCONF_INSTALL_DIR:PATH=/etc \
        -DSHARE_INSTALL_PREFIX:PATH=/usr/share \
%if "lib64" == "lib64" 
        -DLIB_SUFFIX=64 \
%endif 
        -DBUILD_SHARED_LIBS:BOOL=ON

  /usr/bin/cmake --build "." -j8 --verbose

On AlmaLinux 9 this evaluates to:

%if 01 
  
  CFLAGS="${CFLAGS:--O2 -g}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:--O2 -g}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:--O2 -g }" ; export FFLAGS ; 
  FCFLAGS="${FCFLAGS:--O2 -g }" ; export FCFLAGS ; 
  LDFLAGS="${LDFLAGS:-}" ; export LDFLAGS 
%else 
  CFLAGS="${CFLAGS:--O2 -g}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:--O2 -g}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:--O2 -g}" ; export FFLAGS ; 
  FCFLAGS="${FCFLAGS:--O2 -g}" ; export FCFLAGS ; 
   
%endif 
  /usr/bin/cmake \
        -S "%{_vpath_srcdir}" \
        -B "%{_vpath_builddir}" \
        -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
        -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF \
        -DCMAKE_INSTALL_PREFIX:PATH=/usr \
        -DINCLUDE_INSTALL_DIR:PATH=/usr/include \
        -DLIB_INSTALL_DIR:PATH=/usr/lib64 \
        -DSYSCONF_INSTALL_DIR:PATH=/etc \
        -DSHARE_INSTALL_PREFIX:PATH=/usr/share \
%if "lib64" == "lib64" 
        -DLIB_SUFFIX=64 \
%endif 
        -DBUILD_SHARED_LIBS:BOOL=ON

  /usr/bin/cmake --build "%{_vpath_builddir}" -j8 --verbose

Notice the difference in the build path (-B, --build) for the configure and build procedure. On AlmaLinux 8, the build path is the source path due to %__cmake_in_source_build 1, on AlmaLinux 9, there is a dedicated build folder.

This PR fixes the issue by unsetting __cmake_in_source_build and thus reverting back to out-of-source builds for both distributions. I am also replacing the manual calls of the "make" macros with their "cmake" counterpart. See https://docs.fedoraproject.org/en-US/packaging-guidelines/CMake/#_available_macros.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@b42a1dd). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #742   +/-   ##
=========================================
  Coverage          ?   54.58%           
=========================================
  Files             ?       52           
  Lines             ?     6363           
  Branches          ?     1128           
=========================================
  Hits              ?     3473           
  Misses            ?     2551           
  Partials          ?      339           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@christianrauch christianrauch marked this pull request as ready for review December 30, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants