Commit 9c87d9cc authored by Stephen Kelly's avatar Stephen Kelly

Add automatic rcc invocation for Qt.

This replaces the need to invoke qt4_add_resources by allowing
adding the source .qrc file directly to the target sources.
parent 84218e18
......@@ -75,6 +75,8 @@ Properties on Targets
/prop_tgt/AUTOMOC
/prop_tgt/AUTOUIC
/prop_tgt/AUTOUIC_OPTIONS
/prop_tgt/AUTORCC
/prop_tgt/AUTORCC_OPTIONS
/prop_tgt/BUILD_WITH_INSTALL_RPATH
/prop_tgt/BUNDLE_EXTENSION
/prop_tgt/BUNDLE
......@@ -237,6 +239,7 @@ Properties on Source Files
.. toctree::
/prop_sf/ABSTRACT
/prop_sf/AUTOUIC_OPTIONS
/prop_sf/AUTORCC_OPTIONS
/prop_sf/COMPILE_DEFINITIONS_CONFIG
/prop_sf/COMPILE_DEFINITIONS
/prop_sf/COMPILE_FLAGS
......
......@@ -155,6 +155,8 @@ Variables that Control the Build
/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY
/variable/CMAKE_AUTOMOC_MOC_OPTIONS
/variable/CMAKE_AUTOMOC
/variable/CMAKE_AUTORCC
/variable/CMAKE_AUTORCC_OPTIONS
/variable/CMAKE_AUTOUIC
/variable/CMAKE_AUTOUIC_OPTIONS
/variable/CMAKE_BUILD_WITH_INSTALL_RPATH
......
AUTORCC_OPTIONS
---------------
Additional options for rcc when using autorcc (see the :prop_tgt:`AUTORCC` target
property)
This property holds additional command line options which will be used when
rcc is executed during the build via autorcc, i.e. it is equivalent to the
optional OPTIONS argument of the qt4_add_resources() macro.
By default it is empty.
The options set on the .qrc source file may override :prop_tgt:`AUTORCC_OPTIONS` set
on the target.
AUTORCC
-------
Should the target be processed with autorcc (for Qt projects).
AUTORCC is a boolean specifying whether CMake will handle
the Qt rcc code generator automatically, i.e. without having to use
the QT4_ADD_RESOURCES() or QT5_ADD_RESOURCES() macro. Currently Qt4 and Qt5 are
supported.
When this property is set to TRUE, CMake will handle .qrc files added
as target sources at build time and invoke rcc accordingly.
This property is initialized by the value of the :variable:`CMAKE_AUTORCC`
variable if it is set when a target is created.
Additional command line options for rcc can be set via the
:prop_sf:`AUTORCC_OPTIONS` source file property on the .qrc file.
The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the
autouic targets together in an IDE, e.g. in MSVS.
AUTORCC_OPTIONS
---------------
Additional options for rcc when using autorcc (see the :prop_tgt:`AUTORCC` target property)
This property holds additional command line options
which will be used when rcc is executed during the build via autorcc,
i.e. it is equivalent to the optional OPTIONS argument of the
qt4_add_resources() macro.
By default it is empty.
This property is initialized by the value of the variable
:variable:`CMAKE_AUTORCC` if it is set when a target is created.
The options set on the target may be overridden by :prop_sf:`AUTORCC_OPTIONS` set
on the .qrc source file.
CMAKE_AUTORCC
-------------
Whether to handle rcc automatically for Qt targets.
This variable is used to initialize the :prop_tgt:`AUTORCC` property on all the targets.
See that target property for additional information.
CMAKE_AUTORCC_OPTIONS
---------------------
Whether to handle rcc automatically for Qt targets.
This variable is used to initialize the :prop_tgt:`AUTORCC_OPTIONS` property on
all the targets. See that target property for additional information.
set(AM_SOURCES @_moc_files@ )
set(AM_RCC_SOURCES @_rcc_files@ )
set(AM_SKIP_MOC @_skip_moc@ )
set(AM_SKIP_UIC @_skip_uic@ )
set(AM_HEADERS @_moc_headers@ )
......@@ -10,6 +11,7 @@ set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/")
set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/")
set(AM_QT_MOC_EXECUTABLE "@_qt_moc_executable@")
set(AM_QT_UIC_EXECUTABLE "@_qt_uic_executable@")
set(AM_QT_RCC_EXECUTABLE "@_qt_rcc_executable@")
set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/")
set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/")
set(AM_QT_VERSION_MAJOR "@_target_qt_version@")
......@@ -18,3 +20,5 @@ set(AM_RELAXED_MODE "@_moc_relaxed_mode@")
set(AM_UIC_TARGET_OPTIONS @_uic_target_options@)
set(AM_UIC_OPTIONS_FILES @_qt_uic_options_files@)
set(AM_UIC_OPTIONS_OPTIONS @_qt_uic_options_options@)
set(AM_RCC_OPTIONS_FILES @_qt_rcc_options_files@)
set(AM_RCC_OPTIONS_OPTIONS @_qt_rcc_options_options@)
......@@ -1226,7 +1226,8 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
target.GetType() == cmTarget::OBJECT_LIBRARY)
{
if((target.GetPropertyAsBool("AUTOMOC")
|| target.GetPropertyAsBool("AUTOUIC"))
|| target.GetPropertyAsBool("AUTOUIC")
|| target.GetPropertyAsBool("AUTORCC"))
&& !target.IsImported())
{
cmQtAutoGenerators autogen;
......
This diff is collapsed.
......@@ -32,6 +32,7 @@ private:
std::map<std::string, std::string> &configIncludes,
std::map<std::string, std::string> &configDefines);
void SetupAutoUicTarget(cmTarget* target);
void SetupAutoRccTarget(cmTarget* target);
cmGlobalGenerator* CreateGlobalGenerator(cmake* cm,
const char* targetDirectory);
......@@ -49,6 +50,7 @@ private:
bool GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName);
bool GenerateUi(const std::string& uiFileName);
bool GenerateQrc();
void ParseCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
std::map<std::string, std::string>& includedMocs,
......@@ -83,8 +85,12 @@ private:
void MergeUicOptions(std::vector<std::string> &opts,
const std::vector<std::string> &fileOpts, bool isQt5);
void MergeRccOptions(std::vector<std::string> &opts,
const std::vector<std::string> &fileOpts, bool isQt5);
std::string QtMajorVersion;
std::string Sources;
std::string RccSources;
std::string SkipMoc;
std::string SkipUic;
std::string Headers;
......@@ -93,6 +99,7 @@ private:
std::string Builddir;
std::string MocExecutable;
std::string UicExecutable;
std::string RccExecutable;
std::string MocCompileDefinitionsStr;
std::string MocIncludesStr;
std::string MocOptionsStr;
......@@ -109,11 +116,13 @@ private:
std::vector<std::string> MocOptions;
std::vector<std::string> UicTargetOptions;
std::map<std::string, std::string> UicOptions;
std::map<std::string, std::string> RccOptions;
bool Verbose;
bool ColorOutput;
bool RunMocFailed;
bool RunUicFailed;
bool RunRccFailed;
bool GenerateAll;
bool RelaxedMode;
......
......@@ -275,8 +275,10 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
this->SetPropertyDefault("AUTOMOC", 0);
this->SetPropertyDefault("AUTOUIC", 0);
this->SetPropertyDefault("AUTORCC", 0);
this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
......
......@@ -36,6 +36,7 @@ add_definitions(-DFOO -DSomeDefine="Barx")
set(CMAKE_AUTOMOC_RELAXED_MODE TRUE)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# create an executable and two library targets, each requiring automoc:
add_library(codeeditorLib STATIC codeeditor.cpp)
......@@ -43,7 +44,9 @@ add_library(codeeditorLib STATIC codeeditor.cpp)
add_library(privateSlot OBJECT private_slot.cpp)
add_executable(QtAutogen main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>)
xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
test.qrc resourcetester.cpp
)
set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
......
......@@ -38,7 +38,8 @@
**
****************************************************************************/
#include <QApplication>
#include <QCoreApplication>
#include <QTimer>
#include "codeeditor.h"
#include "calwidget.h"
......@@ -49,16 +50,11 @@
#include "xyz.h"
#include "yaf.h"
#include "libC.h"
#include "resourcetester.h"
int main(int argv, char **args)
{
QApplication app(argv, args);
CodeEditor editor;
editor.setWindowTitle(QObject::tr("Code Editor Example"));
Window w;
w.setWindowTitle(QObject::tr("Window Example"));
QCoreApplication app(argv, args);
Foo foo;
foo.doFoo();
......@@ -81,5 +77,9 @@ int main(int argv, char **args)
LibC lc;
lc.foo();
ResourceTester rt;
QTimer::singleShot(0, &rt, SLOT(doTest()));
return app.exec();
}
#include "resourcetester.h"
#include <QDebug>
#include <QApplication>
#include <QFile>
#include <QTimer>
ResourceTester::ResourceTester(QObject *parent)
: QObject(parent)
{
}
void ResourceTester::doTest()
{
if (!QFile::exists(":/CMakeLists.txt"))
qApp->exit(EXIT_FAILURE);
QTimer::singleShot(0, qApp, SLOT(quit()));
}
#ifndef RESOURCE_TESTER_H
#define RESOURCE_TESTER_H
#include <QObject>
class ResourceTester : public QObject
{
Q_OBJECT
public:
explicit ResourceTester(QObject *parent = 0);
private slots:
void doTest();
};
#endif
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>CMakeLists.txt</file>
</qresource>
</RCC>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment