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

Gate CMake tests behind AU_ENABLE_TESTING option #303

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,37 @@ 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()

# 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
)
if(AU_ENABLE_TESTING)
message(STATUS "Unit tests enabled")
enable_testing()

# 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)

# 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)

FetchContent_MakeAvailable(googletest)
include(GoogleTest)
set(AU_CONFIG_FIND_GTEST_LINE "find_dependency(googletest 1.12.1)")
else()
message(STATUS "Unit tests disabled")
endif()

add_subdirectory(au)

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
Loading