From 4bf4cca89010e5d4aec00c55122a64059cb37654 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Fri, 22 Feb 2019 08:55:42 +0100
Subject: [PATCH] [CMake] Force same python version for pybind11.

---
 ThirdParty/CMakeLists.txt | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/ThirdParty/CMakeLists.txt b/ThirdParty/CMakeLists.txt
index e4c493583ab..96e8b4f6f5c 100644
--- a/ThirdParty/CMakeLists.txt
+++ b/ThirdParty/CMakeLists.txt
@@ -48,6 +48,13 @@ if(OGS_BUILD_SWMM)
 endif()
 
 if(OGS_USE_PYTHON)
+    # pybind11 uses old CMake find functionality, pass variables to use
+    # the same Python installation.
+    find_package(Python COMPONENTS Interpreter Development REQUIRED)
+    set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS} CACHE STRING "" FORCE)
+    set(PYTHON_LIBRARIES ${Python_LIBRARIES} CACHE STRING "" FORCE)
+    set(PYTHON_EXECUTABLE ${Python_EXECUTABLE} CACHE FILEPATH "" FORCE)
+
     add_subdirectory(pybind11)
 
     function(check_python_version_compatibility)
@@ -56,19 +63,18 @@ if(OGS_USE_PYTHON)
         endif()
 
         include(${VTK_DIR}/VTKConfig.cmake)
-
         if(NOT ${VTK_WRAP_PYTHON})
             return()
         endif()
+
         if(NOT EXISTS ${VTK_MODULES_DIR}/vtkPython.cmake)
             return()
         endif()
 
         include(${VTK_MODULES_DIR}/vtkPython.cmake)
-
-        if (NOT "${vtkPython_LIBRARIES}" STREQUAL "${PYTHON_LIBRARIES}")
+        if (NOT "${vtkPython_LIBRARIES}" STREQUAL "${Python_LIBRARIES}")
             message(SEND_ERROR "Mismatch between VTK's and OpenGeoSys' Python "
-                "libraries: ${vtkPython_LIBRARIES} vs. ${PYTHON_LIBRARIES}. "
+                "libraries: ${vtkPython_LIBRARIES} vs. ${Python_LIBRARIES}. "
                 "This will lead to compilation or linking errors. "
                 "You can fix this error by using the same Python version for "
                 "OpenGeoSys as VTK is built with.")
@@ -76,6 +82,7 @@ if(OGS_USE_PYTHON)
     endfunction()
 
     check_python_version_compatibility()
+
 endif()
 
 if(OGS_BUILD_UTILS)
-- 
GitLab