利用CMake管理QT5.5+VTK6.3+ITK4.8+Opencv3.0工程
主要参考:
opencv3.1.0的Tutorial:http://docs.opencv.org/3.1.0/db/df5/tutorial_linux_gcc_cmake.html
QT Documentation:http://doc.qt.io/qt-5/cmake-manual.html
Cmake手册:http://doc.qt.io/qt-5/cmake-manual.html
ITK用户手册
博客:http://blog.csdn.net/luoru/article/details/49048353
前提:
系统环境:win64+VS2013+CMake3.3.1+ITK4.8+VTK6.3+Opencv3.0+QT5.5
1. 已经安装好:VS2013,QT和qt-vs-addin,并将QT与VS2013整合完毕。
2. 已经利用CMake对ITK,VTK和opencv进行编译,并配置好环境变量
注:由于我是64位系统,故在CMake编译过程中的编译器都选择的是64位的
利用CMake创建工程:
1. 新建文件夹:D:\test_ITK_VTK_OpenCV_QT
2. 在该文件夹下面建立src和bin两个文件夹:D:\test_ITK_VTK_OpenCV_QT\bin;D:\test_ITK_VTK_OpenCV_QT\src
3. 在bin和src两个文件夹中分别建立文件夹test_ITK_VTK_OpenCV_QT:
D:\test_ITK_VTK_OpenCV_QT\bin\test_ITK_VTK_OpenCV_QT;D:\test_ITK_VTK_OpenCV_QT\src\test_ITK_VTK_OpenCV_QT
4.接下来在D:\test_ITK_VTK_OpenCV_QT\src\test_ITK_VTK_OpenCV_QT放入CMakeLists.txt配置文件和相应的源代码文件:
main.cpp testqtwithvtk.h testqtwithvtk.cpp testqtwithvtk.ui
其中CMakeLists.txt的内容如下:
cmake_minimum_required( VERSION 2.8.11 )
project( test_ITK_VTK_OpenCV_QT ) #这句话是我们刚才标记添加的内容 set(CMAKE_INCLUDE_CURRENT_DIR ON) #这两句是VTK的内容,没什么说的 find_package( VTK REQUIRED ) find_package(ITK REQUIRED)find_package( OpenCV REQUIRED )include( ${VTK_USE_FILE} ) include(${ITK_USE_FILE})include_directories( ${OpenCV_INCLUDE_DIRS} ) #这句话是刚才标价添加的 find_package(Qt5Widgets) #这个include是根据东灵博客的内容 include_directories(${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VTK_DIR}) #这片的内容是设置MOC翻译的内容,我们只需要将东灵博客的QT4改成QT5就可以SET( PROJECT_SRCS main.cpp testqtwithvtk.cpp testqtwithvtk.h )
SET( PROJECT_UIS testqtwithvtk.ui ) SET( PROJECT_MOC_HDRS testqtwithvtk.h ) QT5_WRAP_UI( PROJECT_UIS_H ${PROJECT_UIS} ) QT5_WRAP_CPP( PROJECT_MOC_SRCS ${PROJECT_MOC_HDRS} ) #这句话就是添加可执行文件了 ADD_EXECUTABLE( test_ITK_VTK_OpenCV_QT ${PROJECT_SRCS} ${PROJECT_UIS_H} ${PROJECT_MOC_SRCS} ) #这边我们要包含的东西就是vtk和QT5各自需要包含的头文件 TARGET_LINK_LIBRARIES ( test_ITK_VTK_OpenCV_QT ${ITK_LIBRARIES} ${OpenCV_LIBS} ${VTK_LIBRARIES} Qt5::Widgets )
5.CMake进行编译
5-1.选择source和build完存储的路径
source:对应的是CMakeLists.txt所在的文件夹
build的路径: bin对应的文件夹D:\test_ITK_VTK_OpenCV_QT\bin\test_ITK_VTK_OpenCV_QT
5-2. 点击configue
5-3 成功后点击Generate
6. 接下来到build的目录(D:\test_ITK_VTK_OpenCV_QT\bin\test_ITK_VTK_OpenCV_QT)下,利用VS打开test_ITK_VTK_OpenCV_QT.sln工程,选择ALL_BUILD进行生成
7. 生成后别忘记了将ITK,Opencv,VTK需要的dll文件(如图所示)拷贝debug目录下:D:\test_ITK_VTK_OpenCV_QT\bin\test_ITK_VTK_OpenCV_QT\Debug
7. 将test_ITK_VTK_OpenCV_QT设置为启动项目,即可进行编辑