[CMake] Using the same file in multiple tests with ExternalData

David Manthey david.manthey at kitware.com
Wed Sep 7 09:47:42 EDT 2016


I found a bug using the same external data file with multiple tests.  When
I specify the same file in three different tests, I get an error:

CMake Error: Attempt to add a custom rule to output
"/home/ubuntu/misc/large_image/_build/data/plugins/large_image/sample_image.ptif.sha512-stamp.rule"
which already has a custom rule.

Specifically, I'm using cmake ExternalData via the route exposed in
Girder's build process.  I have a branch here:
*https://github.com/DigitalSlideArchive/large_image/blob/0b06690265866d3bb3f0f92132716fe1e5ad3c69/plugin.cmake#L74
<https://github.com/DigitalSlideArchive/large_image/blob/0b06690265866d3bb3f0f92132716fe1e5ad3c69/plugin.cmake#L74>*
 where I include external data in multiple tests.  I have three test files
that are used in various tests, but not all are used in each test.  I can
use any data file TWICE, but not three times.

The error is thrown when add_custom_command is called in
Modules/ExternalData.cmake, and that function(ExternalData_add_target
target) is called the number of times I expect.  This function sets a
variable called _ExternalData_FILE_${file} to avoid adding custom commands
more than once, but the context is such that this variable is never set
when the function gets called.

I have attached a patch that fixes this problem and tests the fix.

- David

-- 
David Manthey
R&D Engineer
Kitware Inc.
(518) 881-4439
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160907/9527b041/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Allow-external-files-in-multiple-tests.patch
Type: application/octet-stream
Size: 3778 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160907/9527b041/attachment-0001.obj>


More information about the CMake mailing list