package/swig: also create a swig4.0 symlink

FindSWIG in CMake searches for swig4.0, swig3.0 and swig2.0 before it
tries plain swig, and it searches the whole PATH for one name before
moving on to the next. We only create swig3.0 and swig$(SWIG_VERSION_MAJOR)
(swig4.5) symlinks in $(HOST_DIR)/bin, so a swig4.0 installed on the
build machine, as Ubuntu 22.04 does with its swig4.0 package, takes
precedence over our host-swig for every CMake package that does not pass
SWIG_EXECUTABLE explicitly. With CMake 3.22.1, libftdi1 with Python
bindings ends up with

  -- Found SWIG: /usr/bin/swig4.0 (found suitable version "4.0.2", ...)

Also create a swig4.0 symlink, and update the comment accordingly.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Yegor Yefremov
2026-09-24 15:15:33 +02:00
committed by Thomas Petazzoni
parent 875cc7bbf1
commit 9722f61382

View File

@@ -30,18 +30,19 @@ endef
HOST_SWIG_POST_INSTALL_HOOKS += HOST_SWIG_INSTALL_WRAPPER
# CMake looks first at swig3.0, then swig2.0 and then swig. However,
# when doing the search, it will look into the PATH for swig2.0 first,
# and then for swig.
# CMake looks first for swig4.0, then swig3.0 and swig2.0, and only
# then for swig. However, it searches the whole PATH for one name before
# trying the next one.
# While the PATH contains first our $(HOST_DIR)/bin, it also contains
# /usr/bin and other system directories. Therefore, if there is an
# installed swig3.0 on the system, it will get the preference over the
# swig installed in $(HOST_DIR)/bin, which isn't nice. To prevent
# this from happening we create a symbolic link swig3.0 -> swig, so that
# our swig always gets used.
# installed swig4.0 or swig3.0 on the system, it will get the preference
# over the swig installed in $(HOST_DIR)/bin, which isn't nice. To prevent
# this from happening we create swig4.0 and swig3.0 symbolic links to
# swig, so that our swig always gets used.
define HOST_SWIG_INSTALL_SYMLINK
ln -fs swig $(HOST_DIR)/bin/swig$(SWIG_VERSION_MAJOR)
ln -fs swig $(HOST_DIR)/bin/swig4.0
ln -fs swig $(HOST_DIR)/bin/swig3.0
endef