CMakeLists.txt和Qt的* .pri文件

时间:2011-08-25 14:28:17

标签: qt cmake

我正在尝试为KDE4 / Qt4项目创建CMakeLists.txt文件。在这个项目中,目前有一个* .pri文件,它创建了独立的库。我想将该库包含在我的CMakeLists.txt中。我不知道怎么做这个...... 目前我的* .pro文件如下所示:

include(utils/qtpropertybrowser/src/qtpropertybrowser.pri)

QT       += core gui console xml

TARGET = photoframeseditor
TEMPLATE = app

SOURCES += main.cpp\
    plugin/photoframeseditor.cpp \
    ....

HEADERS  += plugin/photoframeseditor.h \
    widgets/photo_context_menu.h \
    ....

LIBS += \
    -L/usr \
    -lkdeui \
    -lkio \
    -lkipi \
    -lkdecore

INCLUDEPATH += \
    plugin \
    ....

OTHER_FILES += \
    resources/photoframeseditorui.rc \
    resources/photoframeseditor.kcfg \
    CMakeLists.txt \
    resources/PFEConfigSkeleton.kcfgc

RESOURCES += \
    resources/icons.qrc

和CMakeLists.txt

  PROJECT( photoframeseditor )

  FIND_PACKAGE( KDE4 REQUIRED )

  INCLUDE(KDE4Defaults)

  SET( INCLUDE_DIRS
      ./
      ./plugin
      .....
  )

  INCLUDE_DIRECTORIES(${QT_INCLUDE} ${KDE4_INCLUDES} ${INCLUDE_DIRS})

  # sources
  SET( SAMPLE_SRCS
      ./main.cpp
     .....
  )

  # moc headers
  SET( SAMPLE_MOC_HDRS
      ./plugin/photoframeseditor.h
     .....
  )

  SET( SAMPLE_RCS
       ./resources/icons.qrc
  )

  ADD_DEFINITIONS( -Wall )

  SET( QT_USE_QTXML TRUE )
  SET( QT_USE_QTCONSOLE TRUE )

  FIND_PACKAGE( Qt4 REQUIRED )

  INCLUDE( ${QT_USE_FILE} )

  QT4_ADD_RESOURCES( SAMPLE_RC_SRCS ${SAMPLE_RCS} )

  QT4_WRAP_CPP( SAMPLE_MOC_SRCS ${SAMPLE_MOC_HDRS} )

  KDE4_ADD_EXECUTABLE( photoframeseditor ${SAMPLE_SRCS} ${SAMPLE_MOC_SRCS} ${SAMPLE_RC_SRCS} )

  TARGET_LINK_LIBRARIES( photoframeseditor ${QT_LIBRARIES} ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} ./utils/qtpropertybrowser/src/qtpropertybrowser.pri)

  KDE4_ADD_KCFG_FILES(photoframeseditor_SRCS ./resources/PFEConfigSkeleton.kcfgc)
  INSTALL( FILES ./resources/PFEConfigSkeleton.kcfgc DESTINATION ${KCFG_INSTALL_DIR} )

  INSTALL( TARGETS photoframeseditor  ${INSTALL_TARGETS_DEFAULT_ARGS} )

最后有* .pri文件,我想包含在我的CMakeLists.txt

include(../common.pri)
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

qtpropertybrowser-uselib:!qtpropertybrowser-buildlib {
    LIBS += -L$$QTPROPERTYBROWSER_LIBDIR -l$$QTPROPERTYBROWSER_LIBNAME
} else {
    SOURCES += $$PWD/qtpropertybrowser.cpp \
            $$PWD/qtpropertymanager.cpp \
            $$PWD/qteditorfactory.cpp \
            $$PWD/qtvariantproperty.cpp \
            $$PWD/qttreepropertybrowser.cpp \
            $$PWD/qtbuttonpropertybrowser.cpp \
            $$PWD/qtgroupboxpropertybrowser.cpp \
            $$PWD/qtpropertybrowserutils.cpp
    HEADERS += $$PWD/qtpropertybrowser.h \
            $$PWD/qtpropertymanager.h \
            $$PWD/qteditorfactory.h \
            $$PWD/qtvariantproperty.h \
            $$PWD/qttreepropertybrowser.h \
            $$PWD/qtbuttonpropertybrowser.h \
            $$PWD/qtgroupboxpropertybrowser.h \
            $$PWD/qtpropertybrowserutils_p.h
    RESOURCES += $$PWD/qtpropertybrowser.qrc
}

win32 {
    contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTPROPERTYBROWSER_EXPORT
    else:qtpropertybrowser-uselib:DEFINES += QT_QTPROPERTYBROWSER_IMPORT
}

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:3)

好的,我为这个* .pri文件提供了正确的CMakeLists.txt:

PROJECT(PropertyBrowser)
SET(QT_MIN_VERSION "4.5.0")
FIND_PACKAGE(Qt4 REQUIRED)

IF(NOT QT4_FOUND)
  MESSAGE(SEND_ERROR "Failed to find Qt 4.5 or greater.")
ELSE(NOT QT4_FOUND)

  INCLUDE(${QT_USE_FILE})
  SET(CMAKE_PACKAGE_QTGUI TRUE)

  SET(qtpropertyeditor_SRCS
        src/qtpropertybrowser.cpp
        src/qtpropertymanager.cpp
        src/qteditorfactory.cpp
        src/qtvariantproperty.cpp
        src/qttreepropertybrowser.cpp
        src/qtbuttonpropertybrowser.cpp
        src/qtgroupboxpropertybrowser.cpp
        src/qtpropertybrowserutils.cpp
   )

  include_directories(${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}/src)
  include_directories(src)
  INCLUDE_DIRECTORIES(
   ${QT_INCLUDE_DIR}
  )

qt4_generate_moc(
  src/qtpropertybrowser.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtpropertybrowser.cpp
)
qt4_generate_moc(
  src/qtpropertymanager.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtpropertymanager.cpp
)
qt4_generate_moc(
  src/qteditorfactory.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qteditorfactory.cpp
)
qt4_generate_moc(
  src/qtvariantproperty.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtvariantproperty.cpp
)
qt4_generate_moc(
  src/qttreepropertybrowser.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qttreepropertybrowser.cpp
)
qt4_generate_moc(
  src/qtbuttonpropertybrowser.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtbuttonpropertybrowser.cpp
)
qt4_generate_moc(
  src/qtgroupboxpropertybrowser.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtgroupboxpropertybrowser.cpp
)
qt4_generate_moc(
  src/qtpropertymanager.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/qtpropertymanager.moc
)
qt4_generate_moc(
  src/qteditorfactory.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/qteditorfactory.moc
)
qt4_generate_moc(
  src/qttreepropertybrowser.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/qttreepropertybrowser.moc
)

set(
  qtpropertyeditor_HEADERS_ONLY_MOC
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtpropertybrowser.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtpropertymanager.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qteditorfactory.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtvariantproperty.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qttreepropertybrowser.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtbuttonpropertybrowser.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtgroupboxpropertybrowser.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/qtpropertymanager.moc
  ${CMAKE_CURRENT_BINARY_DIR}/qteditorfactory.moc
  ${CMAKE_CURRENT_BINARY_DIR}/qttreepropertybrowser.moc
)

set_source_files_properties(
  ${qtpropertyeditor_HEADERS_ONLY_MOC}
  PROPERTIES
    HEADER_FILE_ONLY true
)

qt4_generate_moc(
  src/qtpropertybrowserutils_p.h
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtpropertybrowserutils_p.cpp
)

set(
  qtpropertyeditor_HEADERS_MOC
  ${CMAKE_CURRENT_BINARY_DIR}/moc_qtpropertybrowserutils_p.cpp
)

set(
  qtpropertyeditor_MOC
  ${qtpropertyeditor_HEADERS_MOC}
  ${qtpropertyeditor_HEADERS_ONLY_MOC}
)

qt4_add_resources(
  qtpropertyeditor_RESOURCES
  src/qtpropertybrowser.qrc
)

#set(
#  extension_SRCS
#  main.cpp
#)

#qt4_generate_moc(
#  main.cpp
#  ${CMAKE_CURRENT_SOURCE_DIR}/main.moc
#)

#set(
#  extension_MOC
#  ${CMAKE_CURRENT_SOURCE_DIR}/main.moc
#)

#set_source_files_properties(
#  ${extension_MOC}
#  PROPERTIES
#    HEADER_FILE_ONLY true
#)

  QT4_ADD_RESOURCES(RESOURCE_SRCS src/qtpropertybrowser.qrc)

  #${extension_SRCS}

  SET(SRCS   ${extension_MOC}
  ${qtpropertyeditor_MOC}
  ${qtpropertyeditor_SRCS}
  ${qtpropertyeditor_RESOURCES}
)

  ADD_LIBRARY(PropertyBrowser SHARED ${SRCS})

  TARGET_LINK_LIBRARIES(PropertyBrowser ${QT_LIBRARIES})

  ADD_DEFINITIONS(${QT_DEFINITIONS})
  ADD_DEFINITIONS(-DQT_DLL)
  ADD_DEFINITIONS(-DQT_QTPROPERTYBROWSER_EXPORT)
  ADD_DEFINITIONS(-DQT_PLUGIN)
  #ADD_DEFINITIONS(-DQT_NO_DEBUG)
  ADD_DEFINITIONS(-DQT_SHARED)

  INSTALL( TARGETS PropertyBrowser LIBRARY DESTINATION lib ${INSTALL_TARGETS_DEFAULT_ARGS} )

  ENDIF(NOT QT4_FOUND)

答案 1 :(得分:1)

您可以按照此链接中的说明创建一个CMakeLists.txt文件 http://developer.qt.nokia.com/quarterly/view/using_cmake_to_build_qt_projects

您不需要* .pri文件。只需将* .pri中的文件包含在CMakeLists.txt