diff --git a/CMakeLists.txt b/CMakeLists.txt index b9d98bd4f52..5cba6ee3a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/modules/generic_toolchain.cmake b/cmake/modules/generic_toolchain.cmake index 15697517f68..821213e6d99 100644 --- a/cmake/modules/generic_toolchain.cmake +++ b/cmake/modules/generic_toolchain.cmake @@ -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")