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

How should we disable building tests for CLI11 when added as subproject? #273

Closed
kcsaul opened this issue May 7, 2019 · 10 comments
Closed
Assignees
Milestone

Comments

@kcsaul
Copy link

kcsaul commented May 7, 2019

Hi,

Having found/added CLI11 to my project previously (very pleased to find it!), I've recently upgraded to the latest version.

Rather than copying files or using more complicated commands for including external projects, I prefer to add external projects as a git submodule with cmake add_subdirectory to include them in the overall project build.

After upgrading to the latest version, I'm now getting build failures because the googletest library has already been defined when googletest was included by CLI11 (before being included directly for my project tests).

It would seem this has come about due to #183 forcing the CLI11_TESTING option based on the global BUILD_TESTING option which is defined when including CTest (something I do before including external projects so option can be used to suppress including googletest in the build).

Based on comments in a similar issue for a different project, it would seem the only way of disabling tests for a subproject is it uses a specific option (like CLI11_TESTING), as there's no way of overriding/presetting the global BUILD_TESTING option for a subproject, without disabling tests for main project.

I note there's also comments in #183 which indicate CLI11_TESTING will be deprecated/removed in a future release.

Unless there's another way of achieving it(?), I'd prefer the use of CLI11_TESTING be kept, perhaps defaulting based on BUILD_TESTING (if not already preset before including CLI11).

Thanks,
Kevin

@henryiii
Copy link
Collaborator

henryiii commented May 7, 2019

I've been working on ideas related to this. Because BUILD_TESTING is a global value, it clashes easily. I think I had a solution: only add testing if this is the main project and BUILD_TESTING is defined, or if CLI11_TESTING is defined. You can see the discussion here: https://gitlab.com/CLIUtils/modern-cmake/issues/7 .

This need to be addressed before the 1.8 release.

@henryiii henryiii added this to the v1.8 milestone May 7, 2019
@henryiii henryiii self-assigned this May 7, 2019
@phlptp
Copy link
Collaborator

phlptp commented May 7, 2019

I have found it is handy in subprojects and libraries that are used as components to have some ability to turn off testing even if they are not directly a subproject. So I would recommend having CLI11_TESTING be checked as well if it is defined. So setting CLI11_TESTING to OFF would turn off the build of all the testing regardless of other variables and project scope.

@kcsaul
Copy link
Author

kcsaul commented May 7, 2019

Here's a variation on the initial solution to consider that may be a little more flexible for those who want to explicitly enable/disable CLI11 testing.

  • Default CLI11_TESTING based on whether it's the main project, provided it's not been defined/cached already.

  • Before enabling/including tests, check both CLI11_TESTING and BUILD_TESTING (if defined).

@henryiii henryiii mentioned this issue May 11, 2019
@henryiii
Copy link
Collaborator

Slightly different solution; most of the time you probably do not want all subprojects to build their test suites. So:

Main Project CLI11_TESTING unset CLI11_TESTING OFF CLI11_TESTING ON
BUILD_TESTING unset ✔️ ✔️
BUILD_TESTING OFF
BUILD_TESTING ON ✔️ ✔️ ✔️
Sub Project CLI11_TESTING unset CLI11_TESTING OFF CLI11_TESTING ON
BUILD_TESTING unset ✔️
BUILD_TESTING OFF ✔️
BUILD_TESTING ON ✔️

@phlptp
Copy link
Collaborator

phlptp commented May 11, 2019

The one I would find most confusing here is BUILD_TESTING=ON and CLI11_TESTING=OFF then the tests still build as a main project. I think there should be a single option that when turned off explicitly guarantees the tests are turned off.

@henryiii
Copy link
Collaborator

This one's the hardest - but most of the time, you would not define both in a main project. If you do, then BUILD_TESTING is the "standard" option, so it takes priority over CLI11_TESTING. But I believe I could reverse this. Or I could take an AND or an OR, I think.

I could also drop CLI11_TESTING and never allow tests to be built as a subproject - not sure how well it really supports this anyway nor why one should do it.

@henryiii
Copy link
Collaborator

New version:

Main Project CLI11_TESTING unset CLI11_TESTING OFF CLI11_TESTING ON
BUILD_TESTING default ✔️ ✔️
BUILD_TESTING OFF ✔️
BUILD_TESTING ON ✔️ ✔️
Sub Project CLI11_TESTING unset CLI11_TESTING OFF CLI11_TESTING ON
BUILD_TESTING unset ✔️
BUILD_TESTING OFF ✔️
BUILD_TESTING ON ✔️

@metopa
Copy link
Contributor

metopa commented May 16, 2019

I think the last approach is very reasonable. Giving CLI11_TESTING a priority makes a lot of sense.

@henryiii
Copy link
Collaborator

I like it - it also hides CLI11_TESTING (it's not predefined, so it's not in cmake -L), so main-project builds sees BUILD_TESTING and non-main projects really shouldn't be turning on subproject tests. That's not why add_subdirectory should be used here - you woudn't expect to be able to build the tests for a find_package package. But it's there if someone really wants it.

@henryiii
Copy link
Collaborator

But you'd expect someone who knows about CLI11_TESTING and defines it to know what they want.

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

No branches or pull requests

4 participants