Skip to content

Commit

Permalink
Support building against system libraries
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bretbrownjr committed Dec 28, 2024
1 parent a885d77 commit 5bf523d
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,44 @@ project(

enable_testing()

# [CMAKE.SKIP_TESTS]
option(
BEMAN_EXEMPLAR_BUILD_TESTS
"Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }."
"Enable building tests and test infrastructure."
${PROJECT_IS_TOP_LEVEL}
)

# [CMAKE.SKIP_EXAMPLES]
option(
BEMAN_EXEMPLAR_BUILD_EXAMPLES
"Enable building examples. Default: ON. Values: { ON, OFF }."
"Enable building examples."
${PROJECT_IS_TOP_LEVEL}
)

option(
BEMAN_EXEMPLAR_FETCH_GOOGLETEST
"Enable downloading and building googletest from source."
${PROJECT_IS_TOP_LEVEL}
)

include(FetchContent)
include(GNUInstallDirs)

if(BEMAN_EXEMPLAR_BUILD_TESTS)
# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG
f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0
EXCLUDE_FROM_ALL
)
block()
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
FetchContent_MakeAvailable(googletest)
endblock()
if(BEMAN_EXEMPLAR_FETCH_GOOGLETEST)
# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG
f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0
EXCLUDE_FROM_ALL
)
block()
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
FetchContent_MakeAvailable(googletest)
endblock()
else()
find_package(GTest REQUIRED)
endif()
endif()

add_subdirectory(src/beman/exemplar)
Expand Down

0 comments on commit 5bf523d

Please sign in to comment.