1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (c) 2024, Baumer (www.baumer.com)
4
5# Everything before `--` are arguments for cmake invocation, those must be ignored.
6# The first argument after `--` is the start of the compiler call, which is
7# what we want to get to invoke ECLAIR with the compiler call which is used in the zephyr
8# environment
9foreach(i RANGE ${CMAKE_ARGC})
10  if("${CMAKE_ARGV${i}}" STREQUAL "--")
11    math(EXPR end_of_options "${i} + 1")
12    break()
13  endif()
14endforeach()
15
16foreach(i RANGE ${end_of_options} ${CMAKE_ARGC})
17  list(APPEND ZEPHYR_COMPILER_CALL ${CMAKE_ARGV${i}})
18endforeach()
19
20list(APPEND ECLAIR_ARGS +incremental
21                        -project_name=@ECLAIR_PROJECT_NAME@ -project_root=@ZEPHYR_BASE@
22                        -eval_file=@ECLAIR_ECL_DIR@/analysis.ecl
23                        -eval_file=@ECLAIR_ANALYSIS_ECL_DIR@/analysis_@ECLAIR_RULESET@.ecl
24                        @ECLAIR_ENV_ADDITIONAL_OPTIONS@)
25
26execute_process(
27  COMMAND @CMAKE_COMMAND@ -E env
28    ECLAIR_DIAGNOSTICS_OUTPUT=@ECLAIR_DIAGNOSTICS_OUTPUT@
29    ECLAIR_DATA_DIR=@ECLAIR_ANALYSIS_DATA_DIR@
30    CC_ALIASES=@CC_ALIASES@
31    CXX_ALIASES=@CXX_ALIASES@
32    AS_ALIASES=@AS_ALIASES@
33    LD_ALIASES=@LD_ALIASES@
34    AR_ALIASES=@AR_ALIASES@
35    @ECLAIR_ENV@ ${ECLAIR_ARGS} -- ${ZEPHYR_COMPILER_CALL}
36  COMMAND_ERROR_IS_FATAL ANY
37)
38