当前位置:网站首页>Esp32 add multi directory custom component
Esp32 add multi directory custom component
2022-06-27 00:56:00 【NULL_ one thousand nine hundred and sixty-nine】
Preface
stay esp32 In development , In general, it is vscode. Didn't like keil mdk And so on , I'm not familiar with it cmake People are not very friendly . The author also referred to cmake Official documents and esp32 Development Manual , Find a very effective and simple CmakeList.txt The way of writing .
esp32 Project directory

esp The official recommended directory format is two folders , One is main Folder , One is components Folder , The names of these two folders are not recommended to be changed , These two are esp32 The development environment defaults to main Module and components modular .
esp32 Adopted cmake Compiler tools . When you add a new file, you need to write it yourself cmakelist.txt. The main point here is components Folder .
components Folder

components Each subfolder under the folder esp-idf The environment will think of it as a module . Like in the picture above a,lvgl,sda It's all a module . You need to create a new one under the root directory of each sub module CMakeLists.txt. For example, above a There is one in the catalog CMakeLists.txt, Just this one .mk Documents are unnecessary .a Only put the source code you need in the subdirectory of , No more CMakeLists.txt. Here's the picture :
modular a Yes 3 The specific relationship of subdirectories is as follows :

modular a There are multiple subdirectories and the subdirectories contain .h and .c file , that Cmakelists.txt How to write it? .
file(GLOB_RECURSE SOURCES src_a/*.c src_b/*.c)
set(include_dirs
inc_a
src_a
src_a/src_c
)
idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS ${include_dirs})
Above is the module a Of Cmakelists.txt The full text , Isn't that neat . Specific analysis of the project .
Let's start with the simplest set.set Is to assign a value to a variable , It's going to be inc_a src_a src_a/src_c These three folders are assigned to include_dirs. Just add the header file folder you need to use to set Just inside . adopt “$” To obtain include_dirs The value of the variable . This linux Next bash Grammar is the same .
idf_component_register This is a esp-idf Commands for adding modules , Here, you usually add source files and header files , Use them separately SRCS and INCLUDE_DIRS Keyword representation , These two keywords can be followed by multiple Variable
such as :
idf_component_register(SRCS ${SOURCES} "123.c"
INCLUDE_DIRS ${include_dirs} . "123.h" "inc_a"
)
- "." Represents the file in the current directory
- INCLUDE_DIRS It can be directly followed by the directory name
- SRCS It must be followed by specific documents , You cannot use a directory instead of , This tested directory is invalid , So when there are multiple in the module .c file , Follow the above method to add one by one .c file . It's too troublesome , If there's a lot of .c file , That's too much work , however esp32 There is no specific method in the development manual of . But there must be a way to make .c Files are indexed as directories .
After Baidu and a large number of tests , serviceable file This command . For a detailed explanation, see https://cmake.org/cmake/help/latest/command/file.html
file The command has two main syntax when it is used in the file system
file(GLOB <variable>
[LIST_DIRECTORIES true|false] [RELATIVE <path>] [CONFIGURE_DEPENDS]
[<globbing-expressions>...])
file(GLOB_RECURSE <variable> [FOLLOW_SYMLINKS]
[LIST_DIRECTORIES true|false] [RELATIVE <path>] [CONFIGURE_DEPENDS]
[<globbing-expressions>...])
The official interpretation of this order is , Generate a list of compliance rules , And assign the list to . It is not officially recommended that GLOB command , The command cannot read the self index of the index .
If you will file(GLOB_RECURSE SOURCES src_a/.c src_b/.c) Medium GLOB_RECURSE Change it to GLOB , Compilation will not succeed , Show that... Can't be found sumc function ,sumc Function in src_a/src_c Under the folder .
At that time, there was still a problem
When a new .c File to src_a Next time , Need to edit again Cmakelists.txt, The newly added can be recognized normally when compiling .c file , We haven't found a way to update automatically yet .
add to LVG Components
At that time, the purpose of studying this method was to keep lvgl.lvgl8.2 The directory structure of is as follows ;
among CMakeLists.txt The contents are as follows :
file(GLOB_RECURSE SOURCES src/*.c examples/porting/*.c )
set(included_dirs src examples/porting)
idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS ${included_dirs}
)
adopt file This method can be very convenient to add a large number of .c Source file . The items of this experiment are shown in :
https://download.csdn.net/download/sinat_36568888/85751343
边栏推荐
- 数字格式化的 js 库
- 其他服务注册与发现
- Lwip之定时机制
- 05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
- Lwip之ARP模块实现
- 07 | 工作流设计:如何设计合理的多人开发模式?
- Interface test framework practice (I) | requests and interface request construction
- 小白看MySQL--windows环境安装MySQL
- How to convert an old keyboard into a USB keyboard and program it yourself?
- Using physical information neural network to solve hydrodynamics equations
猜你喜欢

One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial

高清滑环生产过程当中的质量如何把控

墨者学院-X-Forwarded-For注入漏洞实战

Simulation of delta variant strain of novel coronavirus (mindsponge application)

07 | 工作流设计:如何设计合理的多人开发模式?

Other service registration and discovery

05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?

Gaussian and Summary Stats

其他服务注册与发现

解决STC8G1K08程序不能运行的问题和端口配置
随机推荐
Batch generate folders based on file names
Solution of idea hot start failure
LeetCode 142. 环形链表 II
Using physical information neural network to solve hydrodynamics equations
Operating instructions and Q & A of cec-i China learning machine
如何写好测试用例以及go单元测试工具testify简单介绍
find_circ详细使用指南
记录一次换行符引起的bug
Central Limit Theorem
指南针开户安全的吗?
Reading graph augmentations to learn graph representations (lg2ar)
Lwip之定时机制
大健康行业年度必参盛会,2022山东国际大健康产业博览会
Is there anyone who doesn't know the three cores of concurrent programming?
Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
Other service registration and discovery
How to use ch423? Cheap domestic IO expansion chip
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
Law of Large Numbers
解决u8glib只显示一行文字或者不显示的问题