cmake基礎用法總結

2021-10-07 20:04:54 字數 878 閱讀 4844

簡單使用:

cmakelists.txt檔案內容如下:

cmake_minimum_required(version 2.8)

project (hello)

add_executable(hello hello.c)

注釋:這個示例中我們只有乙個原始檔hello.c,目標是生成乙個hello的可執行檔案。執行

cmake .後生成makefile檔案,. 代表cmakelists.txt在當前目錄下,再make即可生成hello的可執行檔案。

第一行用於指定cmake最低版本。

第二行指定專案名稱。

第三行指定編譯乙個可執行檔案,hello是第乙個引數,表示生成可執行檔案的檔名,第二個引數hello.c則用於指定原始檔。

包含目錄的使用:

cmake_minimum_required(version 2.8)

project (hello)

include_directories(inc)

set(sources src/hello.c)

#file(glob sources 「src/*.c」)

add_executable(hello $)

注釋:當前工程目錄結構為:

├── cmakelists.txt

├── inc

├──└─ hello.h

├── src

├──└─hello.c

使用include_directories() 包含頭檔案目錄。

使用set(sources … ) 或glob (or glob_recurse) 設定變數sources。

add_executable 使用變數sources ,而不是具體的檔名

cmake安裝 用法

選擇cmake x.x.x.tar.gz 找個目錄解壓縮 tar xzvf cmake x.x.x.tar.gz cd cmake x.x.x 依次執行 bootstrap make make install cmake 會預設安裝在 usr local bin 下面 檢查版本 cmake vers...

CMake 基本用法

1.最基本的cmakelists 檔案 它將 main.c 編譯為 hello 的可執行檔案 project hello 專案名稱 set src list main.c 原始檔 add executable hello 可執行檔案cmake 是強烈推薦外部編譯的,內部編譯會生成一些無法自動刪除的中...

cmake基本用法

我們編寫乙個c 單例類,使用cmake構建專案,主要是為了記錄一下cmake的基本用法。首先專案資料夾為demoproject,我們建立乙個main.cpp作為我們的主檔案,建立乙個子資料夾singleton,在singleton中建立singleton.h和singleton.cpp作為我們的單例...