build: make non zephyr/ include prefix configurable

Add a Kconfig to disable non prefixed includes. By setting
`CONFIG_LEGACY_INCLUDE_PATH=n` developers can disable having
`include/zephyr` in the search path. This means that includes such
as `#include <kernel.h>` will no longer work.

Internally, every header should be updated to add the `zephyr/`
prefix to the headers. Only then, will developers be able to use
this config value for their applications.

Signed-off-by: Yuval Peress <peress@google.com>
This commit is contained in:
Yuval Peress 2022-03-31 21:05:42 -06:00 committed by Carles Cufí
parent 53ef68d459
commit 1ec0c6f530
9 changed files with 30 additions and 8 deletions

View file

@ -104,9 +104,12 @@ add_library(zephyr_interface INTERFACE)
# flags that come with zephyr_interface.
zephyr_library_named(zephyr)
if(CONFIG_LEGACY_INCLUDE_PATH)
zephyr_include_directories(include/zephyr)
endif()
zephyr_include_directories(
include
include/zephyr
${PROJECT_BINARY_DIR}/include/generated
${USERINCLUDE}
${STDINCLUDE}

View file

@ -800,3 +800,15 @@ config COMPAT_INCLUDES
deprecated header files.
endmenu
config LEGACY_INCLUDE_PATH
bool "Allow for the legacy include paths (without the zephyr/ prefix)"
default y
help
Allow applications and libraries to use the Zephyr legacy include
path which does not use the zephyr/ prefix. For example, the
preferred way to include a Zephyr header is to use <zephyr/kernel.h>,
but enabling CONFIG_LEGACY_INCLUDE_PATH will allow developers to
use <kernel.h> instead. This (without the zephyr/ prefix) is
deprecated and should be avoided. Eventually, it will not be
supported.

View file

@ -5,7 +5,8 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
-c ${CMAKE_C_COMPILER}
-o ${CMAKE_OBJCOPY}
-i ${ZEPHYR_BASE}/include
-i ${ZEPHYR_BASE}/include/zephyr
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}

View file

@ -3,7 +3,8 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/arch/x86/zefi/zefi.py
-c ${CMAKE_C_COMPILER}
-i ${ZEPHYR_BASE}/include
-i ${ZEPHYR_BASE}/include/zephyr
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
-o ${CMAKE_OBJCOPY}
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>

View file

@ -5,7 +5,8 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
-c ${CMAKE_C_COMPILER}
-o ${CMAKE_OBJCOPY}
-i ${ZEPHYR_BASE}/include
-i ${ZEPHYR_BASE}/include/zephyr
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}

View file

@ -34,8 +34,8 @@ gen_kobj(KOBJ_GEN_DIR)
list(APPEND INCLUDE
subsys/testsuite/ztest/include
subsys/testsuite/include
include
include/zephyr
include
.
)

View file

@ -928,8 +928,8 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.
EXCLUDE = @ZEPHYR_BASE@/include/portability/cmsis_os.h \
@ZEPHYR_BASE@/include/portability/cmsis_os2.h
EXCLUDE = @ZEPHYR_BASE@/include/zephyr/portability/cmsis_os.h \
@ZEPHYR_BASE@/include/zephyr/portability/cmsis_os2.h
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded

View file

@ -33,6 +33,7 @@ if(CONFIG_HAS_RPI_PICO)
-DZEPHYR_BASE=${ZEPHYR_BASE}
-DFLASH_TYPE=${flash_type}
-DPYTHON_EXECUTABLE=${Python3_EXECUTABLE}
-DCONFIG_LEGACY_INCLUDE_PATH=$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>
INSTALL_COMMAND "" # No installation needed
BUILD_BYPRODUCTS ${rp2_bootloader_prefix}/boot_stage2.S
BUILD_ALWAYS TRUE

View file

@ -38,9 +38,12 @@ target_include_directories(boot_stage2 PUBLIC
${rp2040_dir}/hardware_regs/include
${common_dir}/pico_base/include
${ZEPHYR_BASE}/include
${ZEPHYR_BASE}/include/zephyr
)
if(CONFIG_LEGACY_INCLUDE_PATH)
target_include_directories(boot_stage2 PUBLIC ${ZEPHYR_BASE}/include/zephyr)
endif()
target_link_options(boot_stage2 PRIVATE
"-nostartfiles"
"--specs=nosys.specs"