当前位置:网站首页>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
- Oracle 數據庫基本知識概念
- ArcGIS 镶嵌数据集切片丢失问题处理
- 记录一次换行符引起的bug
- CH423要如何使用,便宜的国产IO扩展芯片
- Concepts de base de données Oracle
- Solve the problem that only one line of text is displayed or not displayed in u8glib
- matlab数据类型 —— 字符型
- Sword finger offer 10- ii Frog jumping on steps
- Com. Faster XML. Jackson. DataBind. Exc.mismatchedinputexception: tableau ou chaîne attendu. At [Source: X
猜你喜欢

Batch generate folders based on file names

其他服务注册与发现

05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?

Ten thousand words explanation - mindarmour Xiaobai tutorial!

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

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

Memorizing byte order of big and small end

Solve the problem that only one line of text is displayed or not displayed in u8glib

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

Central Limit Theorem
随机推荐
Statistical Hypothesis Testing
07 | workflow design: how to design a reasonable multi person development mode?
寻找旋转排序数组中的最小值 II[经典抽象二分 + 如何破局左中右三者相等]
In depth understanding of UDP in the transport layer and the use of UDP in sockets
目前哪个证券公司炒股开户是最好最安全的?
How to write test cases and a brief introduction to go unit test tool testify
史上最难618,TCL夺得电视行业京东和天猫份额双第一
高清滑环生产过程当中的质量如何把控
墨者学院-X-Forwarded-For注入漏洞实战
Lambda expression
Kubeadm create kubernetes cluster
自定义MVC(导成jar包)+与三层架构的区别+反射+面试题
CH423要如何使用,便宜的国产IO扩展芯片
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
这10款文案神器帮你速码,做自媒体还担心写不出文案吗?
LeetCode 142. Circular linked list II
[vscode] setting sync, a plug-in for synchronizing extensions and settings
Freescale 单片机概述
气液滑环与其他滑环的工作原理有什么区别
温故知新--常温常新