MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
run-logged.cmake
Go to the documentation of this file.
1# Usage: cmake -P run-logged.cmake -- <log> <command> [args...]
2#
3# Runs <command> with stdout and stderr streamed into <log> instead of the build
4# log. A non-zero exit dumps <log> so the failure is not swallowed.
5
6if(CMAKE_ARGC LESS 7)
7 message(FATAL_ERROR "usage: cmake -P run-logged.cmake -- <log> <command> [args...]")
8endif()
9
10set(LOG "${CMAKE_ARGV4}")
11math(EXPR _last "${CMAKE_ARGC} - 1")
12set(CMD)
13foreach(_i RANGE 5 ${_last})
14 # An unescaped ';' would split one argument into several list elements.
15 string(REPLACE ";" "\\;" _arg "${CMAKE_ARGV${_i}}")
16 list(APPEND CMD "${_arg}")
17endforeach()
18
19cmake_path(GET LOG PARENT_PATH _dir)
20file(MAKE_DIRECTORY "${_dir}")
21
22execute_process(
23 COMMAND ${CMD}
24 OUTPUT_FILE "${LOG}"
25 ERROR_FILE "${LOG}"
26 RESULT_VARIABLE _res
27)
28
29if(NOT _res EQUAL 0)
30 file(READ "${LOG}" _log)
31 message("${_log}")
32 list(JOIN CMD " " _cmdline)
33 message(FATAL_ERROR "failed (${_res}), see ${LOG}:\n ${_cmdline}")
34endif()