2013-05-13 378 views
0

嘿,我愿意与Cmake和Ogre3d使用QT5。QT5与cmake找到QX11Info组件

要在QGLWidget来绘图运行食人魔使用

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

回答

1

QX11Info is back in Qt 5.1(即目前的“稳定”分支),目前正处于测试 - 一个beta版即将推出。

+0

嘿,我刚刚使用当前分支,是否有可能从源代码构建,还是需要等待测试? – rcpfuchs 2013-05-14 05:23:02

+0

当然,您可以从源代码构建。我建议不要使用qt5.git或qtsdk.git,但是:克隆qtbase存储库,检出stable分支并编译它。然后克隆qtx11extras,checkout stable并编译它(使用你刚刚构建的qtbase中的qmake:'qmake && make && make install')。冲洗并重复使用您可能需要的所有其他Qt模块。子模块的存储库[可在此获得](https://qt.gitorious.org/qt)。 – peppe 2013-05-14 08:44:51