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

Wrap Fail Macro Inside a Block #274

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
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