Closed rhaschke closed 4 years ago
I see. Please suggest an alternative solution then to fix the broken state.
Maybe, alternatively, we could repeat the code setting those variables where GMOCK_FOUND and GTEST_FOUND are originally defined in the offending situation: https://github.com/ros/catkin/blob/4fe89dd8a553a74e16e14754021e6550386fe5a3/cmake/test/gtest.cmake#L313-L317
To be on the really safe side, you might want to test the variables [GTEST | GMOCK]_FROM_SOURCE_*
beforehand for existence.
Please suggest an alternative solution then to fix the broken state.
Unfortunately I don't have a proposal at hand. This CMake logic is extremely fragile and I wouldn't consider a "cmake project that comprises multiple catkin sub-projects" to be a supported use case - at least this is not used / tested anywhere. So I am not surprised recent changes broke that use case. I am happy to review / consider any kind of patch if it looks reasonably safe.
we could repeat the code setting those variables where GMOCK_FOUND and GTEST_FOUND are originally defined in the offending situation:
I would wonder if this would only cover some of the cases (depending on where/how Googletest is found) but not correctly define the variable in other cases when including multiple catkin packages within a single CMake context. Please consider updating the pull request as you imagine it. Even if it doesn't solve all cases but improves the one you are mostly interested in that would be fine with me to merge.
@dirk-thomas, I pushed the suggested alternative solution.
The patch looks fine to me. If it works for your use case :+1: from me.
Please target the default branch though which is noetic-devel
. I am happy to backport the commit from there to kinetic-devel
.
Maybe also update the title to reflect the changed patch.
Rebased onto noetic-devel and rephrased PR title. Thanks for back-porting to Melodic!
Thanks for the patch.
Cherry-picked to kinetic-devel
since CI had passed before already: 3e1c6555618cf6c917728060c10986b0f8b890e1.
This fixes the following bug occurring for a cmake project that comprises multiple catkin sub-projects:
I think this issue was introduced in #1091 (definitely after release 0.7.24) when a shortcut defining
GTEST_FOUND
was introduced as soon as allgtest
andgmock
targets are defined: https://github.com/ros/catkin/blob/4fe89dd8a553a74e16e14754021e6550386fe5a3/cmake/test/gtest.cmake#L312-L317However, those targets might have been defined via a previous source build of gtest and gmock. In this case, when entering the second catkin sub-package, all GTEST_* variables are undefined again, but the targets still exist causing GTEST_FOUND to be defined w/o defining the remaining variables.
This PR fixes this by defining both GTEST* and GMOCK* variables in a cached fashion in this case.