+# Python binding (with pybind11)
+################
+# Our usage of pybind11::overload_cast mandates C++14
+if((NOT DEFINED enable_python) OR enable_python)
+ get_property(known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
+
+ if("cxx_std_14" IN_LIST known_features)
+
+ if(EXISTS ${CMAKE_HOME_DIRECTORY}/pybind11) # Try to use a local copy of pybind11, if any
+ message(STATUS "Use the internal copy of pybind11 (using C++14).")
+ add_subdirectory(${CMAKE_HOME_DIRECTORY}/pybind11)
+ set(pybind11_FOUND ON)
+
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_HOME_DIRECTORY}/pybind11/tools/)
+ set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
+ find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)
+
+ else()
+ find_package(pybind11 CONFIG)
+ if (pybind11_VERSION VERSION_LESS 2.2)
+ message(STATUS "SimGrid needs at least v2.2 of pybind11. Disabling the Python bindings (found version: ${pybind11_VERSION}).")
+ set(pybind11_FOUND OFF)
+ endif()
+ endif()
+
+ if(NOT PYTHONLIBS_FOUND)
+ message(STATUS "Python libs not found. Turn pybind11 off.")
+
+ set(pybind11_FOUND OFF)
+ endif()
+
+ else()
+ message(STATUS "No support for C++14 detected, don't even search for pybind11.")
+ set(pybind11_FOUND OFF)
+ endif()
+ unset(known_features)
+endif()
+
+option(enable_python "Whether the Python bindings are activated." ${pybind11_FOUND}) # ON by default if dependencies are met
+
+if("${CMAKE_SYSTEM}" MATCHES "FreeBSD" AND enable_model-checking AND enable_python)
+ message(WARNING "FreeBSD + Model-Checking + Python = too much for now. Disabling python.")
+ set(enable_python FALSE)
+endif()
+
+if(enable_python)
+ if(pybind11_FOUND)
+ message(STATUS "Found pybind11, with C++14.")
+ if(NOT enable_lto)
+ set(pybind11_options NO_EXTRAS)
+ endif()
+ pybind11_add_module(python-bindings src/bindings/python/simgrid_python.cpp ${pybind11_options})
+ target_compile_features(python-bindings PRIVATE cxx_std_14)
+ target_link_libraries(python-bindings PUBLIC simgrid)
+ set_target_properties(python-bindings PROPERTIES
+ LIBRARY_OUTPUT_NAME simgrid
+ CXX_VISIBILITY_PRESET "default")
+ add_dependencies(tests python-bindings)
+ set_property(TARGET python-bindings
+ APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
+ else()
+ message(FATAL_ERROR "Please install pybind11-dev to build the Python bindings (or disable that option).")
+ endif()
+endif()
+mark_as_advanced(PYBIND11_PYTHON_VERSION)
+mark_as_advanced(pybind11_DIR)
+