[CMake] Issue with qt5_add_resources with unit tests

Scott Bloom scott at towel42.com
Fri Jan 18 22:29:41 EST 2019


That was it.  I wound up finding a slightly different solution.  I create a static library of the resources, and then have the unit tests link in that lib.

Which gets the same dependency tree the custom target.

My question, that I'm still confused about is why this is necessary.

I have two projects, that depens on the output of a single input....

But this works....

~~Scott


-------- Original message --------
From: "Alan W. Irwin" <Alan.W.Irwin1234 at gmail.com>
Date: 1/18/19 19:11 (GMT-08:00)
To: Scott Bloom <scott at towel42.com>
Cc: cmake Mailing List <cmake at cmake.org>
Subject: Re: [CMake] Issue with qt5_add_resources with unit tests

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
__________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190119/797ad65d/attachment-0001.html>


More information about the CMake mailing list