[packaging bugfix] Fix the application of the compilation flags

I discovered that the second call of "cmake -LAH" further changes the cache.
That was definitelly unintended. Applying "-N" to operate in "cache read-only" mode.

That however broke the build, since the compilation flags are set up during the "cmake" call.
Up until now, the code flow was:
  1) %cmake ...
  2) <adjusting compilation flags>
  3) cmake -LAH
And since the "cmake -LAH" without the "-N" argument changed the cache, it actually applied all the
adjustements in the second step. When switched to "-N" mode, the flags failed to be applied, and the build broke.

What we actually need to do is to:
  1) initialize the compilation flags with the distribution default values
  2) adjust the compilation flags
  3) %cmake ...
  3) cmake -N -LAH

This way the compilation flags are correctly applied during the first CMake call,
and the CMake cache remains unchanged during the second CMake call.

--

The '%cmake' macro contains the '%{set_build_flags}' macro at it's beginning
  https://src.fedoraproject.org/rpms/cmake/blob/b3bf0e/f/macros.cmake.in#_20
and the '%{set_build_flags}' macro is constructed with the:
  CFLAGS="${CFLAGS:-...}
syntax, which translates to "Use the content of the $CFLAGS variable. If empty, use the following default value: '...' ".

So we first need to call the '%{set_build_flags}' macro separately, so we apply the default values. Then we append to them.
And then the '%cmake' macro calls the '%{set_build_flags}' macro that finds the existing values, and uses them, instead of the default ones.
This commit is contained in:
Michal Schorm 2025-05-06 21:35:44 +02:00
parent 3ca7be2944
commit b74fb13bdb

View File

@ -926,6 +926,27 @@ fi
fi
%endif
# Adjust the compliation flags:
# First initialize the distribution default values
%{set_build_flags}
# Add custom tweaks
CFLAGS="$CFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
# Force the 'PIC' mode so that we can build libmysqld.so
CFLAGS="$CFLAGS -fPIC"
# When making a debug build, remove all optimizations
%if %{with debug}
# -D_FORTIFY_SOURCE requires optimizations enabled. Disable the fortify.
%undefine _fortify_level
CFLAGS=`echo "$CFLAGS" | sed -r 's/-O[0123]//'`
CFLAGS="$CFLAGS -O0 -g"
%endif
# Apply the updated values
CXXFLAGS="$CFLAGS"; CPPFLAGS="$CFLAGS"; export CFLAGS CXXFLAGS CPPFLAGS
# The INSTALL_xxx macros have to be specified relative to CMAKE_INSTALL_PREFIX
# so we can't use %%{_datadir} and so forth here.
%cmake \
@ -1001,27 +1022,8 @@ fi
# The issue is that the MariaDB upstream level of hardening is lower than expected by Red Hat
# We disable this option to the default compilation flags (which have higher level of hardening) will be used
CFLAGS="$CFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
# force PIC mode so that we can build libmysqld.so
CFLAGS="$CFLAGS -fPIC"
%if %{with debug}
# Override all optimization flags when making a debug build
# -D_FORTIFY_SOURCE requires optimizations enabled. Disable the fortify.
%undefine _fortify_level
CFLAGS=`echo "$CFLAGS" | sed -r 's/-O[0123]//'`
CFLAGS="$CFLAGS -O0 -g"
%endif
CXXFLAGS="$CFLAGS"
CPPFLAGS="$CFLAGS"
export CFLAGS CXXFLAGS CPPFLAGS
# Print all Cmake options values; "-LAH" means "List Advanced Help"
cmake -B %{_vpath_builddir} -LAH
# Print all cached CMake options values; "-N" means to run in read-only mode; "-LAH" means "List Advanced Help" for each option
cmake -B %{_vpath_builddir} -N -LAH
%cmake_build