Skip to content

Commit

Permalink
Refs #20763. Fix fastdds dll library import
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González <[email protected]>
  • Loading branch information
richiware committed May 14, 2024
1 parent e676e27 commit 47077a8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
8 changes: 6 additions & 2 deletions fastdds_python/src/swig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion fastdds_python/src/swig/fastdds.i
Original file line number Diff line number Diff line change
Expand Up @@ -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@.@[email protected]')\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('$<TARGET_FILE_NAME:fastdds>')\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
Expand Down Expand Up @@ -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>
%}

%exception {
try { $action }
catch (Swig::DirectorException &e) { SWIG_fail; }
Expand Down
8 changes: 8 additions & 0 deletions fastdds_python/test/types/test_complete.i
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exception>
%}

// SWIG helper modules
%include "stdint.i"
%include "std_array.i"
Expand Down
8 changes: 8 additions & 0 deletions fastdds_python/test/types/test_included_modules.i
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exception>
%}

// SWIG helper modules
%include "stdint.i"
%include "std_array.i"
Expand Down
8 changes: 8 additions & 0 deletions fastdds_python/test/types/test_modules.i
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exception>
%}

// SWIG helper modules
%include "stdint.i"
%include "std_array.i"
Expand Down
9 changes: 8 additions & 1 deletion fastdds_python_examples/HelloWorldExample/HelloWorld.i
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exception>
%}

// SWIG helper modules
%include "stdint.i"
%include "std_array.i"
Expand Down

0 comments on commit 47077a8

Please sign in to comment.