CMake 編寫筆記

2021-10-24 01:47:05 字數 1042 閱讀 1801

cmake官網

cmake_minimum_required 限定最小cmake版本,例:

set 設定變數,例:

file 組檔案或資料夾,例:

if 判斷,例:

message 輸出log,例:

include_directories 引入頭檔案目錄,使得目錄下的.h/.hpp檔案可以被引用,例:

add_executable 定義可執行檔案及包含的原始檔,例:

add_library 定義生成靜態/動態庫,例:

windows下打.a 包(msys2下執行)

mkdir build

cd build

cmake .. -g "unix makefiles"

make

windows下打.lib 包(develop powershell 下執行)

mkdir build

cd build

cmake ..

msbuild hello.sln /t:rebuild /p:configuration=release /p:platform=x64

msys2安裝(win下編譯工具之一)

一直下一步即可

安裝完開啟 minggw64 執行

pacman --noconfirm -syu

pacman --noconfirm -s mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake

pacman --noconfirm -s mingw-w64-x86_64-extra-cmake-modules make tar

pacman --noconfirm -s mingw64/mingw-w64-x86_64-cyrus-sasl

pacman --noconfirm -s git

具體語法自行在官網學習

本人建立一github demo,有需求可自行檢視借鑑。

Cmake使用筆記,Cmakelist編寫

project languages 將name存到project name,同時設定變數 include directories after before system dir1 dir2 指定標頭檔案的搜尋路徑,相當於指定gcc的 i引數 include directories hello 增加h...

CMake 高階編寫

假定有vegagis工程,工程的目錄結構如下 vegagis目錄下的cmakelists.txt cmake minimum required version 2.8 工程名 project vegagis 工程檔案中使用相對路徑 set cmake suppress regeneration 1 ...

cmake 編寫步驟

最低cmake版本 cmake minimum required version 2.6 工程名 project websocket 新增頭檔案目錄 include directories include 源檔案目錄 aux source directory src dir srcs 頭檔案目錄 s...