Skip to content

Commit

Permalink
cmake enhanced tiny_to_bool()
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Aug 21, 2024
1 parent 45b24a9 commit 249d523
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
26 changes: 22 additions & 4 deletions cmake/CommonModules/TinyHelpers.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
# Invert a boolean variable value
# Convert to the boolean value and invert this boolean value (currently unused)
function(tiny_invert_bool out_variable value)

if(${value})
# This function may look useless, but I'm using it because I want to have unified
# boolean values, so it's TRUE or FALSE and not ON/OFF, ...

# Don't use the Variable Reference here ${value}, an undefined value can be
# controlled while passing the value to this function using an unquoted
# Variable Reference like:
# tiny_invert_bool(xyz ${some_bool})
# This means if the value is undefined (empty) and will be unquoted, then it fails;
# if it is undefined and quoted, it returns TRUE (as it's inverted)
if(value)
set(${out_variable} FALSE PARENT_SCOPE)
else()
set(${out_variable} TRUE PARENT_SCOPE)
endif()

endfunction()

# Convert to a boolean value
# Convert to the boolean value
function(tiny_to_bool out_variable value)

if(${value})
# This function may look useless, but I'm using it because I want to have unified
# boolean values, so it's TRUE or FALSE and not ON/OFF, ...

# Don't use the Variable Reference here ${value}, an undefined value can be
# controlled while passing the value to this function using an unquoted
# Variable Reference like:
# tiny_to_bool(xyz ${some_bool})
# This means if the value is undefined (empty) and will be unquoted, then it fails;
# if it is undefined and quoted, it returns FALSE
if(value)
set(${out_variable} TRUE PARENT_SCOPE)
else()
set(${out_variable} FALSE PARENT_SCOPE)
Expand Down
13 changes: 11 additions & 2 deletions cmake/TinyPackageConfigHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ function(tiny_printable_configurations out_configurations configurations)

endfunction()

# Convert to a boolean value
# Convert to the boolean value
function(tiny_to_bool out_variable value)

if(${value})
# This function may look useless, but I'm using it because I want to have unified
# boolean values, so it's TRUE or FALSE and not ON/OFF, ...

# Don't use the Variable Reference here ${value}, an undefined value can be
# controlled while passing the value to this function using an unquoted
# Variable Reference like:
# tiny_to_bool(xyz ${some_bool})
# This means if the value is undefined (empty) and will be unquoted, then it fails;
# if it is undefined and quoted, it returns FALSE
if(value)
set(${out_variable} TRUE PARENT_SCOPE)
else()
set(${out_variable} FALSE PARENT_SCOPE)
Expand Down

0 comments on commit 249d523

Please sign in to comment.