find_package其实在windows下扮演的角色并不是很重要。在Unix下就非常重要了,find_package可以根据cmake内置的.cmake的脚本去找相应的库的模块,当然,内建了很多库的模块变量,调用了find_package之后,会有相应的变量“生成”有效。
比如调用了find_package(Qt5Widgets),find_package(Qt4 COMPONENTS QTCORE QTGUI QTOPENGL QTSVG)返回之后
就会有变量Qt5Widgets_FOUND,Qt5Widgets_INCLUDE_DIRS相应的变量生效。
然后就可以在CMakeLists.txt里面使用上述的变量了。类似如下:
1 INCLUDE_DIRECTORIES(${QT_INCLUDES})2 INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDE_DIRS})3 INCLUDE_DIRECTORIES(${Qt5Svg_INCLUDE_DIRS})4 INCLUDE_DIRECTORIES(${Qt5OpenGL_INCLUDE_DIRS})5 INCLUDE_DIRECTORIES(${Qt5Concurrent_INCLUDE_DIRS})
1 if(Qt5Widgets_FOUND)2 3 4 message(STATUS ${Qt5Widgets_INCLUDE_DIRS})5 #qt56 else()7 find_package(Qt4 REQUIRED) #qt48 include(${QT_USE_FILE})9 endif()
references:
http://qt-project.org/doc/qt-5/cmake-manual.html
http://blog.csdn.net/bowater/article/details/2477227
http://www.kdab.com/using-cmake-with-qt-5/