From 58258eb9a67a4e027592ff06c12217925948f1ed Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Mon, 8 Feb 2021 22:57:54 +0100
Subject: [PATCH] Replaced pybind11 submodule with CPM.

---
 .gitmodules                        |  3 ---
 ThirdParty/CMakeLists.txt          | 38 ------------------------------
 ThirdParty/pybind11                |  1 -
 scripts/cmake/Find.cmake           | 15 ++++++++++++
 scripts/cmake/SubmoduleSetup.cmake |  3 ---
 5 files changed, 15 insertions(+), 45 deletions(-)
 delete mode 160000 ThirdParty/pybind11

diff --git a/.gitmodules b/.gitmodules
index 15e5d5f64ee..20187dedb45 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,9 +1,6 @@
 [submodule "ThirdParty/SwmmInterface"]
 	path = ThirdParty/SwmmInterface
 	url = https://github.com/ufz/SwmmInterface.git
-[submodule "ThirdParty/pybind11"]
-	path = ThirdParty/pybind11
-	url = https://github.com/pybind/pybind11.git
 [submodule "ThirdParty/iphreeqc/src"]
 	path = ThirdParty/iphreeqc/src
 	url = https://github.com/ufz/iphreeqc.git
diff --git a/ThirdParty/CMakeLists.txt b/ThirdParty/CMakeLists.txt
index 99ce676bed0..4bd1681920e 100644
--- a/ThirdParty/CMakeLists.txt
+++ b/ThirdParty/CMakeLists.txt
@@ -29,44 +29,6 @@ if(OGS_BUILD_SWMM)
     list(APPEND DISABLE_WARNINGS_TARGETS SWMM SwmmInterface)
 endif()
 
-if(OGS_USE_PYTHON)
-    # pybind11 uses old CMake find functionality, pass variables to use
-    # the same Python installation.
-    set(PYTHON_INCLUDE_DIR ${Python3_INCLUDE_DIRS} CACHE STRING "" FORCE)
-    set(PYTHON_LIBRARIES ${Python3_LIBRARIES} CACHE STRING "" FORCE)
-    set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "" FORCE)
-    set(PYBIND11_PYTHON_VERSION ${Python3_VERSION})
-
-    add_subdirectory(pybind11)
-
-    function(check_python_version_compatibility)
-        if(NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
-            return()
-        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 "${Python3_LIBRARIES}")
-            message(SEND_ERROR "Mismatch between VTK's and OpenGeoSys' Python "
-                "libraries: ${vtkPython_LIBRARIES} vs. ${Python3_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.")
-        endif()
-    endfunction()
-
-    check_python_version_compatibility()
-
-endif()
-
 if(OGS_USE_XDMF)
     find_package(ZLIB REQUIRED) # ZLIB is a HDF5 dependency
     set(XDMF_LIBNAME OgsXdmf CACHE INTERNAL "")
diff --git a/ThirdParty/pybind11 b/ThirdParty/pybind11
deleted file mode 160000
index f1abf5d9159..00000000000
--- a/ThirdParty/pybind11
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit f1abf5d9159b805674197f6bc443592e631c9130
diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake
index 23bfd6cff63..e9e5fbd09fc 100644
--- a/scripts/cmake/Find.cmake
+++ b/scripts/cmake/Find.cmake
@@ -68,6 +68,21 @@ if(tetgen_ADDED)
     install(PROGRAMS $<TARGET_FILE:tetgen> DESTINATION bin)
 endif()
 
+if(OGS_USE_PYTHON)
+    CPMAddPackage(
+        NAME pybind11
+        GITHUB_REPOSITORY pybind/pybind11
+        GIT_TAG f1abf5d9159b805674197f6bc443592e631c9130
+        # pybind11 uses old CMake find functionality, pass variables to use
+        # the same Python installation.
+        OPTIONS
+            "PYTHON_INCLUDE_DIR ${Python3_INCLUDE_DIRS}"
+            "PYTHON_LIBRARIES ${Python3_LIBRARIES}"
+            "PYTHON_EXECUTABLE ${Python3_EXECUTABLE}"
+            "PYBIND11_PYTHON_VERSION ${Python3_VERSION}"
+    )
+endif()
+
 ######################
 ### Find tools     ###
 ######################
diff --git a/scripts/cmake/SubmoduleSetup.cmake b/scripts/cmake/SubmoduleSetup.cmake
index a567dd07059..5d3737ebe2b 100644
--- a/scripts/cmake/SubmoduleSetup.cmake
+++ b/scripts/cmake/SubmoduleSetup.cmake
@@ -12,9 +12,6 @@ endif()
 if(OGS_BUILD_SWMM)
     list(APPEND REQUIRED_SUBMODULES ThirdParty/SwmmInterface)
 endif()
-if(OGS_USE_PYTHON)
-    list(APPEND REQUIRED_SUBMODULES ThirdParty/pybind11)
-endif()
 if (OGS_USE_MFRONT)
     list(APPEND REQUIRED_SUBMODULES ThirdParty/MGIS)
 endif()
-- 
GitLab