So I'm trying to build a program which was originally made with a CMake instead of a .pro file. However, I cannot build it because there is something wrong with the libraries declaration. For example, the following won't work:
#include <QtGui/QApplication>
However, this works more or less, but not completely:
#include <qt4/QtGui/QApplication>
If I use the above, then I get a huge amount of errors because the compiler says that it cannot find the headers that other headers point to. The problem is the prefix of qt4. How can I link it correctly in the CMake file so every header can be found under qt4 without me needing to change the whole bunch of headers shipped with QT-SDK?
CMAKE FILE: (Source: http://code.metager.de/source/xref/kde/Support/polkit-qt-1/examples/CMakeLists.txt)
install(FILES org.qt.policykit.examples.policy DESTINATION ${SHARE_INSTALL_PREFIX}/polkit-1/actions/)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/gui
)
set(polkit_example_SRCS
main.cpp
PkExample.cpp
)
SET(polkit_example_RESOUCES
icons/icons.qrc
)
FIND_PACKAGE(Qt4 REQUIRED)
QT4_WRAP_CPP(polkit_example_MOC_SRCS
PkExample.h
)
QT4_WRAP_UI(polkit_example_UI_SRCS
PkExample.ui
)
QT4_ADD_RESOURCES (qtsourceview_RC_SRCS ${polkit_example_RESOUCES})
add_executable(polkit-example
${polkit_example_SRCS}
${polkit_example_MOC_SRCS}
${polkit_example_UI_SRCS}
${qtsourceview_RC_SRCS}
)
target_link_libraries(polkit-example
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
polkit-qt-gui-1
polkit-qt-core-1
)
#--------Helper Application
# This macro is defined in FindPolkitQt.cmake
macro(dbus_add_activation_system_service _sources)
foreach (_i ${_sources})
get_filename_component(_service_file ${_i} ABSOLUTE)
string(REGEX REPLACE "\\.service.*$" ".service" _output_file ${_i})
set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_output_file})
configure_file(${_service_file} ${_target})
install(FILES ${_target} DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/system-services )
#install(FILES ${_target} DESTINATION ${_install_dir})
endforeach (_i ${ARGN})
endmacro(dbus_add_activation_system_service _sources)
set(polkit_example_helper_SRCS
PkExampleHelper.cpp
mainHelper.cpp
)
qt4_add_dbus_adaptor(polkit_example_helper_SRCS
org.qt.policykit.examples.xml
PkExampleHelper.h
PkExampleHelper
)
QT4_WRAP_CPP(polkit_example_helper_MOC_SRCS
PkExampleHelper.h
)
add_executable(polkit-example-helper
${polkit_example_helper_SRCS}
${polkit_example_helper_MOC_SRCS}
)
# see our helper is pretty small :D
target_link_libraries(polkit-example-helper
${QT_QTCORE_LIBRARY}
polkit-qt-core-1
)
dbus_add_activation_system_service(org.qt.policykit.examples.service.in)
install(FILES org.qt.policykit.examples.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d)
From what I can tell you're close. After your FIND_PACKAGE(Qt4 REQUIRED)
include the following line:
INCLUDE(${QT_USE_FILE})
As per the documentation
The file pointed to by
QT_USE_FILE
will set up your compile environment by adding include directories, preprocessor defines, and populate aQT_LIBRARIES
variable containing all the Qt libraries and their dependencies.
So that should set up the proper paths for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With