Issue
My project uses a third party library project. This third party library comes with their own cmake project file and we use it. The problem is that their cmake project has lots of test and sample executable targets, and after we include that cmake our final cmake-generated xcode project has all these irrelevant test and sample executable targets. Obvious approach is to modify that cmake file and remove/comment out all these test and sample executable targets. However, this won't work well when we update the library. What alternatives do I have, is there a way to include a cmake file and then disable/remove some of the targets that the cmake file declares?
Solution
You mentioned that the third-party library behind the unit tests and example code you wish to disable/remove is abseil.
Abseil's docs have a very clear and thorough documentation on how to disable abseil's unit tests and example code. See Abseil's README section on Running Abseil Tests with CMake. It is pretty clear on how abseil's unit tests are only enabled if both BUILD_TESTING
and ABSL_BUILD_TESTING
are enabled.
After checking the abseil's CMakeLists.txt, it's also clear that you also need to explicitly disable ABSL_BUILD_TEST_HELPERS
. See here.
Typically, you'll have to enable BUILD_TESTING
in your projects if you expect to use CTest to run your project's own unit tests, as it's enabled by default once you include CTest (source). However, abseil's CMakeLists.txt is clear that you need to explicitly disable ABSL_BUILD_TESTING
and ABSL_BUILD_TEST_HELPERS
to to disable its unit tests.
Answered By - RAM Answer Checked By - Dawn Plyler (WPSolving Volunteer)