Skip to content

Commit

Permalink
cmake: Toolchain abstraction: Introducing macro toolchain_cc_imacros
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
daor-oti authored and aescolar committed Jun 12, 2019
1 parent 3189da5 commit 4ddbc00
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@ endif()
# @Intent: Set compiler specific flags for standard C includes
toolchain_cc_nostdinc()

# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
toolchain_cc_imacros(${AUTOCONF_H})

# @Intent: Set compiler specific flag for bare metal freestanding option
toolchain_cc_freestanding()

zephyr_compile_options(
-g # TODO: build configuration enough?
-imacros ${AUTOCONF_H}
-fno-common
${TOOLCHAIN_C_FLAGS}
)
Expand Down
1 change: 1 addition & 0 deletions cmake/compiler/clang/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)

macro(toolchain_cc_security_fortify)
# No op, clang doesn't understand fortify at all
Expand Down
1 change: 1 addition & 0 deletions cmake/compiler/gcc/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_cpp.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_asm.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_baremetal.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_imacros.cmake)
9 changes: 9 additions & 0 deletions cmake/compiler/gcc/target_imacros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

# See root CMakeLists.txt for description and expectations of these macros

macro(toolchain_cc_imacros header_file)

zephyr_compile_options(-imacros ${header_file})

endmacro()
1 change: 1 addition & 0 deletions cmake/compiler/host-gcc/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)
1 change: 1 addition & 0 deletions cmake/compiler/xcc/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake)
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)

0 comments on commit 4ddbc00

Please sign in to comment.