Skip to content

Commit 5e73b01

Browse files
committed
FIX: SWIG Bindings: Use correct SWIG executable and adapt for Apple ld
This commit introduces two changes: (1) It correctly sets the SWIG executable for Apple targets. (2) It adapts to the Apple linker (ld), which does not allow undefined symbols in shared objects (.so) by default. Regarding (2), see SWIG issue 2469. Signed-off-by: Philipp Remy <philipp.remy@law-school.de>
1 parent 649b74a commit 5e73b01

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/cmake/Dependencies.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,10 +1555,17 @@ if(AV_BUILD_SWIG)
15551555
DEPENDS ${PCRE2_TARGET}
15561556
)
15571557

1558-
set(SWIG_CMAKE_FLAGS
1559-
-DSWIG_DIR=${CMAKE_INSTALL_PREFIX}/share/swig/4.3.0
1560-
-DSWIG_EXECUTABLE=${CMAKE_INSTALL_PREFIX}/bin-deps
1561-
)
1558+
if(APPLE)
1559+
set(SWIG_CMAKE_FLAGS
1560+
-DSWIG_DIR=${CMAKE_INSTALL_PREFIX}/share/swig/4.3.0
1561+
-DSWIG_EXECUTABLE=${CMAKE_INSTALL_PREFIX}/bin/swig
1562+
)
1563+
else()
1564+
set(SWIG_CMAKE_FLAGS
1565+
-DSWIG_DIR=${CMAKE_INSTALL_PREFIX}/share/swig/4.3.0
1566+
-DSWIG_EXECUTABLE=${CMAKE_INSTALL_PREFIX}/bin-deps
1567+
)
1568+
endif()
15621569
endif()
15631570

15641571
if(AV_BUILD_XERCESC)

src/cmake/Helpers.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,15 @@ function(alicevision_swig_add_library module_name)
365365
TARGET ${module_name}
366366
PROPERTY COMPILE_OPTIONS -std=c++20
367367
)
368+
if(APPLE)
369+
# The ld on macOS does not allow undefined symbols for shared objects,
370+
# so this must be explicitly passed to the linker.
371+
# See: https://github.com/swig/swig/issues/2469
372+
set_property(
373+
TARGET ${module_name}
374+
PROPERTY LINK_OPTIONS -undefined dynamic_lookup
375+
)
376+
endif()
368377

369378
target_link_libraries(${module_name}
370379
PUBLIC ${SWIG_MODULE_PUBLIC_LINKS}

0 commit comments

Comments
 (0)