3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-05-25 11:26:22 +00:00
yosys/cmake/Condition.cmake
Catherine 9b087b4aa7 Migrate build system to CMake
See #5895 for details.

This commit does not include CI or documentation changes.
2026-05-23 03:48:24 +00:00

35 lines
932 B
CMake

# Syntax:
#
# condition(<var> <expr>...)
#
# If `<expr>...` is truthful (evaluated as in `if()`) then assigns 1 to `<var>`, else assigns 0.
# The assigned value is `0`/`1` rather than `TRUE`/`FALSE` for ease of use in generator expressions.
# Note that `<expr>...` *must* be unquoted.
#
# To understand how a certain outcome is reached, reconfigure the project with `--log-level VERBOSE`.
#
# Believe it or not, CMake doesn't have this built in!
#
macro(condition var)
if (${ARGN})
set(${var} 1)
else()
set(${var} 0)
endif()
set(_debug_expr)
foreach (token ${ARGN})
if (DEFINED ${token})
if (${${token}})
list(APPEND _debug_expr "${token}:1")
else()
list(APPEND _debug_expr "${token}:0")
endif()
else()
list(APPEND _debug_expr "${token}")
endif()
endforeach()
string(JOIN " " _debug_expr ${_debug_expr})
message(VERBOSE " ${var} = ${${var}} (${_debug_expr})")
unset(_debug_expr)
endmacro()