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

Check options #243

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Check options #243

wants to merge 4 commits into from

Conversation

flagarde
Copy link
Contributor

Hi,

Restore the ability to check OPTIONS.

set(OPTION_VALUE
"${OPTION_VALUE}"
PARENT_SCOPE
# https://cmake.org/cmake/help/latest/command/if.html#basic-expressions (1/0 is problematic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is 1/0 problematic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could mean "ON" or NUMBER_OF_CORE "1"

Copy link
Member

@iboB iboB Mar 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why not change all values to "1" instead of to "ON"? Thus this case will be covered

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point with the truthy/falsy values! There could however be more problems with changing the passed parameter to the dependency, e.g. LETTER_TO_PARSE Y and so on, which would lead to strange and unexpected bugs for some users. I think we should either use the normalisation only when checking of parameter consistency or add a note in the readme that we recommend truthy/falsy values to be standardised in CPM.cmake options (e.g. to YES/NO).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheLartians yes good point, this it's an other problem. Maybe CPM could accept only TRUE YES ON. It makes it more informative and I'm temptated to say using 1 or Y for TRUE should be avoided. I think we should either use the normalisation only when checking of parameter consistency or add a note in the readme that we recommend truthy/falsy values to be standardised in CPM.cmake options (e.g. to YES/NO). I agree totlaly to this point but maybe we could add TRUE and On as they are not preblematic and very well used. I have never seen 1 or Y.

cmake/CPM.cmake Outdated
@@ -271,6 +271,55 @@ function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION)
"${CPM_INDENT} requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})."
)
endif()

if(CPM_ARGS_OPTIONS)
Copy link
Member

@iboB iboB Mar 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if when the that package was first added options were not set and now they are, or vice-versa?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes maybe this cases are not well checked.

Copy link
Member

@TheLartians TheLartians left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @flagarde, thanks for re-implementing the options check!

Thinking a bit more about the options, I'm not sure if it's a good idea to perform the check in all cases. E.g. often an upstream package would override a downstream version with a newer dependency. In that case the option names and behaviours could have changed, so the old options no longer apply.

Perhaps we should only perform the check if the versions match, or at least offer a way to opt-out?

set(OPTION_VALUE
"${OPTION_VALUE}"
PARENT_SCOPE
# https://cmake.org/cmake/help/latest/command/if.html#basic-expressions (1/0 is problematic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point with the truthy/falsy values! There could however be more problems with changing the passed parameter to the dependency, e.g. LETTER_TO_PARSE Y and so on, which would lead to strange and unexpected bugs for some users. I think we should either use the normalisation only when checking of parameter consistency or add a note in the readme that we recommend truthy/falsy values to be standardised in CPM.cmake options (e.g. to YES/NO).

@flagarde
Copy link
Contributor Author

Hey @flagarde, thanks for re-implementing the options check!

Thinking a bit more about the options, I'm not sure if it's a good idea to perform the check in all cases. E.g. often an upstream package would override a downstream version with a newer dependency. In that case the option names and behaviours could have changed, so the old options no longer apply.

Perhaps we should only perform the check if the versions match, or at least offer a way to opt-out?

If I understand how CPM is working now, if the upstream ask for a newer version a warning will be raised and the new version will be used. I think this are two different problems and it would be nice to have the warning for the version and the warning for the options.

If you are not warned you could disable some option necessary downstream without knowing it. Sometimes you don't know exactly what are the need of the used repositories. It could be possible to add an option to disable the check.

Internally CMake use ON so if you want to force only one key maybe you should choose this one

@flagarde
Copy link
Contributor Author

In case you include two time the same repo with the same version : Do you want to keep the previous option or the last one. I suppose you want to keep the last one ?

In cas you have same repo but two version you want new version and the new options right ?

@TheLartians
Copy link
Member

Well with the way CPM.cmake currently works (we immediately add the package after definition), we always use the first version and options added. In case another dependency asks for a newer version that the one currently added, we inform the user it may be necessary to upgrade by outputting a warning. As for options I think we must ask ourselves which scenarios are likely. E.g. if a project adds the same dependency twice, but using different options, I see the following scenarios:

  • The version is the same as before: there is a chance that the user was unaware of the other requirement and the options of both should be merged. Other values are to be expected and emitting a warning may be helpful.
  • Using a newer version than downstream: the options may have changed in the update and old options could no longer be valid. Not sure what a good default behaviour would be.
  • Using an older version than downstream: the user might be unaware of the update and we should warn him about the update and options, which a dependency might rely on.

In all cases we might consider adding an OVERRIDE ON parameter to disable the warning, as the user signals that he knows what he is doing

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.

None yet

3 participants