时间:2022-09-28 09:38:54 | 栏目:C代码 | 点击:次
cmake_minimum_required(VERSION 3.18) project(cmake_demo01 LANGUAGES CXX) set(CMAKE_PREFIX_PATH "C:/major/development/tools/qt/5.14/install/5.14.2/msvc2015_64") set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5 COMPONENTS Widgets Gui Core LinguistTools REQUIRED) # set(TS_FILES cmake_demo01_zh_CN.ts) file(GLOB_RECURSE src_file ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE inc_file ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) # file(GLOB_RECURSE ui_file ${CMAKE_CURRENT_SOURCE_DIR}/ui/*.ui) # qt5_wrap_ui(wrap_ui_file ${ui_file}) # SOURCE_GROUP("ui" FILES ${ui_file} ${wrap_ui_file}) add_executable(${PROJECT_NAME} ${src_file} ${inc_file} # ${wrap_ui_file} # ${TS_FILES} ) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/ui) # target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(cmake_demo01 PRIVATE Qt5::Widgets Qt5::Core Qt5::Gui) # qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
文件内容需要替换为本机的Qt和msvc编译器路径
title test build command set VCINSTALLDIR=C:\major\development\tools\vs_2015\install\VC set QTDIR=C:\major\development\tools\qt\5.14\install\5.14.2\msvc2015_64 set PATH=%PATH%;%QTDIR%\bin call "%VCINSTALLDIR%\vcvarsall.bat" amd64 cmake --build ./build --config Debug --target cmake_demo01 -j 14 --
{ "version": "2.0.0", "tasks": [{ "taskName": "qt5", "type": "shell", "command": "cmd", "args": [ "/c", "${workspaceRoot}/build.cmd", "debug" ], "group": { "kind": "build", "isDefault": true } }] }
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "cl.exe ", "type": "cppvsdbg", "request": "launch", "program": "${workspaceRoot}/build/debug/${workspaceFolderBasename}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "console": "externalTerminal", "preLaunchTask": "qt5" } ] }