Skip to content

Commit

Permalink
Add CMake option to fully exclude gtest dependency
Browse files Browse the repository at this point in the history
If users activate this new option, `AU_EXCLUDE_GTEST_DEPENDENCY`, then
it will force `AU_ENABLE_TESTING` to `OFF`.  We will not attempt to
pull in the googletest dependency by any means, and we won't define the
extra targets that depend on it.

Fixes #257.
  • Loading branch information
chiphogg committed Oct 26, 2024
1 parent 0d8b244 commit 0576630
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
51 changes: 33 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ project(
LANGUAGES CXX
)

option(AU_ENABLE_TESTING "Build Unit Tests" ON)
include(CMakeDependentOption)

option(
AU_EXCLUDE_GTEST_DEPENDENCY
"Avoid taking any dependency on googletest (and, implicitly, do not build tests)"
OFF
)
cmake_dependent_option(
AU_ENABLE_TESTING
"Build Unit Tests"
ON
"NOT AU_EXCLUDE_GTEST_DEPENDENCY"
OFF
)

# The export set for all of our headers.
set(AU_EXPORT_SET_NAME AuHeaders)
Expand All @@ -46,23 +59,25 @@ endif()

# Bring in GoogleTest so we can build and run the tests.
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # Release 1.12.1
FIND_PACKAGE_ARGS
1.12.1
NAMES GTest
)

# https://google.github.io/googletest/quickstart-cmake.html
# For Windows: Prevent overriding the parent project's compiler/linker settings
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)")
if (NOT AU_EXCLUDE_GTEST_DEPENDENCY)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # Release 1.12.1
FIND_PACKAGE_ARGS
1.12.1
NAMES GTest
)

# https://google.github.io/googletest/quickstart-cmake.html
# For Windows: Prevent overriding the parent project's compiler/linker settings
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)")
endif()

add_subdirectory(au)

Expand Down
34 changes: 19 additions & 15 deletions au/code/au/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,30 @@ header_only_library(
utility/type_traits.hh
)

header_only_library(
NAME testing
HEADERS testing.hh
DEPS
au
GTest::gmock
)
if (NOT AU_EXCLUDE_GTEST_DEPENDENCY)
header_only_library(
NAME testing
HEADERS testing.hh
DEPS
au
GTest::gmock
)
endif()

#
# Private implementation detail targets
#

header_only_library(
NAME chrono_policy_validation
INTERNAL_ONLY
HEADERS chrono_policy_validation.hh
DEPS
au
GTest::gtest
)
if (NOT AU_EXCLUDE_GTEST_DEPENDENCY)
header_only_library(
NAME chrono_policy_validation
INTERNAL_ONLY
HEADERS chrono_policy_validation.hh
DEPS
au
GTest::gtest
)
endif()

#
# Tests
Expand Down

0 comments on commit 0576630

Please sign in to comment.