From 78a25164be8a15bf3d677ac0f1de402e15555377 Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Mon, 2 Apr 2018 12:40:34 +0200 Subject: [PATCH] cmake: Auto-detect Catch dependency to decide whether to enable tests This automatically enables or disables tests, depending on whether Catch is found on the system. Of course, it is still possible to force building tests: * `-DBUILD_TESTS=OFF` will disable tests even if Catch is found * `-DBUILD_TESTS=ON` will enable tests even if Catch is not found (mostly useful because it causes cmake to fail early) --- CMakeLists.txt | 8 +++++++- cmake/modules/Findcatch.cmake | 9 ++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cda77e..2679d5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ set( VERSION "${restbed_VERSION}" ) # option( BUILD_SHARED "Build shared library." OFF ) option( BUILD_EXAMPLES "Build examples applications." OFF ) -option( BUILD_TESTS "Build all available test suites." OFF ) option( BUILD_SSL "Build secure socket layer support." ON ) # @@ -39,6 +38,13 @@ if ( BUILD_SSL ) include_directories( SYSTEM ${ssl_INCLUDE} ) endif ( ) +find_package( catch ) +if ( CATCH_FOUND ) + option( BUILD_TESTS "Build all available test suites." ON) +else ( ) + option( BUILD_TESTS "Build all available test suites." OFF) +endif ( ) + # # Build # diff --git a/cmake/modules/Findcatch.cmake b/cmake/modules/Findcatch.cmake index c1fd84e..ed241ec 100644 --- a/cmake/modules/Findcatch.cmake +++ b/cmake/modules/Findcatch.cmake @@ -2,10 +2,5 @@ find_path( catch_INCLUDE catch.hpp HINTS "${PROJECT_SOURCE_DIR}/dependency/catch/include" "/usr/include" "/usr/include/catch" "/usr/include/catch2" "/usr/local/include" "/usr/local/include/catch" "/usr/local/include/catch2" "/opt/local/include" "/opt/local/include/catch" "/opt/local/include/catch2" ) -if ( catch_INCLUDE ) - set( CATCH_FOUND TRUE ) - - message( STATUS "${Green}Found Catch include at: ${catch_INCLUDE}${Reset}" ) -else ( ) - message( FATAL_ERROR "${Red}Failed to locate Catch dependency.${Reset}" ) -endif ( ) +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(catch DEFAULT_MSG catch_INCLUDE) -- 2.16.3