Hey I'm willing to use QT5 with Cmake and Ogre3d.
To run Ogre in a QGlWidget the use of
#include <QX11Info>
is needed. As seen here: http://www.ogre3d.org/tikiwiki/tiki-index.php?page=qtOgre
Unfortunately this class is not found, but it was in Qt4.
Does anyone have an Idea to use this in Qt5? I maybe did not include anything properly, so here is my CMakeLists.txt
Thank you very much
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})