CMake 常用巨集分享

2022-02-02 09:27:25 字數 1870 閱讀 4133

在本人多年的cmake使用過程中,有兩個自定義巨集被廣泛且頻繁使用。分別是:

根據專案目錄結構,分組顯示c++檔案,實現目錄結構與專案結構的對應。

# macro group_files

macro(group_files src_files root_path)set(cur_dir $)foreach(group_files $})string(regex replace $/\(.*\) \\1 sgbd_fpath $)

string(regex replace "\(.*\)/.*" \\1 sgbd_group_name $)string(compare equal $ $ sgbd_nogroup)string(replace "/" "\\" sgbd_group_name $)if(sgbd_nogroup)source_group("" files $)else()include_directories($)source_group($ files $)endif(sgbd_nogroup)endforeach(group_files)endmacro(group_files)

根據匹配規則移除專案中的檔案,在跨平台開發中,主要用於移除其它平台相關的**檔案。

macro(exclude_files src_files rescure exclude_dir)file($ excludefiles  $)foreach(excludefile $)list(remove_item $ $)endforeach(excludefile)endmacro(exclude_files)

這裡我們以glslang庫為例

通過對group_files 與 exclude_files的使用,極端情況下只需要修改 $,就可以實現乙個c++庫的cmake化。

cmake取消巨集定義 CMake基本使用

cmake是個很方便的構建系統。官方的文件寫的很明白,就是有點長。於是,根據自己的使用情況,挑選其中最重要的,簡要說明於下 cmakelists.txt的編寫 cmakelists.txt的命令不區分大小寫。基本結構 最低版本宣告,如果本機的cmake版本小於這個,會告警 cmake minimum...

cmake中巨集的使用

首先貼乙個例子進行分析 set var abc macro moo arg message arg set arg abc message after change the value of arg.message arg endmacro message call macro moo 這段使用cm...

cmake 常用總結

不強迫自己永遠不知道自己有多大實力。只有逼迫自己你才知道自己能做到什麼樣子。加油吧 小夥子。cmake 主要的函式 定義了這個工程會生成乙個檔名為hello的可執行檔案,相關的原始檔是src list中定義的原始檔列表 add executable 定義了庫生成的路徑,library output ...