Skip to content

Commit

Permalink
cmake: move testing of compile flag in environment to top CMakeLists.txt
Browse files Browse the repository at this point in the history
This moves the test of compile flags set in environment from generic
toolchain to top-level ${ZEPHYR_BASE}/CMakeLists.txt.

In order to cleanup and make Zephyr CMake modules more generic then
the testing of specific compile flags and warn user is not really a
toolchain module responsible but a implementation detail of the project
itself as to how compile flags should be applied in a project.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
  • Loading branch information
tejlmand authored and carlescufi committed Sep 1, 2022
1 parent 356960b commit 9a12f8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ foreach(optional_include_dir
endif()
endforeach()

# Don't inherit compiler flags from the environment
foreach(var AFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS)
if(DEFINED ENV{${var}})
message(WARNING "The environment variable '${var}' was set to $ENV{${var}}, "
"but Zephyr ignores flags from the environment. Use 'cmake "
"-DEXTRA_${var}=$ENV{${var}}' instead."
)
unset(ENV{${var}})
endif()
endforeach()

zephyr_compile_definitions(
KERNEL
__ZEPHYR__=1
Expand Down
9 changes: 0 additions & 9 deletions cmake/modules/generic_toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ if(NOT TOOLCHAIN_ROOT)
endif()
zephyr_file(APPLICATION_ROOT TOOLCHAIN_ROOT)

# Don't inherit compiler flags from the environment
foreach(var AFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS)
if(DEFINED ENV{${var}})
message(WARNING "The environment variable '${var}' was set to $ENV{${var}},
but Zephyr ignores flags from the environment. Use 'cmake -DEXTRA_${var}=$ENV{${var}}' instead.")
unset(ENV{${var}})
endif()
endforeach()

# Host-tools don't unconditionally set TOOLCHAIN_HOME anymore,
# but in case Zephyr's SDK toolchain is used, set TOOLCHAIN_HOME
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "zephyr")
Expand Down

0 comments on commit 9a12f8b

Please sign in to comment.