cmake: utility to create a failing target

This commit is contained in:
Renz Christian Bagaporo 2020-03-02 07:15:34 +05:00 committed by Renz Bagaporo
parent 14d6dad650
commit 35839232c8
2 changed files with 26 additions and 2 deletions

View file

@ -1,4 +1,4 @@
# 'cmake -E' doesn't have a way to fail outright, so run this script # 'cmake -E' doesn't have a way to fail outright, so run this script
# with 'cmake -P' to fail a build. # with 'cmake -P' to fail a build.
message(FATAL_ERROR "Failing the build (see errors on lines above)") message(FATAL_ERROR "$ENV{FAIL_MESSAGE}")

View file

@ -214,13 +214,37 @@ function(fail_at_build_time target_name message_line0)
set(filename "${CMAKE_CURRENT_BINARY_DIR}/${filename}.cmake") set(filename "${CMAKE_CURRENT_BINARY_DIR}/${filename}.cmake")
file(WRITE "${filename}" "") file(WRITE "${filename}" "")
include("${filename}") include("${filename}")
set(fail_message "Failing the build (see errors on lines above)")
add_custom_target(${target_name} ALL add_custom_target(${target_name} ALL
${message_lines} ${message_lines}
COMMAND ${CMAKE_COMMAND} -E remove "${filename}" COMMAND ${CMAKE_COMMAND} -E remove "${filename}"
COMMAND ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake COMMAND ${CMAKE_COMMAND} -E env FAIL_MESSAGE=${fail_message}
${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake
VERBATIM) VERBATIM)
endfunction() endfunction()
# fail_target
#
# Creates a phony target which fails when invoked. This is used when the necessary conditions
# for a target are not met, such as configuration. Rather than ommitting the target altogether,
# we fail execution with a helpful message.
function(fail_target target_name message_line0)
idf_build_get_property(idf_path IDF_PATH)
set(message_lines COMMAND ${CMAKE_COMMAND} -E echo "${message_line0}")
foreach(message_line ${ARGN})
set(message_lines ${message_lines} COMMAND ${CMAKE_COMMAND} -E echo "${message_line}")
endforeach()
# Generate a timestamp file that gets included. When deleted on build, this forces CMake
# to rerun.
set(fail_message "Failed executing target (see errors on lines above)")
add_custom_target(${target_name}
${message_lines}
COMMAND ${CMAKE_COMMAND} -E env FAIL_MESSAGE=${fail_message}
${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake
VERBATIM)
endfunction()
function(check_exclusive_args args prefix) function(check_exclusive_args args prefix)
set(_args ${args}) set(_args ${args})
spaces2list(_args) spaces2list(_args)