feat(cmakev2/test): add simple test for component include

Add two project components, component1 and component2, and verify that
their real targets are created when they are included.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-11-04 07:48:12 +01:00
parent ba78e62bcf
commit ff432c3e5a
7 changed files with 71 additions and 0 deletions
+21
View File
@@ -180,6 +180,26 @@ function(test_project_properties)
endif()
endfunction()
# Test that the targets for component1 and component2 are created when
# component2 is included.
function(test_include_component)
idf_build_library(INTERFACE idflibtest3 COMPONENTS component2)
idf_component_get_property(component_real_target
component2
COMPONENT_REAL_TARGET)
if(NOT TARGET ${component_real_target})
idf_die("Missing component2 target")
endif()
# Test that component1 is included as a dependency of component2.
idf_component_get_property(component_real_target
component1
COMPONENT_REAL_TARGET)
if(NOT TARGET ${component_real_target})
idf_die("Missing component1 target")
endif()
endfunction()
# Run tests
test_component_priority()
test_idf_version()
@@ -188,6 +208,7 @@ test_toolchain()
test_idf_build_library()
test_kconfig()
test_project_properties()
test_include_component()
__dump_all_properties()
message("ALL TESTS PASSED")
@@ -0,0 +1,2 @@
add_library(${COMPONENT_TARGET} component1.c)
target_include_directories(${COMPONENT_TARGET} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
void component1_func(void)
{
printf("component1\n");
}
@@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _COMPONENT1_H_
#define _COMPONENT1_H_
void component1_func(void);
#endif
@@ -0,0 +1,5 @@
idf_component_include(component1 INTERFACE component1)
add_library(${COMPONENT_TARGET} component2.c)
target_include_directories(${COMPONENT_TARGET} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(${COMPONENT_TARGET} PRIVATE ${component1})
@@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "component1.h"
void component2_func(void)
{
component1_func();
printf("component2\n");
}
@@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _COMPONENT2_H_
#define _COMPONENT2_H_
void component2_func(void);
#endif