用CMake为Qt生成visual studio的工程

4 篇文章 0 订阅

Qt的版本是Qt 5.9.1 for Windows,visual studio是2015 professional。cmake是3.72

Qt的官方文档说得很清楚

http://doc.qt.io/qt-5/cmake-manual.html


这里要注意的就是CMAKE_PREFIX_PATH的设置,要写在cmakelists.txt里。

cmake_minimum_required(VERSION 2.8.11)

project(testproject)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

set(CMAKE_PREFIX_PATH "E:\\Qt\\5.9.0\\5.9\\msvc2015_64\\")
# Find the QtWidgets library
find_package(Qt5Widgets)

# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp mainwindow.cpp mainwindow.h)

# Use the Widgets module from Qt 5.
target_link_libraries(helloworld Qt5::Widgets)

然后

cmake -G "Visual Studio 14 Win64" Cmakelists.txt所在路径,即可生成visual studio所需的sln文件且编译通过。



  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值