CMakeLists.txt 和 Qt 的 *.pri 文件

发布于 2024-12-01 09:57:36 字数 3205 浏览 1 评论 0原文

我正在尝试为 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
}

感谢您提前提供的任何帮助!

I'm trying to create CMakeLists.txt file for KDE4/Qt4 project. In this project currently there is included one *.pri file which creates independent library. I would like to include that library into my CMakeLists.txt. I don't have any idea how to do this...
Currently my *.pro file looks like below:

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

And 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} )

And finally there is *.pri file, I would like to include into my 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
}

Thanks for any help in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

话少心凉 2024-12-08 09:57:36

好的,我已经为这个 *.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)

Ok I've got correct CMakeLists.txt for this *.pri file:

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)
那小子欠揍 2024-12-08 09:57:36

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

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

You can create just a CMakeLists.txt file as described in this link
http://developer.qt.nokia.com/quarterly/view/using_cmake_to_build_qt_projects

you don't need the *.pri file. just include the files in *.pri into your CMakeLists.txt

(り薆情海 2024-12-08 09:57:36

只需向您的 cmakelists.txt 添加一些内容
喜欢:

include_directories(C:/Qt/5.15.2/Src/qttools/src/shared/qtpropertybrowser)
file(GLOB_RECURSE QTPROPERTY_BROWSER_SOURCES
C:/Qt/5.15.2/Src/qttools/src/shared/qtpropertybrowser/*.*)
set(PROJECT_SOURCES
    main.cpp
    widget.cpp
    widget.h
    widget.ui
    ${QTPROPERTY_BROWSER_SOURCES}
   )

just add something to your cmakelists.txt
like:

include_directories(C:/Qt/5.15.2/Src/qttools/src/shared/qtpropertybrowser)
file(GLOB_RECURSE QTPROPERTY_BROWSER_SOURCES
C:/Qt/5.15.2/Src/qttools/src/shared/qtpropertybrowser/*.*)
set(PROJECT_SOURCES
    main.cpp
    widget.cpp
    widget.h
    widget.ui
    ${QTPROPERTY_BROWSER_SOURCES}
   )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文