更新到QT5以后發(fā)現(xiàn)CMAKE里邊的幾個函數(shù)變了,加上qt自身也做了一些調(diào)整,總之以前qt4下面用CMAKE編譯qt工程的那一套不管用了。
然后在按照官方文檔寫了cmake嘗試編譯,發(fā)現(xiàn)報錯:
http://qt-project.org/doc/qt-5.0/qtdoc/cmake-manual.html
CMake Warning at CMakeLists.txt:5 (FIND_PACKAGE):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
百度了一下,中文基本找不到答案,Google了一下找到答案了,但是該死的我忽略了,后來自己整明白才發(fā)現(xiàn)人家給的是完全正確的答案。
http://stackoverflow.com/questions/15639781/how-to-find-qt5-cmake-module-on-windows
我的分析過程如下:
根據(jù)錯誤,可以知道是找不到*Qt5*.cmake這些文件,觀察cmake安裝目錄自帶的一組*.cmake,確實沒有這些qt5工程編譯依賴的*.cmake,于是第一反應(yīng)是想qt sdk代碼里邊一定是提供了的。去搜索一下,果不其然,,,
直接拷貝過去了,,,發(fā)現(xiàn)問題依舊,,,不過這次提示的*.cmake內(nèi)部的錯誤,初步分析了一下和目錄結(jié)構(gòu)可能有點關(guān)系,,,這時候突然回憶起來上面給出的stackoverflow的帖子,,,
果然設(shè)置一下
CMAKE_PREFIX_PATH到qtbase目錄,就搞定
初略的過了下cmake的文檔,在find_package中提到
1. Search paths specified in cmake-specific cache variables. These are intended to be used on the command line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is passed.
CMAKE_PREFIX_PATH
CMAKE_FRAMEWORK_PATH
CMAKE_APPBUNDLE_PATH