[CMake] download file, modify, add test from it

David Cole DLRdave at aol.com
Sun Nov 22 14:46:45 EST 2015


What do you mean by "depend" in this case? All libs and exes should be
built during a "make" or "make all" or "make install" ... And all that
should be done before any tests get run.

Simply typing "ctest" to execute all the tests never does any building. The
assumed workflow is that you build stuff first and then run the tests.

If you want, you can add a custom target that runs a test, and make that
custom target depend on any other targets, but ctest still won't know about
it. Only "make custom_test_target" will...


D



On Sunday, November 22, 2015, Nico Schlömer <nico.schloemer at gmail.com>
wrote:

> Thanks for the hints!
> I'm almost there now, the only thing missing is to have my test depend on
> the custom_target. This
> ```
> SET_TESTS_PROPERTIES(testname PROPERTIES DEPENDS convert)
> ```
> doesn't do the trick: The target `convert` isn't executed before `ctest`.
>
> Any hints?
>
> Cheers,
> Nico
>
>
> On Sun, Nov 22, 2015 at 3:18 AM David Cole <DLRdave at aol.com
> <javascript:_e(%7B%7D,'cvml','DLRdave at aol.com');>> wrote:
>
>> Did you try using full path names for the add_custom_command file names?
>>
>> And the NAME/COMMAND form of the add_test command?
>>
>> Also, I've always found custom commands to work best when they're
>> associated with a target. And if it was part of a target you could make the
>> target depend on the external data target with add_dependencies if
>> necessary.
>>
>>
>> HTH,
>> David C.
>>
>>
>> On Saturday, November 21, 2015, Nico Schlömer <nico.schloemer at gmail.com
>> <javascript:_e(%7B%7D,'cvml','nico.schloemer at gmail.com');>> wrote:
>>
>>> Hi everyone,
>>>
>>> I would like to create a CMake test that does the following:
>>>  * Download a file from an external resource
>>>  * Do something with the file
>>>  * compile an executable myTest
>>>  * execute myTest outputfile
>>>
>>> Using ExternalData for downloading the file works well, but the second
>>> step (file conversion, in this example cp for simplicity) does not work:
>>> ```
>>> cmake_minimum_required(VERSION 3.2)
>>>
>>> project(mytest)
>>>
>>> # Download the files
>>> INCLUDE(ExternalData)
>>> set(
>>>   ExternalData_URL_TEMPLATES
>>>   "https://downloads.sourceforge.net/project/noshdata/%(algo)/%(hash)"
>>>   )
>>> ExternalData_Expand_Arguments(
>>>   testFetchData
>>>   OUT_DATA DATA{${CMAKE_SOURCE_DIR}/test.e}
>>>   )
>>> ExternalData_Add_Target(testFetchData)
>>>
>>> add_custom_command(
>>>   OUTPUT test.g
>>>   COMMAND cp test.e test.g
>>>   DEPENDS test.e
>>>   )
>>>
>>> ADD_EXECUTABLE("myTest" main.cpp)
>>>
>>> add_test(myTest test.g)
>>> ```
>>> I suppose I'm missing something about the dependencies here; after all,
>>> the `add_custom_command` has to wait for `testFetchData` to complete.
>>> Likewise, `add_test` has to wait for `add_custom_command` to complete.
>>>
>>> Hints appreciated.
>>>
>>> Cheers,
>>> Nico
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151122/3b52f242/attachment.html>


More information about the CMake mailing list