Skip to content
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

CMake: Unit tests are always built if CMAKE_CROSSCOMPILING is OFF #14764

Closed
rwalton-arm opened this issue Jun 11, 2021 · 0 comments · Fixed by #14765
Closed

CMake: Unit tests are always built if CMAKE_CROSSCOMPILING is OFF #14764

rwalton-arm opened this issue Jun 11, 2021 · 0 comments · Fixed by #14765

Comments

@rwalton-arm
Copy link
Contributor

rwalton-arm commented Jun 11, 2021

Description of defect

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.

Target(s) affected by this defect ?

N/A

Toolchain(s) (name and version) displaying this defect ?

All

What version of Mbed-os are you using (tag or sha) ?

master

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

N/A

How is this defect reproduced ?

Disable CMAKE_CROSSCOMPILING and run a build in an application including mbed-os.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants