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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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...

message(WARNING
"No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build."
)
Expand Down
Loading