Skip to content

Commit 1ec0c6f

Browse files
Yuval Peresscarlescufi
authored andcommitted
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 <[email protected]>
1 parent 53ef68d commit 1ec0c6f

File tree

9 files changed

+30
-8
lines changed

9 files changed

+30
-8
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ add_library(zephyr_interface INTERFACE)
104104
# flags that come with zephyr_interface.
105105
zephyr_library_named(zephyr)
106106

107+
if(CONFIG_LEGACY_INCLUDE_PATH)
108+
zephyr_include_directories(include/zephyr)
109+
endif()
110+
107111
zephyr_include_directories(
108112
include
109-
include/zephyr
110113
${PROJECT_BINARY_DIR}/include/generated
111114
${USERINCLUDE}
112115
${STDINCLUDE}

Kconfig.zephyr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,15 @@ config COMPAT_INCLUDES
800800
deprecated header files.
801801

802802
endmenu
803+
804+
config LEGACY_INCLUDE_PATH
805+
bool "Allow for the legacy include paths (without the zephyr/ prefix)"
806+
default y
807+
help
808+
Allow applications and libraries to use the Zephyr legacy include
809+
path which does not use the zephyr/ prefix. For example, the
810+
preferred way to include a Zephyr header is to use <zephyr/kernel.h>,
811+
but enabling CONFIG_LEGACY_INCLUDE_PATH will allow developers to
812+
use <kernel.h> instead. This (without the zephyr/ prefix) is
813+
deprecated and should be avoided. Eventually, it will not be
814+
supported.

boards/x86/ehl_crb/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
55
-c ${CMAKE_C_COMPILER}
66
-o ${CMAKE_OBJCOPY}
77
-i ${ZEPHYR_BASE}/include
8-
-i ${ZEPHYR_BASE}/include/zephyr
8+
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
9+
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
910
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
1011
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
1112
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}

boards/x86/qemu_x86/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
33
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/arch/x86/zefi/zefi.py
44
-c ${CMAKE_C_COMPILER}
55
-i ${ZEPHYR_BASE}/include
6-
-i ${ZEPHYR_BASE}/include/zephyr
6+
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
7+
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
78
-o ${CMAKE_OBJCOPY}
89
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
910
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>

boards/x86/up_squared/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
55
-c ${CMAKE_C_COMPILER}
66
-o ${CMAKE_OBJCOPY}
77
-i ${ZEPHYR_BASE}/include
8-
-i ${ZEPHYR_BASE}/include/zephyr
8+
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
9+
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
910
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
1011
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
1112
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}

cmake/modules/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ gen_kobj(KOBJ_GEN_DIR)
3434
list(APPEND INCLUDE
3535
subsys/testsuite/ztest/include
3636
subsys/testsuite/include
37-
include
3837
include/zephyr
38+
include
3939
.
4040
)
4141

doc/zephyr.doxyfile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,8 @@ RECURSIVE = YES
928928
# Note that relative paths are relative to the directory from which doxygen is
929929
# run.
930930

931-
EXCLUDE = @ZEPHYR_BASE@/include/portability/cmsis_os.h \
932-
@ZEPHYR_BASE@/include/portability/cmsis_os2.h
931+
EXCLUDE = @ZEPHYR_BASE@/include/zephyr/portability/cmsis_os.h \
932+
@ZEPHYR_BASE@/include/zephyr/portability/cmsis_os2.h
933933

934934
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
935935
# directories that are symbolic links (a Unix file system feature) are excluded

modules/hal_rpi_pico/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ if(CONFIG_HAS_RPI_PICO)
3333
-DZEPHYR_BASE=${ZEPHYR_BASE}
3434
-DFLASH_TYPE=${flash_type}
3535
-DPYTHON_EXECUTABLE=${Python3_EXECUTABLE}
36+
-DCONFIG_LEGACY_INCLUDE_PATH=$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>
3637
INSTALL_COMMAND "" # No installation needed
3738
BUILD_BYPRODUCTS ${rp2_bootloader_prefix}/boot_stage2.S
3839
BUILD_ALWAYS TRUE

modules/hal_rpi_pico/bootloader/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ target_include_directories(boot_stage2 PUBLIC
3838
${rp2040_dir}/hardware_regs/include
3939
${common_dir}/pico_base/include
4040
${ZEPHYR_BASE}/include
41-
${ZEPHYR_BASE}/include/zephyr
4241
)
4342

43+
if(CONFIG_LEGACY_INCLUDE_PATH)
44+
target_include_directories(boot_stage2 PUBLIC ${ZEPHYR_BASE}/include/zephyr)
45+
endif()
46+
4447
target_link_options(boot_stage2 PRIVATE
4548
"-nostartfiles"
4649
"--specs=nosys.specs"

0 commit comments

Comments
 (0)