Skip to content

Commit

Permalink
fix: wrap fail macro inside a block (#274)
Browse files Browse the repository at this point in the history
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
  • Loading branch information
threeal authored Oct 18, 2024
1 parent efcd8eb commit ad0bf2a
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,50 +74,51 @@ endfunction()
# variable is another variable, it will format both the name and the value of
# the other variable.
macro(fail FIRST_LINE)
set(LINES)
foreach(LINE IN ITEMS "${FIRST_LINE}" ${ARGN})
# Expand variable if it is defined and contains another variable.
if(DEFINED "${LINE}" AND DEFINED "${${LINE}}")
list(APPEND LINES "${${LINE}}" "of variable" "${LINE}")
else()
list(APPEND LINES "${LINE}")
endif()
endforeach()

# Format the first line.
list(POP_FRONT LINES LINE)
if(DEFINED "${LINE}")
set(MESSAGE "${${LINE}}")
set(PREV_IS_STRING FALSE)
set(INDENT_VAR FALSE)
else()
set(MESSAGE "${LINE}")
set(PREV_IS_STRING TRUE)
set(INDENT_VAR TRUE)
endif()

# Format the consecutive lines.
foreach(LINE IN ITEMS ${LINES})
if(DEFINED "${LINE}")
if(PREV_IS_STRING)
string(APPEND MESSAGE ":")
endif()
if(INDENT_VAR)
string(REPLACE "\n" "\n " LINE "${${LINE}}")
string(APPEND MESSAGE "\n ${LINE}")
block()
foreach(LINE IN ITEMS "${FIRST_LINE}" ${ARGN})
# Expand variable if it is defined and contains another variable.
if(DEFINED "${LINE}" AND DEFINED "${${LINE}}")
list(APPEND LINES "${${LINE}}" "of variable" "${LINE}")
else()
string(APPEND MESSAGE "\n${${LINE}}")
list(APPEND LINES "${LINE}")
endif()
endforeach()

# Format the first line.
list(POP_FRONT LINES LINE)
if(DEFINED "${LINE}")
set(MESSAGE "${${LINE}}")
set(PREV_IS_STRING FALSE)
set(INDENT_VAR FALSE)
else()
string(APPEND MESSAGE "\n${LINE}")
set(MESSAGE "${LINE}")
set(PREV_IS_STRING TRUE)
set(INDENT_VAR TRUE)
endif()
endforeach()

# Throw a fatal error with the formatted message.
message(FATAL_ERROR "${MESSAGE}")
# Format the consecutive lines.
foreach(LINE IN ITEMS ${LINES})
if(DEFINED "${LINE}")
if(PREV_IS_STRING)
string(APPEND MESSAGE ":")
endif()
if(INDENT_VAR)
string(REPLACE "\n" "\n " LINE "${${LINE}}")
string(APPEND MESSAGE "\n ${LINE}")
else()
string(APPEND MESSAGE "\n${${LINE}}")
endif()
set(PREV_IS_STRING FALSE)
else()
string(APPEND MESSAGE "\n${LINE}")
set(PREV_IS_STRING TRUE)
set(INDENT_VAR TRUE)
endif()
endforeach()

# Throw a fatal error with the formatted message.
message(FATAL_ERROR "${MESSAGE}")
endblock()
endmacro()

# Asserts the given condition.
Expand Down

0 comments on commit ad0bf2a

Please sign in to comment.