Skip to content

Commit

Permalink
Gate CMake tests behind AU_ENABLE_TESTING option (#303)
Browse files Browse the repository at this point in the history
This brings in the external contributions from #297, merges in the
latest main, and prepends an `AU_` prefix to the option.

A future PR will add another option to let users opt out of the GTest
dependency entirely, losing access to the `Au::testing` target (which
wouldn't be any loss to people who don't use GTest).

To test:

```sh
cmake \
  -S . \
  -B cmake/build \
  -DAU_ENABLE_TESTING=FALSE \
  -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=TRUE \
&& cmake \
  --build cmake/build \
  --target all
```

Helps #257.

---------

Co-authored-by: Riff, Eric <[email protected]>
  • Loading branch information
chiphogg and ericriff authored Oct 21, 2024
1 parent 06b074c commit 4f4f1fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ project(
LANGUAGES CXX
)

option(AU_ENABLE_TESTING "Build Unit Tests" ON)

# The export set for all of our headers.
set(AU_EXPORT_SET_NAME AuHeaders)

enable_testing()
if(AU_ENABLE_TESTING)
message(STATUS "Unit tests enabled")
enable_testing()
else()
message(STATUS "Unit tests disabled")
endif()

# Bring in GoogleTest so we can build and run the tests.
include(FetchContent)
Expand All @@ -55,6 +62,8 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)

set(AU_CONFIG_FIND_GTEST_LINE "find_dependency(googletest 1.12.1)")

add_subdirectory(au)

# Configure how Au will be installed.
Expand Down
2 changes: 1 addition & 1 deletion cmake/AuConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(googletest 1.12.1)
@AU_CONFIG_FIND_GTEST_LINE@

include(${CMAKE_CURRENT_LIST_DIR}/AuHeaders.cmake)

Expand Down
5 changes: 5 additions & 0 deletions cmake/HeaderOnlyLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function(header_only_library)
endfunction()

function(gtest_based_test)
if (NOT AU_ENABLE_TESTING)
message(VERBOSE "AU_ENABLE_TESTING not defined; will not create test target.")
return()
endif()

#
# Handle argument parsing
#
Expand Down

0 comments on commit 4f4f1fc

Please sign in to comment.