Search code examples
conan

How to require gtest in a conanfile.txt


Where to put gtest in a conanfile.txt? In a conanfile.py it is suggested to use test_requires("gtest/1.12.1@"). However, there is no [test_requires] section in conanfile.txt.

I assume it is part of the library and should therefore be in the [requires] section. Or are there any reasons to put it under [tool_requires]?


Solution

  • There is a [test_requires] section in the conanfile.txt, please check this link

    In any case, a "test" requirement is intended for linking a library in the "host" context, like gtest, catch2, or similar. It shouldn't be defined as a [tool_requires], if anything, it should be a regular [requires]. In the case of a conanfile.txt, as it is the end-consumer and there will be no further downstream consumers, there is no distinction in practice between a requires and a test_requires, as the main difference is that test_requires are private and not propagated down the graph.