-
Notifications
You must be signed in to change notification settings - Fork 8.2k
cmake: modules: version: Check that required fields are present #99188
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
base: main
Are you sure you want to change the base?
Conversation
Will throw an error showing what the issue with the VERSION file is if a required field is missing Signed-off-by: Jamie McCrae <[email protected]>
7a280e4 to
d928f88
Compare
|
| set(${type}_VERSION_MAJOR_LENGTH 0) | ||
| set(${type}_VERSION_MINOR_LENGTH 0) | ||
| set(${type}_PATCHLEVEL_LENGTH 0) | ||
| set(${type}_VERSION_TWEAK_LENGTH 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this complexity (also code below) ?
| set(${type}_VERSION_MAJOR_LENGTH 0) | |
| set(${type}_VERSION_MINOR_LENGTH 0) | |
| set(${type}_PATCHLEVEL_LENGTH 0) | |
| set(${type}_VERSION_TWEAK_LENGTH 0) |
| # Validate all version fields fit in a single byte | ||
| if(${type}_VERSION_MAJOR GREATER 255) | ||
| message(FATAL_ERROR "VERSION_MAJOR must be in the range 0-255 (Current ${${type}_VERSION_MAJOR})") | ||
| if(${type}_VERSION_MAJOR_LENGTH EQUAL 0 OR ${type}_VERSION_MAJOR GREATER 255) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If field is not defined, then CMAKE_MATCH_1 will be empty and thus the <type>_VERSION_x is not defined.
So this should be sufficient:
| if(${type}_VERSION_MAJOR_LENGTH EQUAL 0 OR ${type}_VERSION_MAJOR GREATER 255) | |
| if(NOT DEFINED ${type}_VERSION_MAJOR OR ${type}_VERSION_MAJOR GREATER 255) |
and avoid all the LENGTH handling above.
Comment applies to below code lines also.
| if(DEFINED ${type}_VERSION_MAJOR) | ||
| string(LENGTH ${${type}_VERSION_MAJOR} ${type}_VERSION_MAJOR_LENGTH) | ||
| endif() | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(DEFINED ${type}_VERSION_MAJOR) | |
| string(LENGTH ${${type}_VERSION_MAJOR} ${type}_VERSION_MAJOR_LENGTH) | |
| endif() |



Will throw an error showing what the issue with the VERSION file is if a required field is missing