CMakeLists.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. if(${PYTHON_MODULE_EXTENSION} MATCHES "pypy")
  2. add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported.
  3. set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
  4. return()
  5. endif()
  6. find_package(Catch 1.9.3)
  7. if(CATCH_FOUND)
  8. message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
  9. else()
  10. message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers"
  11. " manually or use `cmake -DDOWNLOAD_CATCH=1` to fetch them automatically.")
  12. return()
  13. endif()
  14. add_executable(test_embed
  15. catch.cpp
  16. test_interpreter.cpp
  17. )
  18. target_include_directories(test_embed PRIVATE ${CATCH_INCLUDE_DIR})
  19. pybind11_enable_warnings(test_embed)
  20. if(NOT CMAKE_VERSION VERSION_LESS 3.0)
  21. target_link_libraries(test_embed PRIVATE pybind11::embed)
  22. else()
  23. target_include_directories(test_embed PRIVATE ${PYBIND11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
  24. target_compile_options(test_embed PRIVATE ${PYBIND11_CPP_STANDARD})
  25. target_link_libraries(test_embed PRIVATE ${PYTHON_LIBRARIES})
  26. endif()
  27. find_package(Threads REQUIRED)
  28. target_link_libraries(test_embed PUBLIC ${CMAKE_THREAD_LIBS_INIT})
  29. add_custom_target(cpptest COMMAND $<TARGET_FILE:test_embed>
  30. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  31. pybind11_add_module(external_module THIN_LTO external_module.cpp)
  32. set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  33. add_dependencies(cpptest external_module)
  34. add_dependencies(check cpptest)