-
Notifications
You must be signed in to change notification settings - Fork 260
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
CMake: Inconsistent feature control #850
Comments
i don't know why the cmake files prefer otherwise i agree that we should only be writing out config settings & turning on features based on the knobs the user passed, and not let things get flipped on indirectly. related, i'd like to see the feature tests in cmake files follow an autodetect-by-default policy rather than off-by-default policy. this is how the autotools build works today:
|
Better not, or at least provide an option to change the default for all features. Otherwise it is really hard to avoid unexpected dependencies. The presence of a dependency is only a weak indicator that a depending feature is actually desired. |
it isn't hard: disable the options yourself if you don't care. this is how autotools has worked for decades without much hassle. |
The problem is that with auto-probe, I have to deal with every option because I care about every dependency.
... within a certain scope of systems and expectations. In my experience, preferences for default behaviours very much vary with a person's role: core developer, package maintainer, occassional user. I spent quite some time with the (now gone) autotools setup of GDAL... It is easy to miss control (opt-out) for a feature which you don't need (and different users get different results) but it is much less likely to miss control (opt-in) for a feature which you do need. But I admit that libgd has a fairly small and stable set of options and dependencies. |
most people get gd via distros who are well equipped and expected to control every option. autodetect doesn't matter to them because they would never go that route. random devs who download source releases and build from scratch tend to expect things "just work" out of the box without having to read the manual first. forcing them to specify every option is a pita and not the standard in the larger OSS world. if you're trying to build and package this up for reuse, then you're expected to set the options yourself. |
I don't feel comfortable with the strong bias in the responses. I wonder why took the time to read the code of conduct before posting. |
The key point of this issue that the options do not reliably (enough) control the effects, due to inconsistent use of CMake variables. |
i'm pretty sure i said i agree with you. if the user explicitly enabled/disabled something, then that should be respected. i think the reason we use the "found" variables is because we want to emulate the autoconf behavior i described wrt autodetect-by-default. we just didn't foresee the indirect leakage via other knobs. |
It is (fairly) easy to fix the key point of this issue (strict control).
I fail to see if this was accepted as a sufficient compomise. |
TLDNR: Replace
<Pkg>_FOUND
withENABLE_<Feature>
.Describe the bug
In
CMakeLists.txt
, there are ON/OFF-options for feature control, e.g.ENABLE_GD_FORMATS
:libgd/CMakeLists.txt
Line 12 in 7b0d419
These options are used to control lookup of required dependencies, e.g.
libgd/CMakeLists.txt
Lines 123 to 125 in 7b0d419
This is fine.
However, in further processing (for macro definitions, selection of programs, export of gdlib.pc), the options are not used directly, but the
<Pkg>_FOUND
values are used instead:libgd/CMakeLists.txt
Lines 192 to 196 in 7b0d419
IMO this is wrong and should use the original
ENABLE_<Feature>
variables. A CMake package might have been found even if the user disabled the corresponding libgd feature. In particular, this happens in vcpkg for static triplets when CMake configs or Find module wrappers chainload additional packages to resolve transitive usage requirements.This problem is unlikely to be present with libgd's Find modules in
cmake/modules
which are unaware of actual static usage requirements. Modifying/replacing these modules is mandatory for static linkage. I still think it is an inconsistency which should be resolved.As a variant, feature PNG also looks for ZLIB:
libgd/CMakeLists.txt
Lines 127 to 130 in 7b0d419
I can imagine that this helps with static linkage. But I don't think it should override the effect of
ENABLE_GD_FORMATS
.I could create a PR (based on packaging in vcpkg). I would also merge the second spots (
if(<Pkg>_FOUND)
) with the first spots (if(<Feature>_ENABLED
). This should be possible without source changes which would need adjustments to the autotools build system. But there maybe a need for upfront discussion.To Reproduce
Build for static triplet in vcpkg with different feature configurations and check build, or do the equivalent directly in CMake.
Or maybe (untested):
Expected behavior
If a feature is not enabed, it shall never be compiled into libraries, and related executables must not be built.
Actual results
A feature and related executables may be built even if explicit disabled by the user.
Environment (please complete the following information):
Additional context
microsoft/vcpkg#27551
which now uses a minimal patch to forward
ENABLE_<Feature>
to<Pkg>_FOUND
to achieve the desired build control.The text was updated successfully, but these errors were encountered: