1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (c) 2022, Nordic Semiconductor ASA
4
5# Everything before `--` are arguments for cmake invocation, those must be ignored.
6# First argument after `--` is the real compiler, but that is defined in REAL_CC
7# as environment variable for cgcc, hence that must also be ignored, thus first
8# argument to be passed to sparse is 2nd argument after `--`.
9foreach(i RANGE ${CMAKE_ARGC})
10  if("${CMAKE_ARGV${i}}" STREQUAL "--")
11    math(EXPR end_of_options "${i} + 2")
12    break()
13  endif()
14endforeach()
15
16foreach(i RANGE ${end_of_options} ${CMAKE_ARGC})
17  list(APPEND ARGS ${CMAKE_ARGV${i}})
18endforeach()
19execute_process(COMMAND @CMAKE_COMMAND@ -E env REAL_CC=@CMAKE_C_COMPILER@ @SPARSE_COMPILER@ ${ARGS}
20  COMMAND_ERROR_IS_FATAL ANY
21)
22