CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. add_custom_target(test_cmake_build)
  2. if(CMAKE_VERSION VERSION_LESS 3.1)
  3. # 3.0 needed for interface library for subdirectory_target/installed_target
  4. # 3.1 needed for cmake -E env for testing
  5. return()
  6. endif()
  7. include(CMakeParseArguments)
  8. function(pybind11_add_build_test name)
  9. cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN})
  10. set(build_options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/mock_install"
  11. "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
  12. "-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}"
  13. "-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}")
  14. if(NOT ARG_INSTALL)
  15. list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${PROJECT_SOURCE_DIR}")
  16. endif()
  17. add_custom_target(test_${name} ${CMAKE_CTEST_COMMAND}
  18. --quiet --output-log ${name}.log
  19. --build-and-test "${CMAKE_CURRENT_SOURCE_DIR}/${name}"
  20. "${CMAKE_CURRENT_BINARY_DIR}/${name}"
  21. --build-config Release
  22. --build-noclean
  23. --build-generator ${CMAKE_GENERATOR}
  24. $<$<BOOL:${CMAKE_GENERATOR_PLATFORM}>:--build-generator-platform> ${CMAKE_GENERATOR_PLATFORM}
  25. --build-makeprogram ${CMAKE_MAKE_PROGRAM}
  26. --build-target check
  27. --build-options ${build_options}
  28. )
  29. if(ARG_INSTALL)
  30. add_dependencies(test_${name} mock_install)
  31. endif()
  32. add_dependencies(test_cmake_build test_${name})
  33. endfunction()
  34. pybind11_add_build_test(subdirectory_function)
  35. pybind11_add_build_test(subdirectory_target)
  36. if(NOT ${PYTHON_MODULE_EXTENSION} MATCHES "pypy")
  37. pybind11_add_build_test(subdirectory_embed)
  38. endif()
  39. if(PYBIND11_INSTALL)
  40. add_custom_target(mock_install ${CMAKE_COMMAND}
  41. "-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/mock_install"
  42. -P "${PROJECT_BINARY_DIR}/cmake_install.cmake"
  43. )
  44. pybind11_add_build_test(installed_function INSTALL)
  45. pybind11_add_build_test(installed_target INSTALL)
  46. if(NOT ${PYTHON_MODULE_EXTENSION} MATCHES "pypy")
  47. pybind11_add_build_test(installed_embed INSTALL)
  48. endif()
  49. endif()
  50. add_dependencies(check test_cmake_build)