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

cmake: Fix wrong check for cmake bool #59839

Closed
wants to merge 1 commit into from

Conversation

DaGuich
Copy link

@DaGuich DaGuich commented Jun 29, 2023

The check for the allow_empty property of a library asserted always as true. By removing the quotes around the variable, it is not asserted as a string.

The check for the allow_empty property of a library asserted always as
true. By removing the quotes around the variable, it is not asserted as
a string.

Signed-off-by: Matthias Gilch <[email protected]>
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

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

this changes the behavior from explicitly having to allow empty libraries to suddenly allow empty libraries per default, and thereby having to define when an empty library is not allowed.

@@ -882,7 +882,7 @@ foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
AND NOT ${lib_imported}
)
get_property(allow_empty TARGET ${zephyr_lib} PROPERTY ALLOW_EMPTY)
if(NOT "${allow_empty}")
if(NOT ${allow_empty})
Copy link
Collaborator

@tejlmand tejlmand Jun 29, 2023

Choose a reason for hiding this comment

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

The check for the allow_empty property of a library asserted always as
true.

Are you sure / what issue or false warning do you see ?
According to CMake docs: https://cmake.org/cmake/help/latest/command/if.html#string

if(<string>)
A quoted string always evaluates to false unless:
- The string's value is one of the true constants, or

and the true constants are:

True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number (including floating point numbers)

So by keeping the quotes, then setting ALLOW_EMPTY to one of the above should result in the if(NOT "y") to become false and the warning not printed, but when ALLOW_EMPTY is not set, a warning is printed.

However, the proposed if(NOT ${allow_empty}) will expand into if(NOT ) if ALLOW_EMPTY is not set which will evaluate to false, meaning default behavior will suddenly be to allow empty libraries.

If a library is empty and the warning should be silenced, then that library should set the ALLOW_EMPTY property to true.
Like this:

zephyr_library_property(ALLOW_EMPTY TRUE)

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your review.
Somehow I mixed up my terminals and did not notice that my test did not produce the warning anymore where allow empty was not set.

Nevertheless, I still have the warning for modules that are empty. But the issue for that is somewhere else...

@DaGuich DaGuich closed this Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants