使用Cmake搭建Qt+VTK工程(顺便推荐超好Cmake入门教程一本)
组内的项目要从MFC+OpenGL向Qt+VTK迁移。最近的任务是先把一个小模块进行尝试性迁移。配置环境过程中发现Qt+VTK的项目配置起来十分麻烦,于是google之,发现使用CMake这个工具可以大大简化我们的配置过程。可惜我从没接触过Cmake,于是再次google之,发现搜索到的相关教程都很是简陋,不系统也不实用。后来在机缘巧合之下找到了一份《Cmake 实践》下载:(),真是一本很好的快速入门教程,在此感谢作者。
花几分钟快速过一下,基本就可以动手了。结合网上的代码片段,我终于写出了自己的第一个Cmake脚本——可以把Qt和VTK结合起来,同时也展示了如何使用Cmake引入第三方库。脚本贴在这里供大家参考:# This script help you to generate a project which combines VTK and Qt
# Author: Wei Wang
# Date: 2012/2/18
cmake_minimum_required(VERSION 2.8)
PROJECT(LayoutProto)
FIND_PACKAGE(VTK)
INCLUDE(${VTK_USE_FILE}) # include UseVTK.cmake
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})# include UseQt4.cmake
# support for out-of-source build
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR} #this is where ui_SimpleViewUI.h is generated
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
# 1. Set path for each kind of files
SET(SourceFilesPath ${PROJECT_SOURCE_DIR}/src)
SET(UIFilesPath ${PROJECT_SOURCE_DIR}/ui)
SET(HeadersFilesPath ${PROJECT_SOURCE_DIR}/inc)
# 2. Add items into current project
SET(SourceFiles main.cpp mainwindow.cpp AutoNDE2DPanel.cpp rawdatapanel.cpp)
SET(UIFiles mainwindow.ui)
SET(HeadersFiles mainwindow.h AutoNDE2DPanel.h rawdatapanel.h)
# 3. Concatenate items and their paths
FOREACH(SrcFile ${SourceFiles})
SET(SimpleViewSrcs ${SimpleViewSrcs} ${SourceFilesPath}/${SrcFile})
ENDFOREACH(SrcFile)
#MESSAGE(STATUS "Files: " ${SimpleViewSrcs})
FOREACH(UIFile ${UIFiles})
SET(SimpleViewUI ${SimpleViewUI} ${UIFilesPath}/${UIFile})
ENDFOREACH(UIFile)
#MESSAGE(STATUS "UIFlie: " ${SimpleViewUI})
FOREACH(HeaderFile ${HeadersFiles})
SET(SimpleViewHeaders ${SimpleViewHeaders} ${HeadersFilesPath}/${HeaderFile})
ENDFOREACH(HeaderFile)
#MESSAGE(STATUS "Headers: " ${SimpleViewHeaders})
# Wrap items to pass them to qmake
QT4_WRAP_UI(UISrcs ${SimpleViewUI})
QT4_WRAP_CPP(MOCSrcs ${SimpleViewHeaders} )
SOURCE_GROUP("Resources" FILES
${SimpleViewUI}
)
SOURCE_GROUP("Generated" FILES
${UISrcs}
${MOCSrcs}
)
# Construct an executable
ADD_EXECUTABLE( LayoutProto ${SimpleViewSrcs} ${UISrcs} ${MOCSrcs})
# Link VTK libs and Qt libs to the executable
TARGET_LINK_LIBRARIES( LayoutProto QVTK )
# Add some 3rd party libs
SET(RDTiffUtilLibPath_Release ${PROJECT_SOURCE_DIR}/lib/release)
SET(RDTiffUtilLibPath_Debug ${PROJECT_SOURCE_DIR}/lib/debug)
SET(RDTiffUtilLib_Release recutil.lib rdtutil.lib rdtiff.lib)
SET(RDTiffUtilLib_Debug recutil.lib rdtutil.lib rdtiff.lib)
# For release mode
FOREACH(LibName ${RDTiffUtilLib_Release})
TARGET_LINK_LIBRARIES( LayoutProto optimized ${RDTiffUtilLibPath_Release}/${LibName})
ENDFOREACH(LibName)
# For debug mode
FOREACH(LibName ${RDTiffUtilLib_Debug})
TARGET_LINK_LIBRARIES( LayoutProto debug ${RDTiffUtilLibPath_Debug}/${LibName})
ENDFOREACH(LibName)
我在Cmake方面也还是菜鸟,以上代码仅仅是达到能用的地步而已,缺点肯定是很多了,请各位高手多多指点!
作者:cheng_tian 发表于2012-2-19 5:58:25 原文链接
页:
[1]