Skip to content

Commit 8a26f23

Browse files
committed
Refactor dump() and dd(), use var_dump
1 parent 452d981 commit 8a26f23

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

cmake/rsp/debug.cmake

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,45 @@ if (NOT COMMAND "dump")
1313

1414
#! dump : Outputs given variables' name and value
1515
#
16+
# Note: function outputs using cmake's WARNING message mode
17+
#
18+
# @see https://cmake.org/cmake/help/latest/command/message.html#general-messages
19+
# @see var_dump()
20+
#
1621
# @param ... Variables to output
1722
#
1823
function(dump)
19-
foreach (var ${ARGN})
20-
message("${var} = ${${var}}")
21-
endforeach ()
24+
var_dump(OUTPUT output PROPERTIES ${ARGN})
25+
26+
# Attempt to keep the formatting - see details in rsp/output::output()
27+
string(ASCII 13 CR)
28+
set(formatted_output "${CR}${COLOR_WHITE}dump:${RESTORE}\n${output}")
29+
string(REPLACE "\n" "\n " formatted_output "${formatted_output}")
2230

23-
# Output as warning so that the developer is able to see call stack!
24-
message(WARNING " ${CMAKE_CURRENT_FUNCTION}() called from ${CMAKE_CURRENT_LIST_FILE}")
31+
message(WARNING "${formatted_output}")
2532
endfunction()
2633
endif ()
2734

2835
if (NOT COMMAND "dd")
2936

30-
#! dump and die: Outputs given variables' name and value and stops build
37+
#! dd: Outputs given variables' name and value and stops build (dump and die)
38+
#
39+
# Note: function outputs using cmake's FATAL_ERROR message mode
40+
#
41+
# @see https://cmake.org/cmake/help/latest/command/message.html#general-messages
42+
# @see var_dump()
3143
#
3244
# @param ... Variables to output
3345
#
3446
function(dd)
35-
foreach (var ${ARGN})
36-
message("${var} = ${${var}}")
37-
endforeach ()
47+
var_dump(OUTPUT output PROPERTIES ${ARGN})
48+
49+
# Attempt to keep the formatting - see details in rsp/output::output()
50+
string(ASCII 13 CR)
51+
set(formatted_output "${CR}${COLOR_WHITE}dd:${RESTORE}\n${output}")
52+
string(REPLACE "\n" "\n " formatted_output "${formatted_output}")
3853

39-
# Output as fatal error to ensure that build stops.
40-
message(FATAL_ERROR " ${CMAKE_CURRENT_FUNCTION}() called from ${CMAKE_CURRENT_LIST_FILE}")
54+
message(FATAL_ERROR "${formatted_output}")
4155
endfunction()
4256
endif ()
4357

0 commit comments

Comments
 (0)