Merge branch 'fix/cmake_flags_passing_to_external_project_v5.5' into 'release/v5.5'

fix(build): fix passing CMAKE_<LANG>_FLAGS from ExternalProject_Add (v5.5)

See merge request espressif/esp-idf!46654
This commit is contained in:
Alexey Gerenkov
2026-03-30 21:37:58 +08:00
13 changed files with 118 additions and 7 deletions
@@ -16,6 +16,12 @@ tools/test_apps/build_system/embed_test:
temporary: false
reason: Hardware independent feature, no need to test on all targets
tools/test_apps/build_system/external_project:
enable:
- if: IDF_TARGET in ["esp32", "esp32c3"]
temporary: false
reason: Verifies toolchain preserves CMAKE_*_FLAGS in ExternalProject_Add context
tools/test_apps/build_system/ld_non_contiguous_memory:
disable:
- if: SOC_MEM_NON_CONTIGUOUS_SRAM != 1 # TODO: IDF-13411, since P4 REV2, the SRAM is contiguous
@@ -0,0 +1,10 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.22)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Trim the build. Include the minimal set of components, main, and anything it depends on.
set(COMPONENTS main)
project(external_project)
@@ -0,0 +1,2 @@
| Supported Targets | ESP32 | ESP32-C3 |
| ----------------- | ----- | -------- |
@@ -0,0 +1,19 @@
idf_component_register()
include(ExternalProject)
externalproject_add(ext_subproject
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/subproject
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_C_FLAGS=-DEXTERNAL_PROJECT_FLAG=1
-DCMAKE_CXX_FLAGS=-DEXTERNAL_PROJECT_CXX_FLAG=1
-DCMAKE_ASM_FLAGS=-DEXTERNAL_PROJECT_ASM_FLAG=1
-DCMAKE_EXE_LINKER_FLAGS=-Wl,--defsym=EXTERNAL_PROJECT_LINKER_CHECK=1
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/subproject"
INSTALL_COMMAND ""
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/subproject/libext_lib.a"
)
add_prebuilt_library(ext_lib "${CMAKE_CURRENT_BINARY_DIR}/subproject/libext_lib.a")
target_link_libraries(${COMPONENT_LIB} INTERFACE ext_lib)
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.22)
project(ext_subproject LANGUAGES C CXX ASM)
add_library(ext_lib STATIC check_flag.c check_flag.cpp check_flag.S)
add_executable(ext_link_test link_check.c)
target_link_libraries(ext_link_test PRIVATE ext_lib)
@@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef EXTERNAL_PROJECT_ASM_FLAG
#error "EXTERNAL_PROJECT_ASM_FLAG not defined - toolchain did not preserve CMAKE_ASM_FLAGS from ExternalProject_Add"
#endif
@@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef EXTERNAL_PROJECT_FLAG
#error "EXTERNAL_PROJECT_FLAG not defined - toolchain did not preserve CMAKE_C_FLAGS from ExternalProject_Add"
#endif
@@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef EXTERNAL_PROJECT_CXX_FLAG
#error "EXTERNAL_PROJECT_CXX_FLAG not defined - toolchain did not preserve CMAKE_CXX_FLAGS from ExternalProject_Add"
#endif
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
extern char EXTERNAL_PROJECT_LINKER_CHECK;
int _start(void)
{
return (int)&EXTERNAL_PROJECT_LINKER_CHECK;
}
@@ -0,0 +1,2 @@
idf_component_register(SRCS "test_main.c"
REQUIRES ext_component)
@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
void app_main(void)
{
printf("external_project test OK\n");
}