cmake使用筆記

2021-07-13 14:59:41 字數 1234 閱讀 4008

cmake方法

工程結構

project/

├── bin

├── cmakelists.txt

├── include

│ └── test.h

├── lib

│ └── cmakelist.txt

├── libtest.so

└── src

├── cmakelists.txt

├── main.cpp

└── test.cpp

project目錄中

add_subdirectory(目錄)向這個"目錄"裡搜尋cmakelists.txt檔案

project/cmakelists.txt內容如下:

add_subdirectory(src) #將要在src目錄下搜尋cmakelists.txt

add_subdirectory(lib)#將要在lib目錄下搜尋cmakelists.txt

/$/相當於project/ 也就是工程根目錄的意思

等於project/include

lib目錄中

set(lib_source test.cpp)

include_directories($/include)

set(library_output_path $/lib)

add_library(libhello shared $)#生成動態庫,靜態庫只需將shared換成static

include_directorys($/include)

此函式使編譯器去搜尋project/include目錄找標頭檔案,但是可能找不到庫檔案(見src中的cmakelists.txt)

src目錄中

project/src/

cmakelists.txt內容如下:

\#將可執行檔案生成到project/bin

set(executable_output_path $//bin)

add_executable(test.exe source_files)#生成可執行檔案test.exe

target_link_libraries($ libhello)

Cmake使用筆記,Cmakelist編寫

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

CMake使用筆記 帶ui檔案的Qt程式

set cmake include current dir on 包含編譯目錄 aux source directory dlg dlg cpp 查詢指定目錄下的所有原始檔,然後將結果存進指定變數名 file glob file h 載入資料夾下的所有檔案 file glob dlg file dl...

筆記 cmake 使用

1.新增路徑 add subdirectory replay 2.新增執行程式 add executable replay replay.cc 3.設定專案檔案路徑 set target properties replay properties folder replay 4.設定依賴庫 targe...