cmakelist 添加cmake目录
时间: 2023-09-04 17:09:46 浏览: 129
要向CMakeLists.txt中添加cmake目录,您可以在文件的最顶端使用include_directories命令来添加cmake目录。如下所示:
include_directories(cmake)
这将告诉CMake在构建时搜索并包含cmake目录中的文件。请确保cmake目录位于正确的位置,并且包含您所需的文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [cmakelist 中添加pthread 库](https://blog.csdn.net/hejinjing_tom_com/article/details/124608702)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
相关问题
cmakelist 添加子目录
在CMake中,要添加子目录,需要在父目录的CMakeLists.txt文件中使用add_subdirectory()命令。这个命令的语法是add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])。source_dir是子目录的路径,binary_dir是可选的二进制输出路径,EXCLUDE_FROM_ALL是可选的参数,用于指示该子目录是否被排除在构建过程之外。
在父目录的CMakeLists.txt文件中,你可以使用add_subdirectory()命令来添加一个子目录,并且在构建过程中同时构建该子目录。同时,在子目录的CMakeLists.txt文件中,你可以定义该子目录的源文件、头文件等。例如,你的目录结构可以是这样的:
├── CMakeLists.txt # 父目录的CMakeLists.txt
├── main.cpp # 父目录的源文件,包含main函数
└── sub # 子目录
├── CMakeLists.txt # 子目录的CMakeLists.txt
├── test.h # 子目录的头文件
└── test.cpp # 子目录的源文件
在父目录的CMakeLists.txt文件中,你可以添加如下代码来添加子目录:
```
add_subdirectory(sub)
```
这样,当你构建父目录时,CMake会自动构建子目录,并将子目录中的源文件和头文件包含在构建过程中。这样,你就可以在父目录中使用子目录中定义的函数和变量了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [CMake入门二——子目录的嵌套](https://blog.csdn.net/weixin_44688770/article/details/128855559)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [[cmake][转载]add_subdirectory详解](https://blog.csdn.net/FL1623863129/article/details/120968730)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
cmakelist添加libusb
在CMakeLists.txt文件中,您需要添加对libusb源码的引用。根据提供的引用内容,您需要将以下内容添加到CMakeLists.txt文件中:
```
add_library(
# Sets the name of the library.
usb-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
libusb-support/libusb/core.c
libusb-support/libusb/descriptor.c
libusb-support/libusb/hotplug.c
libusb-support/libusb/io.c
libusb-support/libusb/sync.c
libusb-support/libusb/strerror.c
libusb-support/libusb/os/linux_usbfs.c
libusb-support/libusb/os/poll_posix.c
libusb-support/libusb/os/threads_posix.c
libusb-support/libusb/os/linux_netlink.c
native-lib.cpp
)
```
这样,您就将libusb源码添加到了CMakeLists.txt文件中。
阅读全文