From: Markus Blatt <markus@dr-blatt.de>
Date: Mon, 6 May 2024 08:59:05 +0200
Subject: Prevent pybind11 from stripping debug symbols

pybind11_add_module will strip debug symbols if CMAKE_BUILD_TYPE is
neither Debug nor RelWithDebInfo) and there is no option to prevent
this. To fix this we temporarily reset the CMAKE_BUILD_TYPE to Debug
---
 python/simulators/CMakeLists.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/python/simulators/CMakeLists.txt b/python/simulators/CMakeLists.txt
index 5f6e3d4..7d3ee61 100644
--- a/python/simulators/CMakeLists.txt
+++ b/python/simulators/CMakeLists.txt
@@ -20,6 +20,12 @@ add_custom_command(
     DEPENDS ${PYTHON_DOCSTRINGS_FILE}
     COMMENT "Generating PyBlackOilSimulatorDoc.hpp from JSON file"
 )
+
+# pybind11 will always strip debug symbols if CMAKE_BUILD_TYPE is empty
+# We simply reset here to Debug to prevent stripping.
+set(OPM_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
+set(CMAKE_BUILD_TYPE Debug)
+
 # NOTE: The variable ${PYBIND11_SYSTEM} is set in python/CMakeLists.txt
 #   to the value "SYSTEM" or unset, depending on the current version of Pybind11.
 #   The value is then forwarded to target_include_directories(), see
@@ -33,6 +39,7 @@ pybind11_add_module(simulators ${PYBIND11_SYSTEM}
   PyBlackOilSimulator.cpp
   ${PYTHON_DOCSTRINGS_GENERATED_HPP}  # Include the generated .hpp as a source file
   )
+set(CMAKE_BUILD_TYPE "${OLD_CMAKE_BUILD_TYPE}")
 
 set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_OPM_SIMULATORS_PACKAGE_PATH}
                                              SKIP_BUILD_RPATH TRUE )
