diff --git a/src/Python/CMakeLists.txt b/src/Python/CMakeLists.txt index 71997fd1e6bf3f1cf5a0ccf98b5e44f7df811686..505e5f19429d3b9ecf5c1e6010a3293ca347e3a4 100644 --- a/src/Python/CMakeLists.txt +++ b/src/Python/CMakeLists.txt @@ -11,23 +11,27 @@ if( PYTHONINTERP_FOUND ) endif() if( PYTHONLIBS_FOUND ) - # download and build pybind11 at configure time - configure_file(pybind11.cmake.in ${CMAKE_BINARY_DIR}/pybind11-download/CMakeLists.txt) - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/pybind11-download ) - if(result) - message(FATAL_ERROR "CMake step for pybind11 failed: ${result}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/pybind11-download ) - if(result) - message(FATAL_ERROR "Build step for pybind11 failed: ${result}") - endif() + # check if pybind11 exists on the system + find_package(pybind11 QUIET) + if( NOT pybind11_FOUND ) + # download and build pybind11 at configure time + configure_file(pybind11.cmake.in ${CMAKE_BINARY_DIR}/pybind11-download/CMakeLists.txt) + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/pybind11-download ) + if(result) + message(FATAL_ERROR "CMake step for pybind11 failed: ${result}") + endif() + execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/pybind11-download ) + if(result) + message(FATAL_ERROR "Build step for pybind11 failed: ${result}") + endif() - # add the pybind11 subdirectory to provide the pybind11_add_module macro - add_subdirectory(${CMAKE_BINARY_DIR}/pybind11-src ${CMAKE_BINARY_DIR}/pybind11-build) + # add the pybind11 subdirectory to provide the pybind11_add_module macro + add_subdirectory(${CMAKE_BINARY_DIR}/pybind11-src ${CMAKE_BINARY_DIR}/pybind11-build) + endif() # add the subdirectory with our bindings add_subdirectory(pytnl) diff --git a/src/Python/pybind11.cmake.in b/src/Python/pybind11.cmake.in index 885e62e5e694c86020934ed7260557b1469a4899..1f28673a1d1990fe50470ee5f39ae7cb216c7c59 100644 --- a/src/Python/pybind11.cmake.in +++ b/src/Python/pybind11.cmake.in @@ -8,7 +8,9 @@ ExternalProject_Add(pybind11 GIT_TAG master SOURCE_DIR "${CMAKE_BINARY_DIR}/pybind11-src" BINARY_DIR "${CMAKE_BINARY_DIR}/pybind11-build" - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DPYBIND11_TEST=FALSE + CMAKE_ARGS -DPYBIND11_TEST=FALSE + # Do not install pybind11 in the system or user's home directory + INSTALL_COMMAND "" # Disable update of the external project in an offline build # reference: https://stackoverflow.com/a/40423683 UPDATE_DISCONNECTED ${OFFLINE_BUILD}