cmake: compiler: Add framework for disabling C++ standard includes

This commit adds a new C++ compiler property `nostdincxx` which
specifies the C++ compiler flag for excluding the C++ standard library
include directory from the include paths.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
Stephanos Ioannidis 2021-09-11 22:06:28 +09:00 committed by Anas Nashif
parent 80681d2984
commit fd4700d7b7
2 changed files with 8 additions and 1 deletions

View file

@ -1675,13 +1675,17 @@ if((CMAKE_BUILD_TYPE IN_LIST build_types) AND (NOT NO_BUILD_TYPE_WARNING))
endif()
endif()
# @Intent: Set compiler specific flags for standard C includes
# @Intent: Set compiler specific flags for standard C/C++ includes
# Done at the very end, so any other system includes which may
# be added by Zephyr components were first in list.
# Note, the compile flags are moved, but the system include is still present here.
zephyr_compile_options($<TARGET_PROPERTY:compiler,nostdinc>)
target_include_directories(zephyr_interface SYSTEM INTERFACE $<TARGET_PROPERTY:compiler,nostdinc_include>)
if(NOT CONFIG_LIB_CPLUSPLUS)
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,nostdincxx>>)
endif()
# Finally export all build flags from Zephyr
add_subdirectory_ifdef(
CONFIG_MAKEFILE_EXPORTS

View file

@ -50,6 +50,9 @@ set_compiler_property(PROPERTY cstd)
set_compiler_property(PROPERTY nostdinc)
set_compiler_property(PROPERTY nostdinc_include)
# Compiler flags for disabling C++ standard include.
set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx)
# Required C++ flags when compiling C++ code
set_property(TARGET compiler-cpp PROPERTY required)