The Ninja generator and Visual Studio generators are special-cased for the
QtAutogen feature. In order to reduce the number of custom targets, the Visual
Studio generators prefer to create custom commands instead, and in order to
create appropriate Ninja files, generated rcc files are listed as byproducts.
This requires the use of the GetConfigCommonSourceFiles API of the
cmGeneratorTarget for those generators when initializing the autogen target.
The initializer method is called from Compute() after the cmGeneratorTarget
objects are created, however the initialization of the object directory occurs
later in the InitGeneratorTargets method. That means that the resulting object
locations are computed incorrectly and cached before the object directory is
determined, so the generated buildsystem can not find the object files.
The initialization of the object directory was split from the creation of
cmGeneratorTarget instances in commit 0e0258c8 (cmGlobalGenerator: Split
creation of generator object from initialization., 2015-07-25). The motivation
for the split was to do only what is essential to do early in cases where
cmGeneratorTargets need to be created at configure-time. That is required for
the purpose of implementing policies CMP0024 and CMP0026, and for
try_compile(LINK_LIBRARIES). However, the split was not really necessary.
Compute the object directory in the cmGeneratorTarget constructor instead.
The QtAutogen unit test already tests the use of TARGET_OBJECTS with AUTOMOC,
and that test already passes on Ninja. The reason it already passes is that
the QtAutogen target also uses the AUTORCC feature, and specifies several qrc
files in its SOURCES. Later in the Compute algorithm (after the
InitGeneratorTargets call), the rcc files are determined and target->AddSource
is called. The AddSource call clears the previously mentioned cache of source
files, causing it to be regenerated when next queried, this time taking account
of the object directory.
Extend the test suite with a new target which does not make use of AUTORCC with
qrc files so that the test added alone would break without the fix in this
commit.
Since Qt 5.4.2, it is necessary to compile against Qt 5 with -fPIC
and not -fPIE when using GCC 5. Not doing so results in a hanging
test in this case, so use the PIC flag directly instead.
In commit v3.2.0-rc1~480^2 (QtAutogen: Regenerate qrc files if their input
changes, 2014-09-17) the "cmake -E cmake_autogen" rule was switched from
always running to running as a custom command with dependencies if rcc
is enabled. This is not correct because automoc always needs to re-run.
Switch back to always running the command.
The stderr may have warning messages. We should not treat these lines
as resource files. However, we must still recognize error message lines
for missing resource files that may be generated.
Extend the QtAutogen test to cover a generated resource as the only one
listed in a .qrc file. This causes 'rcc --list' to print a warning to
stderr that we now intend to ignore.
The 'rcc --list' operation may print newlines of the form CRCRLF,
so strip any trailing CR characters found on each line.
Update the Tests/QtAutogen test to use a resource named in a
subdirectory. This causes 'rcc --list' to display a blank line
and tests that it is correctly filtered out.
Pass CMAKE_BUILD_TYPE into the test on generators that use it so that
the per-config part of the test can activate as needed. Do not make the
per-config part conditional on the Debug configuration because the
generator expressions evaluate to empty in other configurations.
Skip the per-config source case with the Ninja generator because it does
not currently work. cmQtAutoGenerators::InitializeAutogenTarget needs
to know the list of source files on a target, but generator expressions
in the list cannot be evaluated until after CreateGeneratorTargets has
been called. That cannot happen until after Autogen targets have been
generated. It is a chicken-and-egg problem.
Get dependencies from the output of ``rcc --list`` if using
Qt 5. Otherwise process the file in the same way as the
qt4_add_resources macro.
This does not work for RCC files which are generated.
The cmake_autogen build step is implemented as a PRE_BUILD step
of the target currently if possible, rather than a standalone
custom target. This is to keep the number of (synthesized)
custom targets that appear in the UI low, but in some cases
it is necessary to fall back to a full custom target.
Fall back to a full custom target for the VS builds if autorcc
is used.
Disallow the use of config-specific source files with
the Visual Studio and Xcode generators. They don't have
any way to represent the condition currently.
Use the same common-config API in cmQtAutoGenerators. While
it accepts config-specific files, it doesn't have to support
multiple configurations yet.
Loop over the configs in cmTargetTraceDependencies
and cmGlobalGenerator::WriteSummary and consume all source
files.
Loop over the configs in cmComputeTargetDepends and compute the
object library dependencies for each config.
Don't store a mapping of the directory to the ui file. The directory
will be a unique key, allowing only one ui file to be specified.
Use the source file name instead as the mapping key.
The rcc tool generates a cpp file with a symbol called qInitResources
or called qInitResources_${name}, if the name is passed. The
qInitResources symbol clashes if multiple qrc files are used in
one target.
Always pass the name to ensure that the symbol is unique. This is also
the behavior of the qtx_add_resource macros.
Visual Studio is handled as a special case for autogen depends. However,
the special handling works only for target dependencies, not file
dependencies output by a custom command.
Use a PRE_BUILD step only if all depends are targets.
The qtx_add_resources() macro adds the resource file to the output list
to maintain file-level dependencies. Having the qrc file in a target
sources is a precondition for AUTORCC to function.
When processing the source files of a target, only add the generated
qrc_<file>.cpp to the target sources if AUTORCC is ON. This avoids
pre-porting conflict with the macro.
Reported-by: Micha Hergarden
The source files are already processed by cmQtAutomoc to look for
moc includes, so extend that to also look for ui_ includes and
find corresponding .ui files to process.
This replaces the need to invoke qt4_wrap_ui().
As the ui files are not likely to be part of the SOURCES of the
target, store the options associated with them separately in the
cmMakefile for querying during the autogen run.
Don't try to show the windows, which would require a gui capable test
machine, and that's not guaranteed.
Automatically link to qtmain.a on Windows to avoid a policy warning. Set
policy CMP0020 to NEW by increasing the required version.
Don't attempt to run the test when using Windows.