From 13dc32328ca71450b7af63c8de46fff48b6eeee7 Mon Sep 17 00:00:00 2001 From: Ferdinand Bachmann Date: Thu, 8 Jan 2026 16:35:27 +0100 Subject: [PATCH] fix(cmake): Fix "IMPORTED_LOCATION not set for imported target" errors esp-idf uses imported targets as dummy targets that are never linked. Previous CMake versions would ignore these and not error on unset IMPORTED_LOCATION if they are never actually linked. CMake 4.2 and newer errors during codemodel-v2 api queries when imported targets are missing IMPORTED_LOCATION, so set a dummy location that would error when actually linked, which fixes the error during api queries. Closes https://github.com/espressif/esp-idf/pull/18103 --- tools/cmake/build.cmake | 2 ++ tools/cmake/component.cmake | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 64a37bf694..00809c8907 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -209,6 +209,8 @@ function(__build_init idf_path) # Create the build target, to which the ESP-IDF build properties, dependencies are attached to. # Must be global so as to be accessible from any subdirectory in custom projects. add_library(__idf_build_target STATIC IMPORTED GLOBAL) + # Set the IMPORTED_LOCATION property to avoid errors on IDE codemodel queries with CMake >=4.2 + set_property(TARGET __idf_build_target PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dummy.a") # Set the Python path (which may be passed in via -DPYTHON=) and store in a build property set_default(PYTHON "python") diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index e4d445cf65..23eacee26c 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -166,6 +166,8 @@ function(__component_add component_dir prefix component_source) if(NOT component_target IN_LIST component_targets) if(NOT TARGET ${component_target}) add_library(${component_target} STATIC IMPORTED) + # Set the IMPORTED_LOCATION property to avoid errors on IDE codemodel queries with CMake >=4.2 + set_property(TARGET ${component_target} PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dummy.a") endif() idf_build_set_property(__COMPONENT_TARGETS ${component_target} APPEND) else()