From 4f4f1fc26ead91b269c86b8618a5a3142ac96cad Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Mon, 21 Oct 2024 11:20:47 -0400 Subject: [PATCH] Gate CMake tests behind `AU_ENABLE_TESTING` option (#303) 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 --- CMakeLists.txt | 11 ++++++++++- cmake/AuConfig.cmake.in | 2 +- cmake/HeaderOnlyLibrary.cmake | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b18407f..08ea411 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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. diff --git a/cmake/AuConfig.cmake.in b/cmake/AuConfig.cmake.in index b121f76..4b86f68 100644 --- a/cmake/AuConfig.cmake.in +++ b/cmake/AuConfig.cmake.in @@ -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) diff --git a/cmake/HeaderOnlyLibrary.cmake b/cmake/HeaderOnlyLibrary.cmake index 3c49527..eafd4d1 100644 --- a/cmake/HeaderOnlyLibrary.cmake +++ b/cmake/HeaderOnlyLibrary.cmake @@ -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 #