Skip to content

Commit 4ddbc00

Browse files
daor-otiaescolar
authored andcommitted
cmake: Toolchain abstraction: Introducing macro toolchain_cc_imacros
The macro is intended to abstract the -imacros compiler option for inclusion of the autoconf.h header file. The abstraction allows for a given toolchain to decide how the inclusion of the header file is to be done. The intent here is to abstract Zephyr's dependence on toolchains, thus allowing for easier porting to other, perhaps commercial, toolchains and/or usecases. No functional change expected. Signed-off-by: Danny Oerndrup <[email protected]>
1 parent 3189da5 commit 4ddbc00

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ endif()
214214
# @Intent: Set compiler specific flags for standard C includes
215215
toolchain_cc_nostdinc()
216216

217+
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
218+
toolchain_cc_imacros(${AUTOCONF_H})
219+
217220
# @Intent: Set compiler specific flag for bare metal freestanding option
218221
toolchain_cc_freestanding()
219222

220223
zephyr_compile_options(
221224
-g # TODO: build configuration enough?
222-
-imacros ${AUTOCONF_H}
223225
-fno-common
224226
${TOOLCHAIN_C_FLAGS}
225227
)

cmake/compiler/clang/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
8080
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
8181
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
8282
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake)
83+
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)
8384

8485
macro(toolchain_cc_security_fortify)
8586
# No op, clang doesn't understand fortify at all

cmake/compiler/gcc/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_cpp.cmake)
140140
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_asm.cmake)
141141
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_baremetal.cmake)
142142
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake)
143+
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_imacros.cmake)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# See root CMakeLists.txt for description and expectations of these macros
4+
5+
macro(toolchain_cc_imacros header_file)
6+
7+
zephyr_compile_options(-imacros ${header_file})
8+
9+
endmacro()

cmake/compiler/host-gcc/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
8989
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
9090
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
9191
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake)
92+
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)

cmake/compiler/xcc/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
8383
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
8484
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
8585
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake)
86+
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)

0 commit comments

Comments
 (0)