From: Jérémie Dumas Date: Fri, 27 Jul 2018 02:50:45 +0000 (-0400) Subject: Compile tests only in top-level projects. (#197) X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ae35eecb589ab28357691cf1b5b1a3544acd7333;p=nlopt.git Compile tests only in top-level projects. (#197) * Only compile tests in top-level projects. * Add an option for building tests. * Update CMakeLists.txt --- 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}")