Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 1 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 2 | message(STATUS "Setting tests build type to MinSizeRel as none was specified") |
Wenzel Jakob | 7962f30 | 2016-09-17 12:58:18 +0200 | [diff] [blame] | 3 | set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Choose the type of build." FORCE) |
| 4 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" |
| 5 | "MinSizeRel" "RelWithDebInfo") |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 6 | endif() |
| 7 | |
| 8 | set(PYBIND11_TEST_FILES |
Jason Rhinelander | ec62d97 | 2016-09-09 02:42:51 -0400 | [diff] [blame] | 9 | test_alias_initialization.cpp |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 10 | test_buffers.cpp |
| 11 | test_callbacks.cpp |
Trent Houliston | 352149e | 2016-08-25 23:08:04 +1000 | [diff] [blame] | 12 | test_chrono.cpp |
Jason Rhinelander | 5fffe20 | 2016-09-06 12:17:06 -0400 | [diff] [blame] | 13 | test_class_args.cpp |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 14 | test_constants_and_functions.cpp |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 15 | test_eigen.cpp |
Dean Moldovan | a9a37b4 | 2016-08-13 00:57:24 +0200 | [diff] [blame] | 16 | test_enum.cpp |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 17 | test_eval.cpp |
| 18 | test_exceptions.cpp |
| 19 | test_inheritance.cpp |
| 20 | test_issues.cpp |
| 21 | test_keep_alive.cpp |
| 22 | test_kwargs_and_defaults.cpp |
| 23 | test_methods_and_attributes.cpp |
| 24 | test_modules.cpp |
Dean Moldovan | 568ec6b | 2016-09-20 11:52:25 +0200 | [diff] [blame] | 25 | test_multiple_inheritance.cpp |
Ivan Smirnov | 91b3d68 | 2016-08-29 02:41:05 +0100 | [diff] [blame] | 26 | test_numpy_array.cpp |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 27 | test_numpy_dtypes.cpp |
| 28 | test_numpy_vectorize.cpp |
| 29 | test_opaque_types.cpp |
| 30 | test_operator_overloading.cpp |
| 31 | test_pickling.cpp |
| 32 | test_python_types.cpp |
| 33 | test_sequences_and_iterators.cpp |
Dean Moldovan | 568ec6b | 2016-09-20 11:52:25 +0200 | [diff] [blame] | 34 | test_smart_ptr.cpp |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 35 | test_stl_binders.cpp |
| 36 | test_virtual_functions.cpp |
| 37 | ) |
| 38 | |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 39 | string(REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES}") |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 40 | |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 41 | # Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but |
| 42 | # keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed" |
| 43 | # skip message). |
| 44 | list(FIND PYBIND11_TEST_FILES test_eigen.cpp PYBIND11_TEST_FILES_EIGEN_I) |
| 45 | if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1) |
| 46 | find_package(Eigen3 QUIET) |
| 47 | |
| 48 | if(EIGEN3_FOUND) |
| 49 | message(STATUS "Building tests with Eigen v${EIGEN3_VERSION}") |
| 50 | else() |
| 51 | list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I}) |
| 52 | message(STATUS "Building tests WITHOUT Eigen") |
| 53 | endif() |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 54 | endif() |
| 55 | |
| 56 | # Create the binding library |
Wenzel Jakob | dac3858 | 2016-09-29 21:30:00 +0200 | [diff] [blame] | 57 | pybind11_add_module(pybind11_tests pybind11_tests.cpp |
| 58 | ${PYBIND11_TEST_FILES} ${PYBIND11_HEADERS}) |
| 59 | |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 60 | pybind11_enable_warnings(pybind11_tests) |
| 61 | |
| 62 | if(EIGEN3_FOUND) |
| 63 | target_include_directories(pybind11_tests PRIVATE ${EIGEN3_INCLUDE_DIR}) |
| 64 | target_compile_definitions(pybind11_tests PRIVATE -DPYBIND11_TEST_EIGEN) |
| 65 | endif() |
| 66 | |
| 67 | set(testdir ${PROJECT_SOURCE_DIR}/tests) |
| 68 | |
| 69 | # Always write the output file directly into the 'tests' directory (even on MSVC) |
| 70 | if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) |
| 71 | set_target_properties(pybind11_tests PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${testdir}) |
| 72 | foreach(config ${CMAKE_CONFIGURATION_TYPES}) |
| 73 | string(TOUPPER ${config} config) |
| 74 | set_target_properties(pybind11_tests PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} ${testdir}) |
| 75 | endforeach() |
| 76 | endif() |
| 77 | |
Jason Rhinelander | dd3d56a | 2016-08-26 17:11:40 -0400 | [diff] [blame] | 78 | # Make sure pytest is found or produce a fatal error |
Dean Moldovan | 18319d5 | 2016-08-13 02:44:56 +0200 | [diff] [blame] | 79 | if(NOT PYBIND11_PYTEST_FOUND) |
Wenzel Jakob | 6a1734a | 2016-10-09 20:10:49 +0200 | [diff] [blame] | 80 | execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pytest --version --noconftest OUTPUT_QUIET ERROR_QUIET |
| 81 | RESULT_VARIABLE PYBIND11_EXEC_PYTHON_ERR) |
| 82 | if(PYBIND11_EXEC_PYTHON_ERR) |
Jason Rhinelander | dd3d56a | 2016-08-26 17:11:40 -0400 | [diff] [blame] | 83 | message(FATAL_ERROR "Running the tests requires pytest. Please install it manually (try: ${PYTHON_EXECUTABLE} -m pip install pytest)") |
Dean Moldovan | 18319d5 | 2016-08-13 02:44:56 +0200 | [diff] [blame] | 84 | endif() |
Wenzel Jakob | b55a5c5 | 2016-10-09 13:51:05 +0200 | [diff] [blame] | 85 | set(PYBIND11_PYTEST_FOUND TRUE CACHE INTERNAL "") |
Dean Moldovan | 18319d5 | 2016-08-13 02:44:56 +0200 | [diff] [blame] | 86 | endif() |
| 87 | |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 88 | # A single command to compile and run the tests |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 89 | add_custom_target(pytest COMMAND ${PYTHON_EXECUTABLE} -m pytest -rws ${PYBIND11_PYTEST_FILES} |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 90 | DEPENDS pybind11_tests WORKING_DIRECTORY ${testdir}) |