# main/CMakeLists.txt # This command finds all .c files in the current directory (main/) # and recursively in all its subdirectories file(GLOB_RECURSE COMPONENT_SRCS "*.c") # Define the base include directory (the current directory of this CMakeLists.txt) set(COMPONENT_INCLUDE_DIRS_BASE "${CMAKE_CURRENT_SOURCE_DIR}") # Find all subdirectories within the current directory. # This ensures that only actual directories are added, not files. # 'RELATIVE' ensures the paths are relative, which is often cleaner, # but can also use 'ABSOLUTE' if preferred for debugging. file(GLOB_RECURSE SUB_DIRS_FOUND LIST_DIRECTORIES true FOLLOW_SYMLINKS "${CMAKE_CURRENT_SOURCE_DIR}/*/") # Combine the base directory and all found subdirectories for INCLUDE_DIRS # Ensure to filter out any non-directory results if GLOB_RECURSE sometimes yields them # (though LIST_DIRECTORIES true should prevent this for "*/" pattern) # For robustness, we can explicitly add each subdirectory set(COMPONENT_INCLUDE_DIRS "${COMPONENT_INCLUDE_DIRS_BASE}") # Start with current directory foreach(subdir ${SUB_DIRS_FOUND}) if(IS_DIRECTORY "${subdir}") list(APPEND COMPONENT_INCLUDE_DIRS "${subdir}") endif() endforeach() idf_component_register(SRCS "${COMPONENT_SRCS}" INCLUDE_DIRS "${COMPONENT_INCLUDE_DIRS}")