From b01450878b39307df9abb702f02ce8c1d6c9ee30 Mon Sep 17 00:00:00 2001 From: bfierz Date: Thu, 7 Sep 2017 02:50:30 +0200 Subject: [PATCH] Adds an option to disable test generation (#552) When integrating the GSL as an external dependency, it is usually unnecessary to build and run the unit-tests. --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 986d948..53058e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,12 @@ find_package(Git) # creates a library GSL which is an interface (header files only) add_library(GSL INTERFACE) +# determine whether this is a standalone project or included by other projects +set(GSL_STANDALONE_PROJECT OFF) +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(GSL_STANDALONE_PROJECT ON) +endif () + # when minimum version required is 3.8.0 remove if below # both branches do exactly the same thing if (CMAKE_MAJOR_VERSION VERSION_LESS 3.7.9) @@ -53,5 +59,8 @@ install( DESTINATION include ) -enable_testing() -add_subdirectory(tests) +option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT}) +if (GSL_TEST) + enable_testing() + add_subdirectory(tests) +endif ()