From 47077a865ac79e4c3fbff738438f84496465b3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Fri, 12 Apr 2024 07:36:37 +0200 Subject: [PATCH] Refs #20763. Fix fastdds dll library import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González --- fastdds_python/src/swig/CMakeLists.txt | 8 ++++++-- fastdds_python/src/swig/fastdds.i | 10 +++++++++- fastdds_python/test/types/test_complete.i | 8 ++++++++ fastdds_python/test/types/test_included_modules.i | 8 ++++++++ fastdds_python/test/types/test_modules.i | 8 ++++++++ fastdds_python_examples/HelloWorldExample/HelloWorld.i | 9 ++++++++- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index 13204f9a..0623526f 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -28,7 +28,10 @@ set(${PROJECT_NAME}_FILE ${CMAKE_CURRENT_BINARY_DIR}/${${PROJECT_NAME}_MODULE}.i ) -configure_file(${${PROJECT_NAME}_MODULE}.i ${${PROJECT_NAME}_FILE} @ONLY) +file(GENERATE + OUTPUT ${${PROJECT_NAME}_FILE} + INPUT ${${PROJECT_NAME}_MODULE}.i + ) set_source_files_properties(${${PROJECT_NAME}_FILE} PROPERTIES CPLUSPLUS ON @@ -44,7 +47,8 @@ endif (BUILD_DOCUMENTATION) swig_add_library(${PROJECT_NAME} TYPE SHARED LANGUAGE python - SOURCES ${${PROJECT_NAME}_FILE} + SOURCES + ${${PROJECT_NAME}_FILE} ) if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/fastdds_python/src/swig/fastdds.i b/fastdds_python/src/swig/fastdds.i index c6286a5b..5bb565e3 100644 --- a/fastdds_python/src/swig/fastdds.i +++ b/fastdds_python/src/swig/fastdds.i @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -%module(directors="1", threads="1", moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('fastdds-@fastdds_VERSION_MAJOR@.@fastdds_VERSION_MINOR@.dll')\nif __package__ or '.' in __name__:\n from . import _fastdds_python\nelse:\n import _fastdds_python") fastdds +%module(directors="1", threads="1", moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('$')\nif __package__ or '.' in __name__:\n from . import _fastdds_python\nelse:\n import _fastdds_python") fastdds // Handle exceptions on python callbacks and send them back to C++ so that they can be catched // Also, add some meaningful description of the error @@ -43,6 +43,14 @@ } } +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} + %exception { try { $action } catch (Swig::DirectorException &e) { SWIG_fail; } diff --git a/fastdds_python/test/types/test_complete.i b/fastdds_python/test/types/test_complete.i index 0329d758..9abf9a67 100644 --- a/fastdds_python/test/types/test_complete.i +++ b/fastdds_python/test/types/test_complete.i @@ -21,6 +21,14 @@ %module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('test_complete.dll')\nif __package__ or '.' in __name__:\n from . import _test_completeWrapper\nelse:\n import _test_completeWrapper") test_complete +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} + // SWIG helper modules %include "stdint.i" %include "std_array.i" diff --git a/fastdds_python/test/types/test_included_modules.i b/fastdds_python/test/types/test_included_modules.i index 0f4e081a..0b66cfb8 100644 --- a/fastdds_python/test/types/test_included_modules.i +++ b/fastdds_python/test/types/test_included_modules.i @@ -21,6 +21,14 @@ %module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('test_included_modules.dll')\nif __package__ or '.' in __name__:\n from . import _test_included_modulesWrapper\nelse:\n import _test_included_modulesWrapper") test_included_modules +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} + // SWIG helper modules %include "stdint.i" %include "std_array.i" diff --git a/fastdds_python/test/types/test_modules.i b/fastdds_python/test/types/test_modules.i index f543a8f1..b14a1556 100644 --- a/fastdds_python/test/types/test_modules.i +++ b/fastdds_python/test/types/test_modules.i @@ -21,6 +21,14 @@ %module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('test_modules.dll')\nif __package__ or '.' in __name__:\n from . import _test_modulesWrapper\nelse:\n import _test_modulesWrapper") test_modules +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} + // SWIG helper modules %include "stdint.i" %include "std_array.i" diff --git a/fastdds_python_examples/HelloWorldExample/HelloWorld.i b/fastdds_python_examples/HelloWorldExample/HelloWorld.i index 1bb53381..0906684e 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorld.i +++ b/fastdds_python_examples/HelloWorldExample/HelloWorld.i @@ -19,9 +19,16 @@ * This file was generated by the tool fastddsgen. */ -%module HelloWorld %module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('HelloWorld.dll')\nif __package__ or '.' in __name__:\n from . import _HelloWorldWrapper\nelse:\n import _HelloWorldWrapper") HelloWorld +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} + // SWIG helper modules %include "stdint.i" %include "std_array.i"