当前位置:网站首页>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
边栏推荐
- Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
- Pet hospital management system based on SSMP
- JSON解析,ESP32轻松获取时间气温和天气
- matlab数据类型 —— 字符型
- Central Limit Theorem
- buuctf-pwn write-ups (6)
- 07 | 工作流设计:如何设计合理的多人开发模式?
- 小白看MySQL--windows环境安装MySQL
- How to use ch423? Cheap domestic IO expansion chip
- 统一结果集的封装
猜你喜欢

ESP32实验-自建web服务器配网02

Gaussian and Summary Stats

MATLAB data type - character type

Flink 实战问题(七):No Watermark(Watermarks are only available EventTime is used)

滑环安装有哪些技巧和方法

Memorizing byte order of big and small end

07 | workflow design: how to design a reasonable multi person development mode?

Review the old and know the new -- constant renewal at normal temperature

Ten thousand words explanation - mindarmour Xiaobai tutorial!

In depth understanding of UDP in the transport layer and the use of UDP in sockets
随机推荐
Simulation of delta variant strain of novel coronavirus (mindsponge application)
剑指 Offer 10- II. 青蛙跳台阶问题
Lambda expression
com. fasterxml. jackson. databind. exc.MismatchedInputException: Expected array or string. at [Source:x
matlab数据类型 —— 字符型
气液滑环与其他滑环的工作原理有什么区别
Generate flow chart with code, and how to use markdown
超越锂电池——未来电池的概念
如何把老式键盘转换成USB键盘并且自己编程?
大健康行业年度必参盛会,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
目前哪个证券公司炒股开户是最好最安全的?
Xiaobai looks at MySQL -- installing MySQL in Windows Environment
JSON parsing, esp32 easy access to time, temperature and weather
Great health industry annual must attend event, 2022 Shandong International Great Health Industry Expo
Overview of Freescale MCU