cmake 创建 QT项目

包含VTK、ITK


cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(bnAiClient)

find_package(VTK REQUIRED)

include(${VTK_USE_FILE})

find_package(ITK REQUIRED)

include(${ITK_USE_FILE})

if("${VTK_QT_VERSION}" STREQUAL "")

  message(FATAL_ERROR "VTK was not built with Qt")

endif()

# Set your files and resources here

set( Srcs cJSON.c loaddicomdlg.cpp main.cpp maincenterwidgets.cpp mainleftwidgets.cpp mainrightwidgets.cpp maintopwidgets.cpp mainwindow.cpp common/basestylewidget.cpp common/dicomlablewidget.cpp common/dicomvtkwidget.cpp common/httpapi.cpp common/imagelistitem.cpp common/networkapi.cpp common/shadowwidget.cpp common/staticbutton.cpp common/staticruler.cpp common/titlebutton.cpp common/waitingdlg.cpp )

set( Hdrs cJSON.h loaddicomdlg.h maincenterwidgets.h mainleftwidgets.h mainrightwidgets.h maintopwidgets.h mainwindow.h common/basestylewidget.h common/dicomlablewidget.h common/consts.h common/dicomvtkwidget.h common/httpapi.h common/imagelistitem.h common/networkapi.h common/shadowwidget.h common/staticbutton.h common/staticruler.h common/titlebutton.h common/waitingdlg.h )

set( MOC_Hdrs loaddicomdlg.h maincenterwidgets.h mainleftwidgets.h mainrightwidgets.h maintopwidgets.h mainwindow.h common/basestylewidget.h common/dicomlablewidget.h  common/dicomvtkwidget.h common/httpapi.h common/networkapi.h common/shadowwidget.h common/staticbutton.h common/staticruler.h common/titlebutton.h common/waitingdlg.h )

set( QRCs res.qrc )

include_directories(

  ${CMAKE_CURRENT_BINARY_DIR}

  ${CMAKE_CURRENT_SOURCE_DIR}

)

# Instruct CMake to run moc automatically when needed.

set(CMAKE_AUTOMOC ON)

if(VTK_QT_VERSION VERSION_GREATER "4")

  find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)

  qt5_add_resources(QRC_Srcs ${QRCs} )

    source_group("Resources" FILES

    ${QRCs}

    ${EXE_ICON} # Not present

  )

  source_group("Generated" FILES

    ${MOC_Srcs}

    ${QRC_Srcs}

  )

  # CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.

  add_executable(bnAiClient ${Srcs} ${Hdrs}  ${MOC_Hdrs} ${QRC_Srcs})

  qt5_use_modules(bnAiClient Core Gui Widgets Network)

  target_link_libraries(bnAiClient ${VTK_LIBRARIES})

else()

  find_package(Qt4 REQUIRED)

  SET(QT_USE_QTNETWORK TRUE)

  include(${QT_USE_FILE})


  # Use what VTK built with

  set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")

  set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")

  set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")

  qt4_wrap_cpp(MOC_Srcs ${MOC_Hdrs} )

  qt4_add_resources(QRC_Srcs ${QRCs})

  source_group("Resources" FILES

    ${QRCs}

    ${EXE_ICON} # Not present

  )

  source_group("Generated" FILES

    ${QRC_Srcs}

    ${QRC_Srcs}

  )

  add_executable(bnAiClient  MACOSX_BUNDLE

    ${Srcs} ${Hdrs}  ${MOC_Hdrs} ${QRC_Srcs})

  target_link_libraries(bnAiClient 

    ${QT_LIBRARIES}

    ${VTK_LIBRARIES}

    ${ITK_LIBRARIES}

  )

endif()


更多Qt 模块

SET(QT_USE_QTOPENGL TRUE)

其它较常用的模块包括:

                                     QT_USE_QTNETWORK

                                     QT_USE_QTOPENGL

                                     QT_USE_QTSQL

                                     QT_USE_QTXML

                                     QT_USE_QTSVG

                                     QT_USE_QTTEST

                                     QT_USE_QTDBUS

                                     QT_USE_QTSCRIPT

                                     QT_USE_QTWEBKIT

                                     QT_USE_QTXMLPATTERNS

                                     QT_USE_PHONON

此外,还有其它的宏可以用,具体地可参见cmake/share/Modules/FindQt4.cmake 


参考:https://www.cnblogs.com/findumars/p/5641859.html

你可能感兴趣的:(cmake 创建 QT项目)