【问题标题】:QT5 with cmake find QX11Info componentsQT5 用 cmake 查找 QX11Info 组件
【发布时间】:2013-05-14 03:06:09
【问题描述】:

嘿,我愿意将 QT5 与 Cmake 和 Ogre3d 一起使用。

在QGlWidget中运行Ogre的使用

#include <QX11Info>

是必需的。如此处所示:http://www.ogre3d.org/tikiwiki/tiki-index.php?page=qtOgre

很遗憾,没有找到这个类,但它在 Qt4 中。

有没有人有想法在 Qt5 中使用它? 我可能没有正确包含任何内容,所以这是我的 CMakeLists.txt

非常感谢

file(GLOB COLLECTED_HDR_FILES *.hpp)
file(GLOB COLLECTED_SRC_FILES *.cpp)
file(GLOB COLLECTED_UI_FILES *.ui)
file(GLOB COLLECTED_RCS_FILES *.qrc)

set( SRCS ${COLLECTED_SRC_FILES} )
set( HDRS ${COLLECTED_HDR_FILES} )
set( MOC_HDRS ${HDRS} )
set( UIS ${COLLECTED_UI_FILES} )
set( RCS ${COLLECTED_RCS_FILES} )



# enable warnings
ADD_DEFINITIONS(-Wall)

# ogre -->
ADD_DEFINITIONS(-g)
# <-- ogre

FIND_PACKAGE(OpenGL REQUIRED)

# ogre -->
find_package(PkgConfig)
pkg_check_modules(OGRE REQUIRED OGRE)

if (CMAKE_BUILD_TYPE STREQUAL "")
  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  # differentiation between debug and release builds.
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

set(CMAKE_DEBUG_POSTFIX "_d")

set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist")

find_package(OGRE REQUIRED)

find_package(OIS REQUIRED)

if(NOT OIS_FOUND)
    message(SEND_ERROR "Failed to find OIS.")
endif()

# Find Boost
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
    if (WIN32 OR APPLE)
        set(Boost_USE_STATIC_LIBS TRUE)
    else ()
        # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
        set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
    endif ()
    if (MINGW)
        # this is probably a bug in CMake: the boost find module tries to look for
        # boost libraries with name libboost_*, but CMake already prefixes library
        # search names with "lib". This is the workaround.
        set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
    endif ()
    set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
    # Components that need linking (NB does not include header-only components like bind)
    set(OGRE_BOOST_COMPONENTS thread date_time)
    find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
    if (NOT Boost_FOUND)
        # Try again with the other type of libs
        set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
    endif()
    find_package(Boost QUIET)

    # Set up referencing of Boost
    include_directories(${Boost_INCLUDE_DIR})
    add_definitions(-DBOOST_ALL_NO_LIB)
    set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()

include_directories( ${OIS_INCLUDE_DIRS}
    ${OGRE_INCLUDE_DIRS}
    ${OGRE_SAMPLES_INCLUDEPATH}
)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/bin)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/media)


#if(MINGW OR UNIX)
#   set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin2)
#endif(MINGW OR UNIX)

# <-- ogre

# by default only QtCore and QtGui modules are enabled
# other modules must be enabled like this:
#SET(QT_USE_QTXML TRUE)
#SET(QT_USE_QTOPENGL TRUE)



# this command will generate rules that will run rcc on all files from SAMPLE_RCS
# in result SAMPLE_RC_SRCS variable will contain paths to files produced by rcc
#QT4_ADD_RESOURCES( RC_SRCS ${RCS} )

# this will run uic on .ui files:
#QT4_WRAP_UI( UI_HDRS ${UIS} )

# and finally this will run moc:
#QT4_WRAP_CPP( MOC_SRCS ${MOC_HDRS} ${UI_HDRS} )

# Qt5 -->
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Widgets finds its own dependencies.
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Test REQUIRED)
qt5_wrap_ui(UI_HDRS ${UIS})
qt5_add_resources (RC_SRCS ${RCS})
# <-- Qt5

# add some useful macros and variables
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a path to CMake script)
# INCLUDE( ${QT_USE_FILE} )

# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${OPENGL_INCLUDE_DIR})

# here we instruct CMake to build executable from all of the source files
ADD_EXECUTABLE( LevelEditor ${HDRS} ${SRCS} ${MOC_SRCS} ${RC_SRCS} ${UI_HDRS} ${UIS} )

qt5_use_modules( LevelEditor Widgets Core OpenGL )

# ogre --> 
install(TARGETS LevelEditor
    RUNTIME DESTINATION bin
    CONFIGURATIONS All)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/media
    DESTINATION ./
    CONFIGURATIONS Release RelWithDebInfo Debug
)

install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
    ${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
    DESTINATION bin
    CONFIGURATIONS Release RelWithDebInfo Debug
)
set_target_properties(LevelEditor PROPERTIES DEBUG_POSTFIX _d)
# <-- ogre

# last thing we have to do is to tell CMake what libraries our executable needs,
# luckily FIND_PACKAGE prepared QT_LIBRARIES variable for us:
TARGET_LINK_LIBRARIES( LevelEditor ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ${OGRE_LIBRARIES} ${OIS_LIBRARIES})

【问题讨论】:

    标签: 3d x11 qt5 ogre


    【解决方案1】:

    QX11Info is back in Qt 5.1(即当前的“稳定”分支),目前正在测试中——应该很快就会发布一个测试版。

    【讨论】:

    • 嘿,我是使用当前分支的新手,是否可以从源代码构建它,还是需要等待测试版?
    • 当然,您可以从源代码构建。我建议不要使用 qt5.git 或 qtsdk.git,但是:克隆 qtbase 存储库,签出 stable 分支并编译它。然后克隆 qtx11extras,签出 stable,并编译它(使用刚刚构建的 qtbase 中的 qmake:qmake &amp;&amp; make &amp;&amp; make install)。冲洗并重复您可能需要的所有其他 Qt 模块。子模块的存储库是available here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多