当前位置:网站首页>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
- Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
- Solution of idea hot start failure
- Encapsulation of unified result set
- Implementation of ARP module in LwIP
- Unable to create a folder to save the sketch: MKDIR sketch
- One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial
- 这3个并发编程的核心,竟然还有人不知道?
- Law of Large Numbers
- 滑环选型选购时需要注意的技巧
猜你喜欢

com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x

剑指 Offer 10- II. 青蛙跳台阶问题

Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022

CH423要如何使用,便宜的国产IO扩展芯片

如何把老式键盘转换成USB键盘并且自己编程?

【UVM实战 ===> Episode_3 】~ Assertion、Sequence、Property
![[vscode] setting sync, a plug-in for synchronizing extensions and settings](/img/e0/4889b59105e9815d11ae31988f58f2.jpg)
[vscode] setting sync, a plug-in for synchronizing extensions and settings

Ten thousand words explanation - mindarmour Xiaobai tutorial!

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

About Random Numbers
随机推荐
Is there anyone who doesn't know the three cores of concurrent programming?
Generate flow chart with code, and how to use markdown
如何把老式键盘转换成USB键盘并且自己编程?
Unable to create a folder to save the sketch: MKDIR sketch
Memorizing byte order of big and small end
Lambda表达式
Is it safe for CITIC Securities Commission to open an online account and speculate in stocks
05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?
Batch generate folders based on file names
大白话高并发(一)
07 | workflow design: how to design a reasonable multi person development mode?
解决unable to create a folder to save the sketch: mkdir sketch
Great health industry annual must attend event, 2022 Shandong International Great Health Industry Expo
At present, which securities company is the best and safest to open an account for stock speculation?
test
墨者学院-X-Forwarded-For注入漏洞实战
3 - wire SPI Screen Drive
滑环选型选购时需要注意的技巧
05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
解决STC8G1K08程序不能运行的问题和端口配置