You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimization levels and debugging options are tied to a "build type/configuration" in CMake. If a user wants to override any of these, they should use the CMAKE_CXX_FLAGS_<CONFIG> variables. In depends, the $(host)_{release,debug}_CXXFLAGS variables handle this. However, they are not overridable by the user at the moment.
If a user wants to override any of these, they should use the CMAKE_CXX_FLAGS_ variables.
Any user would expect this to be handled by the toolchain file, which is meant to pass everything required through to CMake. Regardless of that, the fact that the behaviour here is inconsistent depending on whether or not you pass -DCMAKE_BUILD_TYPE=RelWithDebug explictly, is confusing.
I suppose that should only happen if the -O3 isn't coming from an explicitly set CMAKE_CXX_FLAGS_RELEASE.
Possibly, but I think the way this has been implented is confusing (also not properly documented), and the goals are unclear. Are we trying to prevent compilation with -O3, or just trying to make things as non-standard (CMake) as possible. Why even do the replacement if you are going to let it be overridden (using the standard flags)? The current code, and that behaviour are just going to trip up everyone that expects 'Release' to already be a certain thing.
doesn't work. What should users do? Are we disallowing -O3 wholesale? If this is the case, it should probably be documented (with the rationale), and likely warned about at configure time (if they have set -O3 via CMAKE_CXX_FLAGS_ or any other way), rather than sliently swapping users flags out from under them.
I suppose that should only happen if the -O3 isn't coming from an explicitly set CMAKE_CXX_FLAGS_RELEASE.
This would be better than the current approach of silently changing user flags, but thinking about this more, I'm also not sure we want to be adding even more special cases, without it being clear what outcome we are trying to acheive.
So basically the user will always get -O2, unless they change the optims by setting them in the supported/documented variable: -DCMAKE_CXX_FLAGS_RELEASE=-O3
Note that this does not address the depends problem. The issue there is that the "-Ox" flags are jumbled in with the rest of the flags.
To fix that, we need to grab the "-O" values out of the passed-in CXXFLAGS and tack the last one onto CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT. I'll push a commit for that to my branch.
So should we also be documenting that our -DCMAKE_BUILD_TYPE=Release doesn't give -O3 (given it's the expected CMake default)? As users explicitly setting that are expecting -O3, without having to also provide it via CMAKE_CXX_FLAGS_RELEASE, but still wont get it via master or your branch above.
I guess it could make sense to append -O2 in the case of -DCMAKE_BUILD_TYPE=RelWithDebInfo reported in OP as well, to avoid the unexpected -O3 there? (The output reading a bit odd seems like a style issue that can be ignored for now)
@hebasto Have you experimented with using regular cache variables as opposed to the _INIT ones?
Cache variables are designed to be set by the user. With the suggested approach, there is no way to distinguish whether the variable is set on the command line by the user or in a toolchain file.
doesn't work. What should users do? Are we disallowing -O3 wholesale? If this is the case, it should probably be documented (with the rationale), and likely warned about at configure time (if they have set -O3 via CMAKE_CXX_FLAGS_ or any other way), rather than sliently swapping users flags out from under them.
Anything left to be done here? It looks like the initial reports were about some depends-specific issues. However, the discussion then went into a general discussion about O3 and release notes? The -DCMAKE_CXX_FLAGS_type thing should be fixed by now.
It could make sense to file a new issue, or at least change the title to clarify that this is a depends-related report. Assuming that this isn't already covered by #31920 or #30813
Activity
hebasto commentedon Dec 13, 2024
Optimization levels and debugging options are tied to a "build type/configuration" in CMake. If a user wants to override any of these, they should use the
CMAKE_CXX_FLAGS_<CONFIG>variables. In depends, the$(host)_{release,debug}_CXXFLAGSvariables handle this. However, they are not overridable by the user at the moment.fanquake commentedon Dec 13, 2024
Any user would expect this to be handled by the toolchain file, which is meant to pass everything required through to CMake. Regardless of that, the fact that the behaviour here is inconsistent depending on whether or not you pass
-DCMAKE_BUILD_TYPE=RelWithDebugexplictly, is confusing.fanquake commentedon Dec 13, 2024
Does this actually work in this case though? If I do:
I still get
-O2?theuni commentedon Dec 13, 2024
I'm seeing the same. This definitely worked at some point, I assume there's been some regression since merge?
theuni commentedon Dec 13, 2024
Ah, I see. It's:
replace_cxx_flag_in_config(Release -O3 -O2)I suppose that should only happen if the
-O3isn't coming from an explicitly setCMAKE_CXX_FLAGS_RELEASE.fanquake commentedon Dec 16, 2024
Possibly, but I think the way this has been implented is confusing (also not properly documented), and the goals are unclear. Are we trying to prevent compilation with
-O3, or just trying to make things as non-standard (CMake) as possible. Why even do the replacement if you are going to let it be overridden (using the standard flags)? The current code, and that behaviour are just going to trip up everyone that expects 'Release' to already be a certain thing.fanquake commentedon Jan 6, 2025
@hebasto Given that your suggestion of
> If a user wants to override any of these, they should use the CMAKE_CXX_FLAGS_
doesn't work. What should users do? Are we disallowing
-O3wholesale? If this is the case, it should probably be documented (with the rationale), and likely warned about at configure time (if they have set-O3viaCMAKE_CXX_FLAGS_or any other way), rather than sliently swapping users flags out from under them.This would be better than the current approach of silently changing user flags, but thinking about this more, I'm also not sure we want to be adding even more special cases, without it being clear what outcome we are trying to acheive.
theuni commentedon Jan 6, 2025
I'd say this actually isn't a special case, rather it's fixing a logical bug in the current impl.
Currently, we essentially do:
echo "$CMAKE_CXX_FLAGS_RELEASE" | sed "s/-O3/-O2/".Instead, I think we only want to do that if we're not overriding the user. Essentially the same as: https://github.com/bitcoin/bitcoin/blob/28.x/configure.ac#L298
So basically the user will always get -O2, unless they change the optims by setting them in the supported/documented variable:
-DCMAKE_CXX_FLAGS_RELEASE=-O3See here for the fix: theuni@4f8f7de
I can PR ^^ if you're good with it.
theuni commentedon Jan 6, 2025
Note that this does not address the depends problem. The issue there is that the "-Ox" flags are jumbled in with the rest of the flags.
To fix that, we need to grab the "-O" values out of the passed-in
CXXFLAGSand tack the last one ontoCMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT. I'll push a commit for that to my branch.theuni commentedon Jan 6, 2025
Unfortunately it seems like the behavior around
$config_FLAGSis just broken in depends. It uses_INITvalues which are always appended-to.So at the moment, the $config setting always takes precedence over what's set in depends, even if not overriding C(XX)FLAGS.
@hebasto Have you experimented with using regular cache variables as opposed to the _INIT ones?
fanquake commentedon Jan 10, 2025
So should we also be documenting that our
-DCMAKE_BUILD_TYPE=Releasedoesn't give-O3(given it's the expected CMake default)? As users explicitly setting that are expecting-O3, without having to also provide it viaCMAKE_CXX_FLAGS_RELEASE, but still wont get it via master or your branch above.6 remaining items
sipa commentedon Apr 24, 2025
See also #32337.
fanquake commentedon Apr 25, 2025
@hebasto can you followup with all the questions asked in this thread:
#31491 (comment)
#31491 (comment)
It'd be good to get some clarification on which behaviour is meant to work.
maflcko commentedon Apr 25, 2025
I guess it could make sense to append
-O2in the case of-DCMAKE_BUILD_TYPE=RelWithDebInforeported in OP as well, to avoid the unexpected-O3there? (The output reading a bit odd seems like a style issue that can be ignored for now)hebasto commentedon Apr 26, 2025
@theuni
Cache variables are designed to be set by the user. With the suggested approach, there is no way to distinguish whether the variable is set on the command line by the user or in a toolchain file.
hebasto commentedon Apr 26, 2025
@theuni
@fanquake
Fixed in #32356.
hebasto commentedon Apr 26, 2025
I cannot reproduce the output for the second
cmakeinvocation.Merge #32356: cmake: Respect user-provided configuration-specific flags
maflcko commentedon May 9, 2025
Anything left to be done here? It looks like the initial reports were about some
depends-specific issues. However, the discussion then went into a general discussion about O3 and release notes? The-DCMAKE_CXX_FLAGS_typething should be fixed by now.It could make sense to file a new issue, or at least change the title to clarify that this is a depends-related report. Assuming that this isn't already covered by #31920 or #30813
fanquake commentedon May 9, 2025
Given the amount of discussion here, we can re-open new issues.
Merge bitcoin/bitcoin#32356: cmake: Respect user-provided configurati…
Merge bitcoin/bitcoin#32356: cmake: Respect user-provided configurati…