cmake: Added assert that will show usage

There is a catch-22 in that you need to run CMake to get a build
system that can show you usage, but you need to know the usage to be
able to get a build system.

This assert could be used to improve the usability somewhat. When
invalid usage is detected it can be used to print the usage.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
Sebastian Bøe 2017-12-06 13:56:05 +01:00 committed by Anas Nashif
commit 6c8ebab183

View file

@ -811,3 +811,21 @@ macro(assert_exists var)
message(FATAL_ERROR "No such file or directory: ${var}: '${${var}}'")
endif()
endmacro()
# Usage:
# assert_with_usage(BOARD_DIR "No board named '${BOARD}' found")
#
# will print an error message, show usage, and then end executioon
# with a FATAL_ERROR if the test fails.
macro(assert_with_usage test comment)
if(NOT ${test})
message(${comment})
message("see usage:")
execute_process(
COMMAND
${CMAKE_COMMAND} -P $ENV{ZEPHYR_BASE}/cmake/usage/usage.cmake
)
message(FATAL_ERROR "Invalid usage")
endif()
endmacro()