cmake--文件目錄


一, 目錄結構

├── CMakeLists.txt
├── include
│          └── Hello.h
└── src
          ├── Hello.cpp
          └── main.cpp

* link:CMakeLists.txt[CMakeLists.txt] - Contains the CMake commands you wish to run.
* link:include/Hello.h[include/Hello.h] - The header file to include.
* link:src/Hello.cpp[src/Hello.cpp] - A source file to compile.
* link:src/main.cpp[src/main.cpp] - The source file with main.

 

二,cmake基本腳本

cmake_minimum_required(VERSION 3.5)

project (hello_headers)

# 創建源文件變量,列出所有源文件,並設置到變量中
set(SOURCES
src/Hello.cpp
src/main.cpp
)

# 可執行程序中添加源文件
add_executable(hello_headers ${SOURCES})

# 設置要包含的目錄, g++編譯時將include頭文件,形式為 -l/path/
target_include_directories(hello_headers PRIVATE  ${PROJECT_SOURCE_DIR}/include)

三,擴展分析

1. 目錄路徑

另有專門的文章描述

2. 添加源文件的另外一種方式,采用通配符的方式添加子目錄中的所有指定類型的文件

file(GLOB SOURCES "src/*.cpp")

但是這種方式每次添加文件時,必須重新執行cmake才能編譯代碼。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM