[CMake] Order of enable_testing and add_subdirectory

Mateusz Loskot mateusz at loskot.net
Mon Feb 1 14:34:58 EST 2010


Marcel Loose wrote:
> On Sun, 2010-01-31 at 01:20 +0000, Mateusz Loskot wrote:
>> Hi,
>>
>> I have just learned by trial and error that enable_testing()
>> macro should be called before a subdirector(y|ies) with tests
>> are added, otherwise tests are not configured.
>>
>> Here is a bit of CMakeLists.txt in root directory of my project
>>
>> 1) This option works properly
>>
>> enable_testing()
>> add_subdirectory(include)
>> add_subdirectory(src)
>> add_subdirectory(tests) # Here are my tests
>>
>> 2) This does not configure any tests
>>
>> add_subdirectory(include)
>> add_subdirectory(src)
>> add_subdirectory(tests) # Here are my tests
>> enable_testing()
>>
>> and make test or ctest -N does not show anything but message like:
>>
>> Running tests...
>> Test project /home/mloskot/dev/geos/_svn/build
>> No tests were found!!!
>>
>>
>> Is my conclusion correct, that the order of enable_testing and
>> add_subdirectory is relevant?
>> If it is, perhaps it would be good to update the manual
>> appropriate note on how things in the CMakeLists.txt are being
> processed.
>> Best regards,
> 
> Hi Mateusz,
> 
> Yes, your conclusion is correct. I think the docs are clear about this. 
> 
>>From the docs:
> 
> enable_testing: Enable testing for current directory and below.
> 
> add_test: Add a test to the project with the specified arguments.
> If the ENABLE_TESTING command has been run, this command adds a test
> target to the current directory. If ENABLE_TESTING has not been run,
> this command does nothing.
> 
> So order *does* matter here.

Marcel,

You are perfectly right. I was apparently reading the "has been run"
part too quickly and with not enough consideration.
Everything is in place.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org


More information about the CMake mailing list