diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 92acd5965..b2f9cae7f 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -279,6 +279,18 @@ function run_tests() mv CMakeLists.bak CMakeLists.txt assert_built ${APP_BINS} ${BOOTLOADER_BINS} ${PARTITION_BIN} + print_status "Setting EXTRA_COMPONENT_DIRS works" + clean_build_dir + mkdir -p main/main/main # move main component contents to another directory + mv main/* main/main/main + cp CMakeLists.txt CMakeLists.bak # set EXTRA_COMPONENT_DIRS to point to the other directory + sed -i "s%cmake_minimum_required(VERSION \([0-9]\+\).\([0-9]\+\))%cmake_minimum_required(VERSION \1.\2)\nset(EXTRA_COMPONENT_DIRS main/main/main)%" CMakeLists.txt + idf.py build || failure "Build with EXTRA_COMPONENT_DIRS set failed" + mv CMakeLists.bak CMakeLists.txt # revert previous modifications + mv main/main/main/* main + rm -rf main/main + assert_built ${APP_BINS} ${BOOTLOADER_BINS} ${PARTITION_BIN} + print_status "All tests completed" if [ -n "${FAILURES}" ]; then echo "Some failures were detected:" diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 679023e48..034566e7f 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -18,25 +18,31 @@ endfunction() macro(project name) - # Bridge existing documented variable names with library namespaced variables in order for old projects to work. + # Bridge existing documented variable names with library namespaced + # variables in order for old projects to work. + if(COMPONENT_DIRS) spaces2list(COMPONENT_DIRS) foreach(component_dir ${COMPONENT_DIRS}) - get_filename_component(full_path ${component_dir} ABSOLUTE) - get_filename_component(idf_path "${IDF_PATH}/components" ABSOLUTE) - - if(NOT full_path STREQUAL idf_path) - set(IDF_EXTRA_COMPONENT_DIRS "${IDF_EXTRA_COMPONENT_DIRS} ${component_dir}") - endif() + get_filename_component(component_dir ${component_dir} ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR}) + list(APPEND IDF_COMPONENT_DIRS "${component_dir}") endforeach() - else() - if(MAIN_SRCS) - set(IDF_EXTRA_COMPONENT_DIRS "${EXTRA_COMPONENT_DIRS} ${CMAKE_SOURCE_DIR}/components") - else() - set(IDF_EXTRA_COMPONENT_DIRS "${EXTRA_COMPONENT_DIRS} \ - ${CMAKE_SOURCE_DIR}/components ${CMAKE_SOURCE_DIR}/main") - endif() + endif() + + if(EXTRA_COMPONENT_DIRS) + spaces2list(EXTRA_COMPONENT_DIRS) + + foreach(component_dir ${EXTRA_COMPONENT_DIRS}) + get_filename_component(component_dir ${component_dir} ABSOLUTE BASE_DIR ${CMAKE_SOURCE_DIR}) + list(APPEND IDF_EXTRA_COMPONENT_DIRS "${component_dir}") + endforeach() + endif() + + list(APPEND IDF_EXTRA_COMPONENT_DIRS "${CMAKE_SOURCE_DIR}/components") + + if(NOT MAIN_SRCS) + list(APPEND IDF_EXTRA_COMPONENT_DIRS "${CMAKE_SOURCE_DIR}/main") endif() if(COMPONENTS)