当前位置:网站首页>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
边栏推荐
- Statistical Hypothesis Testing
- Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
- 當Transformer遇見偏微分方程求解
- 墨者学院-SQL注入漏洞测试(报错盲注)
- Overview of Freescale MCU
- 如何写好测试用例以及go单元测试工具testify简单介绍
- Play OLED, u8g2 animation, increasing numbers, random triangles, etc
- C#程序结构预览最基础入门
- Sword finger offer 10- ii Frog jumping on steps
- Gaussian and Summary Stats
猜你喜欢

CH423要如何使用,便宜的国产IO扩展芯片
![The [MySQL] time field is set to the current time by default](/img/40/5f1d3448259ab703c4b5dc29713a99.png)
The [MySQL] time field is set to the current time by default

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

超越锂电池——未来电池的概念

Lambda表达式

【Vscode】预览md文件

Esp32-solo development tutorial to solve config_ FREERTOS_ UNICORE problem

史上最难618,TCL夺得电视行业京东和天猫份额双第一

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

Lwip之ARP模块实现
随机推荐
Simulation of delta variant strain of novel coronavirus (mindsponge application)
Pet hospital management system based on SSMP
The [MySQL] time field is set to the current time by default
Database interview questions +sql statement analysis
Lorsque le transformateur rencontre l'équation différentielle partielle
温故知新--常温常新
MATLAB data type - character type
Is it safe for CITIC Securities Commission to open an online account and speculate in stocks
Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
Hid device descriptor and keyboard key value corresponding coding table in USB protocol
解决unable to create a folder to save the sketch: mkdir sketch
[vscode] setting sync, a plug-in for synchronizing extensions and settings
Solve the problem that only one line of text is displayed or not displayed in u8glib
What is the difference between the working principle of gas-liquid slip ring and other slip rings
2022健康博览会,山东养生保健展会,产后健康、睡眠健康展
指南针开户安全的吗?
One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial
Gaussian and Summary Stats
Ten thousand words explanation - mindarmour Xiaobai tutorial!
CPU exception handling