From 9a12f8b68b82874f7d76c7f42e9a52e36db99651 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Mon, 22 Aug 2022 16:45:23 +0200 Subject: [PATCH] cmake: move testing of compile flag in environment to top CMakeLists.txt 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 --- CMakeLists.txt | 11 +++++++++++ cmake/modules/generic_toolchain.cmake | 9 --------- 2 files changed, 11 insertions(+), 9 deletions(-) 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")