-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unittest check #14765
Fix unittest check #14765
Conversation
googletest now follows the "Abseil Live at HEAD" philosophy, which means they recommend using the latest commit on the master branch and always compiling from source. They recommend this to avoid version mismatch issues and "diamond dependency" problems which are common in dependency graphs with pinned versions. Google make the "promise" that future changes won't break downstream code if it follows the "Abseil compatability guidelines". Upping the version to master also fixes some CMake configure time warnings that were present with the older tagged releases of googletest: CMake Deprecation Warning at __build/_deps/googletest-src/CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at __build/_deps/googletest-src/googlemock/CMakeLists.txt:45 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at __build/_deps/googletest-src/googletest/CMakeLists.txt:56 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions.
Typically when adding a unit test directory to a CMake project a check will be used to ensure the subdirectory is added only if the following are true: * The BUILD_TESTING option is set to ON. * The current CMake project is the top-level project. The reason being, if a downstream project includes our project they generally don't want to build our unit tests. In mbed-os, we do correctly specify the above condition before adding the central UNITTEST subdirectory, which fetches googletest and adds the "stub" libraries the unit tests depend on. However, we only check if CMAKE_CROSSCOMPILING is OFF (or undefined) before actually adding the unit tests. This mismatched logic would lead to unexpected build failures in various scenarios. One likely case could be: a downstream project including mbed-os happens to set CMAKE_CROSSCOMPILING to OFF/undefined for any reason (possibly to build its own unit tests). mbed-os would go ahead and attempt to build its tests without fetching googletest or adding the required stub targets. To fix the issue replace the check for CMAKE_CROSSCOMPILING in the unit tests with the same BUILD_TESTING idiom we use for adding the central UNITTESTS subdirectory.
@rwalton-arm, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They got interesting approach with Abseil. It was hard for us to maintain similar approach (bleeding edge as we called it) and we broke user code often.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Summary of changes
Typically when adding a unit test directory to a CMake project a check
will be used to ensure the subdirectory is added only if the following
are true:
The reason being, if a downstream project includes our project they
generally don't want to build our unit tests.
In mbed-os, we do correctly specify the above condition before adding
the central UNITTEST subdirectory, which fetches googletest and adds the
"stub" libraries the unit tests depend on. However, we only check if
CMAKE_CROSSCOMPILING is OFF (or undefined) before actually adding the
unit tests. This mismatched logic would lead to unexpected build
failures in various scenarios. One likely case could be: a downstream
project including mbed-os happens to set CMAKE_CROSSCOMPILING to
OFF/undefined for any reason (possibly to build its own unit tests).
mbed-os would go ahead and attempt to build its tests without fetching
googletest or adding the required stub targets.
To fix the issue replace the check for CMAKE_CROSSCOMPILING in the unit
tests with the same BUILD_TESTING idiom we use for adding the central
UNITTESTS subdirectory.
While I'm here, fix some CMake warnings produced by googletest because we're
using an outdated version. googletest recommend using the latest commit from
master
Fixes #14764
Impact of changes
None
Migration actions required
None
Documentation
None
Pull request type
Test results
Reviewers