Building from source in Ubuntu, it thinks I have swig2.0 when I have swig 4.0

I can’t figure this out:

kicad/build/release $ cmake -DCMAKE_BUILD_TYPE=Release ../../
-- KiCad install dir: </usr/local>
-- Check for installed GLEW -- found
-- Boost version: 1.54.0
CMake Error at /usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
  Could NOT find SWIG: Found unsuitable version "2.0.11", but required is at
  least "3.0" (found /usr/bin/swig2.0)
Call Stack (most recent call first):
  /usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:372 (_FPHSA_FAILURE_MESSAGE)
  CMakeModules/FindSWIG.cmake:93 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:676 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/gabriels/GS/dev/KiCad/source/kicad/build/release/CMakeFiles/CMakeOutput.log".
See also "/home/gabriels/GS/dev/KiCad/source/kicad/build/release/CMakeFiles/CMakeError.log".

The find_program routine in kicad/CMakeModules/FindSWIG.cmake obviously thinks I have swig 2.0 installed, but I just built swig 4.0 from source, and when I run swig -version I get SWIG Version 4.0.0.

How can I make cmake continue the kicad build?

Note that which swig shows my swig 4.0 is here: “/usr/local/bin/swig”. swig -swiglib shows: /usr/local/share/swig/4.0.0

Swig 4.0 is not correctly detected by FindSWIG.cmake. You can try and patch it, it may be as simple as adding swig4.0 to the list here:


Which ubuntu version are you running? There should be a swig 3.0 package available for it.

I tried adding swig4.0:

find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig)

This made no difference. So I did a crude hack which works fine instead: I just forced it to be set to where I know the 4.0 binary is (via set(SWIG_EXECUTABLE /usr/local/bin/swig) below). We need a better solution but for now this works I guess. The commented out lines are other things I tried that didn’t work.

# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

find_program(SWIG_EXECUTABLE NAMES swig3.0 swig2.0 swig)
# find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig)
# find_program(SWIG_EXECUTABLE NAMES swig swig3.0 swig2.0 PATHS usr/local/share NO_CMAKE_FIND_ROOT_PATH)
# find_program(SWIG_EXECUTABLE NAMES swig PATHS /usr/local/bin NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)

# message("hey " ${SWIG_EXECUTABLE})
set(SWIG_EXECUTABLE /usr/local/bin/swig)
# message("hey " ${SWIG_EXECUTABLE})

if(SWIG_EXECUTABLE)
  execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib

I’m using Ubuntu 14.04. This machine has unique build dependencies and cannot be upgraded to a later version of Ubuntu at this time.

Is /usr/local/bin earlier on $PATH than /usr/bin?
It’s a longshot, but maybe you are just trying to run cmake from a shell that still has old path to swig cached in it. Try hash -r to dump the cache and force shell to find binaries from $PATH again, that may help.

Yes, /usr/local/bin comes earlier on $PATH. Here’s the order:

/home/gabriels/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/usr/lib/jvm/java-8-oracle/bin
/usr/lib/jvm/java-8-oracle/db/bin
/usr/lib/jvm/java-8-oracle/jre/bin

I tried the hash -r thing. No luck.

I should mention that swig2.0 really is installed on my machine in /usr/bin/swig2.0, but I renamed it to /usr/bin/deprecated_swig2.0 to try to make it not found. No luck with that either. I’m not sure how to uninstall swig2.0 either.

UPDATE: I take that back: sudo apt remove swig2.0 looks like it may work, but I think it’ll break other dependencies, so I think I’m going to avoid that for now.

New solution. It turns out you can set the value of SWIG_EXECUTABLE directly when calling cmake, by simply adding -DSWIG_EXECUTABLE="/usr/local/bin/swig", for example, to the end of your cmake command.

My full cmake command is now:

cmake -DCMAKE_BUILD_TYPE=Release -DKICAD_SCRIPTING=OFF -DKICAD_SCRIPTING_MODULES=OFF -DKICAD_SCRIPTING_WXPYTHON=OFF -DKICAD_SCRIPTING_ACTION_MENU=OFF -DSWIG_EXECUTABLE="/usr/local/bin/swig" ../../

See my full build notes and details documented here: https://bugs.launchpad.net/kicad/+bug/1804771.

I now have successfully built KiCad from source in Linux Ubuntu. Yaaaaay! :grinning:

I had the same problem on my Ubuntu 14.04, even after a ./configure;make;make install of SWIG 4.0. I removed everything in my build directory and did a cmake ../ again and it worked well.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.