set(cmake_include_current_dir on) #包含編譯目錄
aux_source_directory(dlg dlg_cpp) #查詢指定目錄下的所有原始檔,然後將結果存進指定變數名
file(glob file_h ./**) #載入資料夾下的所有檔案
file(glob dlg_file dlg/**) #以當前cmakelists路徑作為相對路徑
file(glob dlg_h "dlg/*.h")
2.1 基於環境變數set(cmake_prefix_path $env) #系統路徑建議直接包含../lib/qt5/.cmake檔案
find_package(qt5 components core gui widgets charts required) # qml quick network xml
2.2 手動新增(不需本機qt5環境,但仍需相關cmake檔案,但將原始碼目錄進行一定程度剝離簡化)set(qt5_dir "$/extern/qt512/lib/cmake/qt5")
set(qt5core_dir "$/extern/qt512/lib/cmake/qt5core")
set(qt5gui_dir "$/extern/qt512/lib/cmake/qt5gui")
set(qt5widgets_dir "$/extern/qt512/lib/cmake/qt5widgets")
set(qt5charts_dir "$/extern/qt512/lib/cmake/qt5charts")
include_directories("$/extern/qt512/include/qtcharts")
include_directories("$/extern/qt512/include/qtcore")
include_directories("$/extern/qt512/include/qtgui")
include_directories("$/extern/qt512/include/qtwidgets")
include_directories("$/extern/qt512/include")
link_directories("$/extern/qt512/lib")
find_package(qt5core)
find_package(qt5gui)
find_package(qt5widgets)
find_package(qt5charts)
set(file_lib
qt5::core
qt5::gui
qt5::widgets
qt5::charts
)
2.3 編譯ui檔案(cmake_autouic,qt5_wrap_ui)#set(cmake_automoc on) #qobject派生的c++類也需要通過moc進行處理 生成目錄下有demo_automoc檔案(去掉才能編過) #qobject派生的c++類也需要通過moc進行處理 生成目錄下有demo_automoc檔案(去掉才能編過)
#set(cmake_autouic on)
file(glob file_ui "./*.ui")
qt5_wrap_ui(ui_files $ )
3.1 set_propertyset_property(global property use_folders on) #開啟允許建立資料夾的開關 build、zero放在cmakepredefinedtargets
#set_property(global property predefined_targets_folder "cmaketargets") #給cmake自動建立的工程重新命名(此步驟可以省略)
3.2 設定(release/字符集)#set(cmake_build_type "release") #release需加引號
set(cmake_build_type release cache string "set build type to release")
add_compile_options("/utf-8")
set(cmake_cxx_standard 11)
cmake使用筆記
cmake方法 工程結構 project bin cmakelists.txt include test.h lib cmakelist.txt libtest.so src cmakelists.txt main.cpp test.cpp project目錄中 add subdirectory 目...
Cmake使用筆記,Cmakelist編寫
project languages 將name存到project name,同時設定變數 include directories after before system dir1 dir2 指定標頭檔案的搜尋路徑,相當於指定gcc的 i引數 include directories hello 增加h...
Qt使用TCP傳輸檔案(帶UI)
ui設計 源 伺服器與客戶端 ifndef serverwidget h define serverwidget h include include include include include namespace ui class serverwidget public qwidget endi...