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

Support system libs #92

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bretbrownjr
Copy link
Contributor

Problem

Given:

A sandbox environment is an environment where dependencies
are all provided but access to the internet is not. Also take as
a given that the build for this project happens in an environment
that meets that description.

When:

Configuring this project with any of the provided approaches. For
instance:

cmake -B build -S .

Then:

The configuration step hangs or fails, depending on the nature of
the sandboxed environment.

Solution

Introduce a BEMAN_EXEMPLAR_FETCH_GOOGLETEST option to allow the
user to disable actions to download files from the internet without
disabling the building and running of tests. Those dependencies will
be provided correctly such that find_package calls will complete
successfully.

This workflow will provide minimal support for all known existing
packaging approaches, though BEMAN_EXEMPLAR_FETCH_GOOGLETEST
option will need to be explicitly set to a falsey value.

Future commits can revisit how to balance FetchContent and
find_package approaches to configuring CMake projects.

Problem
-------

Given a setting of `BEMAN_EXEMPLAR_BUILD_TESTS` equal to `OFF`,
when a user runs a basic CMake test command such as:

```
cmake --build binary-dir/ --target test
```

Then the user gets an error that indicates there is no CMake
test target defined.

```
$ cmake --build build2/ --target test
ninja: error: unknown target 'test', did you mean 'help'?
```

Solution
--------

It is not required to actually build any tests to define the CMake
test target. This commit defines the CMake `test` target
unconditionally.

This is good practice for a few reasons:

* A user or tool doesn't have to know project-specific details to
perform basic actions on this project.

* A user or tool doesn't have to know how to interpret the
"unknown target 'test'" error.

* When no tests are built, the user sees a successful run of zero
tests instead of a more ambiguous situation where test aren't run
for unclear reasons.
Problem
-------

**Given**:

A sandbox environment is an environment where dependencies
are all provided but access to the internet is not. Also take as
a given that the build for this project happens in an environment
that meets that description.

**When**:

Configuring this project with any of the provided approaches. For
instance:

```
cmake -B build -S .
```

**Then**:

The configuration step hangs or fails, depending on the nature of
the sandboxed environment.

Solution
--------

Introduce a `BEMAN_EXEMPLAR_FETCH_GOOGLETEST` option to allow the
user to disable actions to download files from the internet without
disabling the building and running of tests. Those dependencies will
be provided correctly such that `find_package` calls will complete
successfully.

This workflow will provide minimal support for all known existing
packaging approaches, though `BEMAN_EXEMPLAR_FETCH_GOOGLETEST`
option will need to be explicitly set to a falsey value.

Future commits can revisit how to balance `FetchContent` and
`find_package` approaches to configuring CMake projects.
@bretbrownjr
Copy link
Contributor Author

This is ready to review, though it includes the change in #91, so I'll leave it in draft for now. We could either merge this PR with both changes and close #91 or rebase this change on top of #91 after it is merged.

FetchContent_MakeAvailable(googletest)
endblock()
else()
find_package(GTest REQUIRED)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there never a case where we don't need google test? I'm actually hoping projects use something else mostly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Projects that test another way wouldn't need googletest, I suppose. In particular, projects providing entirely constexpr features wouldn't benefit from a framework like googletest, so the extra dependency would get removed. Also, some libraries would be too low level to justify a dependency on a test framework that pulls in vectors and serializers and such.

I would still expect a CMake test target to exercise a "test suite" of some sort, even if that's a series of example main functions that get compiled and executed.

Copy link

@JeffGarland JeffGarland Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entirely constexpr features wouldn't benefit from a framework

Well, in my experience with this in boost date-time I still had runtime tests along with the constexpr validation tests -- of course in that case the runtime tests came first and constexpr later. Still, with a trust-but-verify thinking I'd still want both compile and runtime covered -- but I wouldn't need/use the massive google test for simple test cases.

At the moment I'm not sure how to resolve the issue -- perhaps we leave a comment that says 'replace test framework here' -- not sure. In the end I wouldn't want to leave the impression that gtest is the sanctioned test framework.

@JeffGarland
Copy link

except for my question, I have no issues with the PR

FetchContent_MakeAvailable(googletest)
endblock()
else()
find_package(GTest REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this cause version conflict? e.g. we are fetching a specific version of Google Test, but find package finds a different (e.g. lower version) of it.

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

Successfully merging this pull request may close these issues.

3 participants