[CMake] Issue with qt5_add_resources with unit tests

Alan W. Irwin Alan.W.Irwin1234 at gmail.com
Fri Jan 18 22:11:26 EST 2019


On 2019-01-19 00:09-0000 Scott Bloom wrote:

> I use qt + google test to run tests in my build environment.
>
> The problem I have, is in some (most) of my unit test directories, there will be multiple test executables created, all dependent on the same output file from the add_resources step.
>
> Typically its something like
>
> qt_add_resource( resourceVar resource.qrc )
>
> add_executable( test1 test1main.cpp ${resourceVar} )
> add_executable( test2 test2main.cpp ${resourceVar} )
>
> On windows (running the build from cmake through visual studio with parallel building turned on) this sometimes (1 out of 20 or 30 builds or so) causes a race condition, where the dependency on the qrc_resource.cpp is attempted to be generated by both executable dependencies at once.
>
> Not sure what is going on, but wondering if there was any advice out there for this problem

Hi Scott:

I could find no google hits for qt_add_resource (except for your
question).  But that search did ask is "qt5_add_resources" what
you meant?
If so there is a rather old but still useful
discussion at
<https://stackoverflow.com/questions/23041356/corrupted-resource-cpp-file-when-using-qt5-add-resources-and-multithread-compil>
for what appears to be exactly the problem you describe.  See
especially the CMake code associated with this comment:

"The workaround is to add a custom target and add explicit depends on that".

Actually, regardless of causes and whether you were refererring to
qt5_add_resources or not I think that workaround will work to solve
your issue since in a parallel build environment a custom target and
relevant dependencies on that target always assures just one build
(rather than multiple builds which race with each other) of whatever
it refers to.

Alan
__________________________
Alan W. Irwin

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list