Hi

I have an existing c++ exe project which I want to test with gtest. I have not yet found an easy way to keep the project as is and test it directly since gtest insists (obviously) to link against the code being tested. I found a smart answer on SO to link against object files and that works ok but it's messy and a lot of manual setup after cmake project generation, probably impossible to automate in cmake.

The other quick way is to change the VS project output to a static lib. That also works but is a manual step which again not sure can be automated at all. And there is a bigger issue hidden in here.. I can't link to this lib due to dual main() entry point.

So unless there is some smart workaround to keep project as an exe and get gtest to work, I guess the only remaining option is to separate the main() into a small bootstrap exe and then link against the rest of the program (which contains the actual testable logic) as a lib. Finally, if I understand correctly, using target_link_libraries will automatically set up the two projects as dependent and lib will always get built before the main is run.


Hopefully not inventing hot water in 2019 here.


Best regards, cen

--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org

Reply via email to