esp-idf/tools/cmake
Frantisek Hrbata 1ca9e63e79 tools: add target consistency checks to cmake
Extend target checks in cmake, in case it's run directly and not via
idf.py or if idf.py misses something. This may happen
for example if cmake variables are set in project's CMakeLists.txt.

Some clean-ups are included along with the new checks and tests.

1. __target_check() function is removed. IIUC it should never fail,
   because the selected target is explicitly passed as environmental
   variable to kconfgen. Meaning the IDF_TARGET from environment variable may
   not be actually used in kconfgen if IDF_TARGET is already set it cmake cache.
   Note that the IDF_TARGET environment variable used for kconfgen is not
   based on the actual IDF_TARGET environment variable set for idf.py, but
   rather on the value set in __target_init() with

	set(IDF_TARGET ${env_idf_target} CACHE STRING "IDF Build Target")

   My understanding is that the original check was introduced to handle
   situation, where IDF_TARGET was already set in cmake's cache and
   the IDF_TARGET from environment variable was different. Since
   the kconfgen would use the original environment variable(not
   explicitly passed as it is now) the IDF_TARGET in cmake and in
   sdkconfig could differ. IOW I think the original check was introduced
   to cope with the following cmake behaviour

	set(VARIABLE "value1" CACHE STRING "test variable")
	set(VARIABLE "value2" CACHE STRING "test variable")
	message("Variable value: ${VARIABLE}")
	output: Variable value: value1

2. I scratched by head how it is possible that the following code
   in __target_check()

   	if(NOT ${IDF_TARGET} STREQUAL ${env_idf_target})

   could fail if IDF_TARGET is not set. For example in clean project

	IDF_TARGET=esp32 idf.py reconfigure

   Here env_idf_target==esp32 and IDF_TARGET is not set, so I would
   expect that cmake will fail with error message that the cache
   and env target do not match. The thing is that the variable
   evaluation is done before the if command, so it actually
   sees this

   	if(NOT  STREQUAL esp32)

   which is false and the error is not printed. It can be seen
   with 'cmake --trace-expand' command. I don't know if this
   was used on purpose or it worked just as a coincidence, but
   I find it very confusing, so I added explicit check if the
   IDF_TARGET is defined before the actual check. Same for
   CMAKE_TOOLCHAIN_FILE.

3. Error messages are not formated(line-wrapped) by cmake's markup
   so it's easier to check the output in tests.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2023-03-08 16:45:47 +01:00
..
scripts build & config: Don't include common components on early expansion 2022-05-30 14:34:30 +02:00
third_party Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
build.cmake tools: add target consistency checks to cmake 2023-03-08 16:45:47 +01:00
component_deps.dot.in G0: add a build example to check G0 dependencies 2022-06-14 15:00:53 +08:00
component.cmake build system: Add idf_component_add_link_dependency function, use for spi_flash overriding 2022-12-16 16:26:44 +01:00
depgraph.cmake cmake: add component dependency graph generation helpers 2021-12-02 15:29:00 +01:00
dfu.cmake ESP32-H2: Introduce new target for ESP32H2 2022-11-23 14:38:05 +08:00
git_submodules.cmake CI: build system do not check submodule for CI 2019-12-08 20:32:10 +08:00
idf.cmake tools: cmake: check tool supported version with idf_tools.py 2022-10-03 19:01:32 +04:00
kconfig.cmake tools: Move out kconfig_new in favour of using the esp-idf-kconfig package 2022-11-15 21:19:51 +01:00
ldgen.cmake build system: fix quoting of fragments list passed to ldgen 2021-12-14 19:17:53 +01:00
project_description.json.in feature: add build framework support 2023-02-01 17:57:25 +08:00
project.cmake tools: cmake: ignore linker RWX segment warnings 2023-02-22 05:33:03 +00:00
run_dfu_util.cmake tools: Increase the minimal supported CMake version to 3.16 2022-06-01 06:35:02 +00:00
run_size_tool.cmake tools: Add --output-file argument to idf.py size commands 2022-09-27 15:41:36 +02:00
targets.cmake tools: add target consistency checks to cmake 2023-03-08 16:45:47 +01:00
tool_version_check.cmake tools: cmake: check tool supported version with idf_tools.py 2022-10-03 19:01:32 +04:00
toolchain-clang-esp32.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-clang-esp32c2.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-clang-esp32c3.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-clang-esp32c6.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-clang-esp32h2.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-clang-esp32s2.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-clang-esp32s3.cmake build: Adds support for universal Clang toolchain 2022-11-23 13:25:16 +03:00
toolchain-esp32.cmake Build: Xtensa assembly files are now assembled with -mlongcalls option 2022-06-20 13:56:49 +08:00
toolchain-esp32c2.cmake tools: add riscv zicsr/zifencei because they were separated from i 2023-02-22 05:33:03 +00:00
toolchain-esp32c3.cmake tools: add riscv zicsr/zifencei because they were separated from i 2023-02-22 05:33:03 +00:00
toolchain-esp32c6.cmake tools: add riscv zicsr/zifencei because they were separated from i 2023-02-22 05:33:03 +00:00
toolchain-esp32h2.cmake tools: change esp32h2 march to rv32imac_zicsr_zifencei 2023-02-22 05:33:03 +00:00
toolchain-esp32h4.cmake tools: add riscv zicsr/zifencei because they were separated from i 2023-02-22 05:33:03 +00:00
toolchain-esp32s2.cmake Build: Xtensa assembly files are now assembled with -mlongcalls option 2022-06-20 13:56:49 +08:00
toolchain-esp32s3.cmake Build: Xtensa assembly files are now assembled with -mlongcalls option 2022-06-20 13:56:49 +08:00
toolchain-linux.cmake build system: don't add GCC-specific options when building with clang 2021-01-24 12:48:29 +01:00
uf2.cmake esp32h2: renaming esp32h2 to esp32h4 2022-11-08 17:05:33 +08:00
utilities.cmake cmake: use target_link_options and _directories supported since 3.13 2022-09-20 11:08:02 +02:00
version.cmake versions: Update version to 5.1.0 2022-08-04 09:55:43 +02:00