chiark / gitweb /
Prefer target_include_directories in CMake build script
[nlopt.git] / test / CMakeLists.txt
1 add_custom_target (tests)
2
3 # have to add timer.c and mt19937ar.c as symbols are declared extern
4 add_executable (testopt testfuncs.c testfuncs.h testopt.cpp ${PROJECT_SOURCE_DIR}/util/timer.c ${PROJECT_SOURCE_DIR}/util/mt19937ar.c)
5 target_link_libraries (testopt ${nlopt_lib})
6 target_include_directories (testopt PRIVATE ${NLOPT_PRIVATE_INCLUDE_DIRS})
7 add_dependencies (tests testopt)
8
9 foreach (algo_index RANGE 29)# 42
10   foreach (obj_index RANGE 1)# 21
11     set (enable_ TRUE)
12     # cxx stogo
13     if (NOT WITH_CXX)
14       if (algo_index STREQUAL 8 OR algo_index STREQUAL 9)
15         set (enable_ FALSE)
16       endif ()
17     endif ()
18     # L-BFGS
19     if (algo_index STREQUAL 10)
20       set (enable_ FALSE)
21     endif ()
22     # LN_NEWUOA_BOUND timeouts on msvc
23     if (algo_index STREQUAL 27)
24       set (enable_ FALSE)
25     endif ()
26     if (enable_)
27       add_test (NAME testopt_algo${algo_index}_obj${obj_index} COMMAND testopt -a ${algo_index} -o ${obj_index})
28     endif ()
29   endforeach ()
30 endforeach ()
31
32 if (NUMPY_FOUND AND PYTHONLIBS_FOUND AND (SWIG_FOUND OR (EXISTS ${PROJECT_SOURCE_DIR}/swig/nlopt-python.cpp)))
33   set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/swig"
34                                   "PYTHONPATH=${PROJECT_BINARY_DIR}/swig"
35     )
36   add_test (NAME test_python COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/t_python.py)
37   set_tests_properties (test_python PROPERTIES ENVIRONMENT "${PYINSTALLCHECK_ENVIRONMENT}")
38 endif ()
39
40 if (OCTAVE_FOUND)
41   add_test (NAME test_octave COMMAND ${OCTAVE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/t_octave.m ${PROJECT_SOURCE_DIR}/octave ${PROJECT_BINARY_DIR}/octave)
42 endif ()
43
44 if (GUILE_FOUND AND ((SWIG_FOUND AND SWIG_VERSION VERSION_GREATER 2.0.9) OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/nlopt-guile.cpp)))
45   set (GUILECHECK_ENVIRONMENT "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/swig"
46                               "GUILE_LOAD_PATH=${PROJECT_BINARY_DIR}/swig"
47     )
48   add_test (NAME test_guile COMMAND ${GUILE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/t_guile.scm)
49   set_tests_properties (test_guile PROPERTIES ENVIRONMENT "${GUILECHECK_ENVIRONMENT}")
50 endif ()