# cmake_project **Repository Path**: yuwei-web/cmake_project ## Basic Information - **Project Name**: cmake_project - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-12-14 - **Last Updated**: 2024-12-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 示例说明 该示例演示了如何使用 CMake 构建一个包含多个组件的项目,每个组件都可以独立编译和链接。 ## 项目结构 ``` ├── CMakeLists.txt ├── components │ ├── CMakeLists.txt │ ├── ComponentA │ │ ├── CMakeLists.txt │ │ ├── ComponentA.c │ │ └── include │ └── ComponentB │ ├── CMakeLists.txt │ ├── ComponentB.c │ └── include ├── main.c ``` ## 构建项目 ```shell $ cmake -S . -B build -DBUILD_ComponentA=ON -DBUILD_ComponentB=ON && make -C build ``` ## 添加新组件 1. 在 `components` 目录下创建新的组件目录,例如 `ComponentC`。 2. 在 `ComponentC` 目录下创建 `CMakeLists.txt` 文件,定义组件的编译规则,需要在该文件下处理好组件间的依赖关系。 3. 在 `ComponentC` 目录下创建 `ComponentC.c` 文件,实现组件的功能。 4. 在 `ComponentC` 目录下创建 `include` 目录,存放组件的头文件。