cmake: sparse: deprecate old sparse support

Deprecate old sparse support as Zephyr now provides a proper
infrastructure for SCA tools. Set ZEPHYR_SCA_VARIANT to sparse if user
is using deprecated way.

This allows to cleanup sparse code in various places and thus have a
cleaner build system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2022-11-30 12:46:38 +01:00 committed by Stephanos Ioannidis
parent 91902c5fd4
commit 60196ca112
4 changed files with 15 additions and 46 deletions

View File

@ -301,12 +301,6 @@ if(CONFIG_COMPILER_COLOR_DIAGNOSTICS)
zephyr_compile_options($<TARGET_PROPERTY:compiler,diagnostic>)
endif()
if("${SPARSE}" STREQUAL "y")
list(APPEND TOOLCHAIN_C_FLAGS -D__CHECKER__)
# Avoid compiler "attribute directive ignored" warnings
list(APPEND TOOLCHAIN_C_FLAGS -Wno-attributes)
endif()
zephyr_compile_options(
${TOOLCHAIN_C_FLAGS}
)

View File

@ -5,39 +5,8 @@ set_ifndef(C++ g++)
# Configures CMake for using GCC, this script is re-used by several
# GCC-based toolchains
if("${SPARSE}" STREQUAL "y")
# No search PATHS because we need more than cgcc in the default PATH
find_program(CMAKE_C_COMPILER cgcc REQUIRED)
message(STATUS "Found sparse: ${CMAKE_C_COMPILER}")
find_program(SPARSE_REAL_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH REQUIRED)
# We know what REAL_CC _must_ be, so why do we ask the user to define it? Because CMake
# cannot set (evil) build time env variables at configure time:
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-get-or-set-environment-variables
# As of Sep. 2022, sparse/cgcc has unfortunately no --real-cc option as it should.
#
# In theory we could define REAL_CC ourselves here and fix the configure-time
# --print-file-name below (and maybe others). Then ask the user to define REAL_CC later
# at _build_ time. But in practice who would define environment variables at build time
# _only_? So best to fail early and clearly here.
if ("$ENV{REAL_CC}" STREQUAL "")
message(FATAL_ERROR
"The only way to override its 'cc' default when cross-compiling with sparse is "
"unfortunately an environment variable. So you _must_ set REAL_CC at both configuration "
"time and build time to: ${SPARSE_REAL_COMPILER}")
else() # check ENV{REAL_CC}
file(REAL_PATH "${SPARSE_REAL_COMPILER}" real_compiler_rp)
file(REAL_PATH "$ENV{REAL_CC}" env_real_cc_rp)
cmake_path(COMPARE "${real_compiler_rp}" EQUAL "${env_real_cc_rp}" expected_env_REAL_CC)
if(NOT expected_env_REAL_CC)
message(FATAL_ERROR
"Unexpected environment variable REAL_CC: $ENV{REAL_CC}, must be: ${SPARSE_REAL_COMPILER}")
endif()
endif()
else() # SPARSE
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
endif()
find_package(Deprecated COMPONENTS SPARSE)
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
if(${CMAKE_C_COMPILER} STREQUAL CMAKE_C_COMPILER-NOTFOUND)
message(FATAL_ERROR "C compiler ${CROSS_COMPILE}${CC} not found - Please check your toolchain installation")

View File

@ -66,12 +66,6 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
zephyr_get_include_directories_for_lang(C current_includes)
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
if("${SPARSE}" STREQUAL "y")
set(ld_command ${SPARSE_REAL_COMPILER})
else()
set(ld_command ${CMAKE_C_COMPILER})
endif()
add_custom_command(
OUTPUT ${linker_script_gen}
DEPENDS
@ -80,7 +74,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
${extra_dependencies}
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
${linker_script_dep}
COMMAND ${ld_command}
COMMAND ${CMAKE_C_COMPILER}
-x assembler-with-cpp
${NOSYSDEF_CFLAG}
-MD -MF ${linker_script_gen}.dep -MT ${linker_script_gen}

View File

@ -78,6 +78,18 @@ if("XTOOLS" IN_LIST Deprecated_FIND_COMPONENTS)
"Please set ZEPHYR_TOOLCHAIN_VARIANT to 'zephyr'")
endif()
if("SPARSE" IN_LIST Deprecated_FIND_COMPONENTS)
list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SPARSE)
# This code was deprecated after Zephyr v3.2.0
if(SPARSE)
message(DEPRECATION
"Setting SPARSE=${SPARSE} is deprecated. "
"Please set ZEPHYR_SCA_VARIANT to 'sparse'"
)
set_ifndef(ZEPHYR_SCA_VARIANT sparse)
endif()
endif()
if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS)
list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SOURCES)
if(SOURCES)