GoogleTest gtest_discover_tests post-build command launched by install target
GoogleTest module provides two functions to help use the Google Test infrastructure: gtest_add_tests (considered as the old one) and gtest_discover_tests (considered as the new one)
gtest_discover_tests works by adding post-build command that runs the test executable with the --gtest_list_tests argument.
All is ok when I run cmake --build . --config Release
: the post-build command is correctly launched and tests are discovered.
If I run cmake --build . --config Release --target run_tests
, the build is not relaunched even if sources have changed (actually this command does not make a rebuild at all). This is not really a problem for me and not the subject of this ticket. I just note that the post-build command for gtest is not launched in this case (that is not a problem as in anyway we must have rebuild the project before).
But now if I run cmake --build . --config Release --target install
, I see that the gtest post-build command is systematically launched. An this is problem for me.
To understand why I think this is a problem, here is my current build flow. I use conan and inside conan I use cmake. In conan, there is file conanfile.py that contains all informations needed to compile and package the library. In particular there is two functions build and package. In build I call cmake to build the library and run the tests. In package I call the install target with cmake. My library has some dependencies managed by conan.
In this situation, conan manages dependencies and allows to copy needed files in local folder such that the build process has all necessary resources (in particular *.dll of dependencies). Here is how conan works:
- install dependencies and make a local copy of needed resources
- build
- delete local copy of needed resources
- package the library
So when I package the library, I do not have anymore dependencies needed (in particular) to run the tests. So the gtest post-build command fails because my gtest drivers cannot found their dependencies.
Some of you may think it is a problem with conan but I think it is a problem with GoogleTest cmake module:
- There is no reason why gtests post-build command should be launched during install. That has no meaning and the result of running the post-build command will never be used.
- Tests are actually not part of the library binary package (but if you really want do it explicitly) so the tests drivers could even have been deleted before packaging and the packaging will fail only because of the post-build command
For my case I now use the old function gtest_add_tests and that has solved my problem, but as gtest_discover_tests is supposed to be the new and better one, I think this must be fixed.
I use cmake 3.11.4 and Visual Studio 2015 on Windows 10