Support using pybind from the system.

This should make packaging easier and more streamlined
to the process on some Linux systems.
This commit is contained in:
Markus Blatt
2021-03-15 21:41:11 +01:00
parent a05bb1a0b9
commit 755c23bfb5
2 changed files with 14 additions and 2 deletions

View File

@@ -1,4 +1,12 @@
if(NOT TARGET pybind11)
find_package(pybind11 2.2 CONFIG)
if(NOT pybind11_FOUND)
add_subdirectory( pybind11 )
# SYSTEM is supported for embedded pybind source (>= 2.3.0)
set(PYBIND11_SYSTEM "SYSTEM")
elseif(pybind11_VERSION VERSION_GREATER_EQUAL "2.3.0")
# SYSTEM is only support for pybind >= 2.3.0 (Unfortunately querying the
# version does not work. AT least we know the embedded one.
set(PYBIND11_SYSTEM "SYSTEM")
endif()
add_subdirectory( simulators )

View File

@@ -4,7 +4,8 @@
# find_package(PYTHON) to define variables like
# ${PYTHON_EXECUTABLE}
#
pybind11_add_module(simulators simulators.cpp SYSTEM)
pybind11_add_module(simulators simulators.cpp ${PYBIND11_SYSTEM})
set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/opm2 )
@@ -26,6 +27,9 @@ file( COPY ${PROJECT_SOURCE_DIR}/python/test_data
DESTINATION ${PROJECT_BINARY_DIR}/python)
if(OPM_ENABLE_PYTHON_TESTS)
if(Python3_EXECUTABLE AND NOT PYTHON_EXECUTABLE)
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
endif()
add_test(NAME python_tests
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/python
COMMAND ${CMAKE_COMMAND}