Skip to content

Commit

Permalink
Compile tests only in top-level projects. (#197)
Browse files Browse the repository at this point in the history
* Only compile tests in top-level projects.

* Add an option for building tests.

* Update CMakeLists.txt
  • Loading branch information
jdumas authored and stevengj committed Jul 27, 2018
1 parent 24fc75f commit ae35eec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit ae35eec

Please sign in to comment.