diff options
Diffstat (limited to 'cmake/utils/HumanReadable.cmake')
| -rw-r--r-- | cmake/utils/HumanReadable.cmake | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cmake/utils/HumanReadable.cmake b/cmake/utils/HumanReadable.cmake new file mode 100644 index 00000000..8bc1722f --- /dev/null +++ b/cmake/utils/HumanReadable.cmake @@ -0,0 +1,17 @@ +# Human-readable size conversion utilities + +# Convert bytes to human-readable format (GB, MB, KB) +# Usage: format_bytes_human_readable(<bytes> <output_var>) +function(format_bytes_human_readable bytes output_var) + math(EXPR size_gb "${bytes} / 1073741824") + math(EXPR size_mb "${bytes} / 1048576") + math(EXPR size_kb "${bytes} / 1024") + + if(size_gb GREATER 0) + set(${output_var} "${size_gb} GB" PARENT_SCOPE) + elseif(size_mb GREATER 0) + set(${output_var} "${size_mb} MB" PARENT_SCOPE) + else() + set(${output_var} "${size_kb} KB" PARENT_SCOPE) + endif() +endfunction() |
