blob: 8dbc8a42f976af0feaee91dbdf8565ea4f7fe201 [file] [log] [blame]
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2023, BUGSENG Srl
find_program(ECLAIR_ENV eclair_env REQUIRED)
message(STATUS "Found eclair_env: ${ECLAIR_ENV}")
find_program(ECLAIR_REPORT eclair_report REQUIRED)
message(STATUS "Found eclair_report: ${ECLAIR_REPORT}")
if(ECLAIR_OPTIONS_FILE)
if(IS_ABSOLUTE ${ECLAIR_OPTIONS_FILE})
set(ECLAIR_OPTIONS ${ECLAIR_OPTIONS_FILE})
else()
set(ECLAIR_OPTIONS ${APPLICATION_CONFIG_DIR}/${ECLAIR_OPTIONS_FILE})
endif()
include(${ECLAIR_OPTIONS})
else()
include(${CMAKE_CURRENT_LIST_DIR}/sca_options.cmake)
endif()
# ECLAIR Settings
set(ECLAIR_PROJECT_NAME "Zephyr-${BOARD}${BOARD_QUALIFIERS}")
set(ECLAIR_OUTPUT_DIR "${CMAKE_BINARY_DIR}/sca/eclair")
set(ECLAIR_ECL_DIR "${ZEPHYR_BASE}/cmake/sca/eclair/ECL")
set(ECLAIR_ANALYSIS_ECL_DIR "${ZEPHYR_BASE}/cmake/sca/eclair/ECL")
set(ECLAIR_DIAGNOSTICS_OUTPUT "${ECLAIR_OUTPUT_DIR}/DIAGNOSTIC.txt")
set(ECLAIR_ANALYSIS_DATA_DIR "${ECLAIR_OUTPUT_DIR}/analysis_data")
set(ECLAIR_PROJECT_ECD "${ECLAIR_OUTPUT_DIR}/PROJECT.ecd")
set(CC_ALIASES "${CMAKE_C_COMPILER}")
set(CXX_ALIASES "${CMAKE_CXX_COMPILER}")
set(AS_ALIASES "${CMAKE_AS}")
set(LD_ALIASES "${CMAKE_LINKER}")
set(AR_ALIASES "${CMAKE_ASM_COMPILER_AR} ${CMAKE_C_COMPILER_AR} ${CMAKE_CXX_COMPILER_AR}")
set(ECLAIR_ENV_ADDITIONAL_OPTIONS "")
set(ECLAIR_REPORT_ADDITIONAL_OPTIONS "")
# Default value
set(ECLAIR_RULESET first_analysis)
# ECLAIR env
if(ECLAIR_RULESET_FIRST_ANALYSIS)
set(ECLAIR_RULESET first_analysis)
elseif(ECLAIR_RULESET_STU)
set(ECLAIR_RULESET STU)
elseif(ECLAIR_RULESET_STU_HEAVY)
set(ECLAIR_RULESET STU_heavy)
elseif(ECLAIR_RULESET_WP)
set(ECLAIR_RULESET WP)
elseif(ECLAIR_RULESET_STD_LIB)
set(ECLAIR_RULESET std_lib)
elseif(ECLAIR_RULESET_USER)
set(ECLAIR_RULESET ${ECLAIR_USER_RULESET_NAME})
if(IS_ABSOLUTE ${ECLAIR_USER_RULESET_PATH})
set(ECLAIR_ANALYSIS_ECL_DIR ${ECLAIR_USER_RULESET_PATH})
else()
set(ECLAIR_ANALYSIS_ECL_DIR ${APPLICATION_CONFIG_DIR}/${ECLAIR_USER_RULESET_PATH})
endif()
endif()
# ECLAIR report
if (ECLAIR_METRICS_TAB)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-metrics_tab=${ECLAIR_OUTPUT_DIR}/metrics")
endif()
if (ECLAIR_REPORTS_TAB)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-reports_tab=${ECLAIR_OUTPUT_DIR}/reports")
endif()
if (ECLAIR_REPORTS_SARIF)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-reports_sarif=${ECLAIR_OUTPUT_DIR}/reports.sarif")
endif()
if (ECLAIR_SUMMARY_TXT)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-summary_txt=${ECLAIR_OUTPUT_DIR}/summary_txt")
endif()
if (ECLAIR_SUMMARY_DOC)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-summary_doc=${ECLAIR_OUTPUT_DIR}/summary_doc")
endif()
if (ECLAIR_SUMMARY_ODT)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-summary_odt=${ECLAIR_OUTPUT_DIR}/summary_odt")
endif()
if (ECLAIR_FULL_TXT_ALL_AREAS)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-setq=report_areas,areas")
endif()
if (ECLAIR_FULL_TXT_FIRST_AREA)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-setq=report_areas,first_area")
endif()
if (ECLAIR_FULL_TXT)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-full_txt=${ECLAIR_OUTPUT_DIR}/report_full_txt")
endif()
if (ECLAIR_FULL_DOC_ALL_AREAS)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-setq=report_areas,areas")
endif()
if (ECLAIR_FULL_DOC_FIRST_AREA)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-setq=report_areas,first_area")
endif()
if (ECLAIR_FULL_DOC)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-full_doc=${ECLAIR_OUTPUT_DIR}/report_full_doc")
endif()
if (ECLAIR_FULL_ODT)
list(APPEND ECLAIR_REPORT_ADDITIONAL_OPTIONS "-full_odt=${ECLAIR_OUTPUT_DIR}/report_full_odt")
endif()
message(STATUS "ECLAIR outputs have been written to: ${ECLAIR_OUTPUT_DIR}")
message(STATUS "ECLAIR ECB files have been written to: ${ECLAIR_ANALYSIS_DATA_DIR}")
add_custom_target(eclair_setup_analysis_dir ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory ${ECLAIR_ANALYSIS_DATA_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${ECLAIR_ANALYSIS_DATA_DIR}
VERBATIM
USES_TERMINAL
)
# configure the camke script which will be used to replace the compiler call with the eclair_env
# call which calls the compiler and to generate analysis files.
configure_file(${CMAKE_CURRENT_LIST_DIR}/eclair.template ${ECLAIR_OUTPUT_DIR}/eclair.cmake @ONLY)
set(launch_environment ${CMAKE_COMMAND} -P ${ECLAIR_OUTPUT_DIR}/eclair.cmake --)
set(CMAKE_C_COMPILER_LAUNCHER ${launch_environment} CACHE INTERNAL "")
# This target is used to generate the ECLAIR database when all the compilation is done and the
# elf file was generated with this we cane make sure that the analysis is completed.
add_custom_target(eclair_report ALL
COMMAND ${CMAKE_COMMAND} -E env
ECLAIR_DATA_DIR=${ECLAIR_ANALYSIS_DATA_DIR}
ECLAIR_OUTPUT_DIR=${ECLAIR_OUTPUT_DIR}
ECLAIR_PROJECT_ECD=${ECLAIR_PROJECT_ECD}
${ECLAIR_REPORT} -quiet -eval_file=${ECLAIR_ECL_DIR}/db_generation.ecl
DEPENDS ${CMAKE_BINARY_DIR}/zephyr/zephyr.elf
VERBATIM
USES_TERMINAL
COMMAND_EXPAND_LISTS
)
# This command is used to generate the final reports from the database and print the overall results
add_custom_target(eclair_summary_print ALL
COMMAND ${ECLAIR_REPORT}
-db=${ECLAIR_PROJECT_ECD} ${ECLAIR_REPORT_ADDITIONAL_OPTIONS}
-overall_txt=${ECLAIR_OUTPUT_DIR}/summary_overall.txt
COMMAND ${CMAKE_COMMAND} -E cat ${ECLAIR_OUTPUT_DIR}/summary_overall.txt
)
add_dependencies(eclair_summary_print eclair_report)