用CMake为Qt生成visual studio的工程

来源:互联网 发布:搜狗搜索sem优化师 编辑:程序博客网 时间:2024/05/29 17:45

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 directoriesset(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 libraryfind_package(Qt5Widgets)# Tell CMake to create the helloworld executableadd_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文件且编译通过。



原创粉丝点击