From ae35eecb589ab28357691cf1b5b1a3544acd7333 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Dumas?= Date: Thu, 26 Jul 2018 22:50:45 -0400 Subject: [PATCH] Compile tests only in top-level projects. (#197) * Only compile tests in top-level projects. * Add an option for building tests. * Update CMakeLists.txt --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46962d6..d9fb57b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,12 @@ option (NLOPT_GUILE "build guile bindings" ON) option (NLOPT_SWIG "use SWIG to build bindings" ON) option (NLOPT_LINK_PYTHON "link Python libs" ON) +if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + option (NLOPT_TESTS "build unit tests" ON) +else () + option (NLOPT_TESTS "build unit tests" OFF) +endif () + set (NLOPT_SUFFIX) if (NLOPT_CXX) set (NLOPT_SUFFIX _cxx) @@ -324,8 +330,10 @@ if (OCTAVE_FOUND OR Matlab_FOUND) add_subdirectory (src/octave) endif () -enable_testing () -add_subdirectory (test) +if (NLOPT_TESTS) + enable_testing () + add_subdirectory (test) +endif () set (CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") set (CPACK_PACKAGE_VERSION_MAJOR "${NLOPT_MAJOR_VERSION}") -- 2.30.2